diff --git a/code-analyzer.js b/code-analyzer.js index 0146bb9..e9045d8 100644 --- a/code-analyzer.js +++ b/code-analyzer.js @@ -21,132 +21,133 @@ * */ -const fs = require('fs') -const path = require('path') -const java7 = require('./grammar/java7') +const fs = require("fs"); +const path = require("path"); +const java7 = require("./grammar/java7"); // Java Primitive Types var javaPrimitiveTypes = [ - 'void', - 'byte', - 'short', - 'int', - 'long', - 'float', - 'double', - 'boolean', - 'char', - 'Byte', - 'Double', - 'Float', - 'Integer', - 'Long', - 'Short', - 'String', - 'Character', - 'java.lang.Byte', - 'java.lang.Double', - 'java.lang.Float', - 'java.lang.Integer', - 'java.lang.Long', - 'java.lang.Short', - 'java.lang.String', - 'java.lang.Character' -] + "void", + "byte", + "short", + "int", + "long", + "float", + "double", + "boolean", + "char", + "Byte", + "Double", + "Float", + "Integer", + "Long", + "Short", + "String", + "Character", + "java.lang.Byte", + "java.lang.Double", + "java.lang.Float", + "java.lang.Integer", + "java.lang.Long", + "java.lang.Short", + "java.lang.String", + "java.lang.Character", +]; // Java Collection Types var javaCollectionTypes = [ - 'Collection', - 'Set', - 'SortedSet', - 'NavigableSet', - 'HashSet', - 'TreeSet', - 'LinkedHashSet', - 'List', - 'ArrayList', - 'LinkedList', - 'Deque', - 'ArrayDeque', - 'Queue' -] + "Collection", + "Set", + "SortedSet", + "NavigableSet", + "HashSet", + "TreeSet", + "LinkedHashSet", + "List", + "ArrayList", + "LinkedList", + "Deque", + "ArrayDeque", + "Queue", +]; // Java Collection Types (full names) -var javaUtilCollectionTypes = javaCollectionTypes.map(c => { return 'java.util.' + c }) +var javaUtilCollectionTypes = javaCollectionTypes.map((c) => { + return "java.util." + c; +}); /** * Java Code Analyzer */ class JavaCodeAnalyzer { - /** * @constructor */ - constructor () { + constructor() { /** @member {type.UMLModel} */ - this._root = new type.UMLModel() - this._root.name = 'JavaReverse' + this._root = new type.UMLModel(); + this._root.name = "JavaReverse"; /** @member {Array.} */ - this._files = [] + this._files = []; /** @member {Object} */ - this._currentCompilationUnit = null + this._currentCompilationUnit = null; /** * @member {{classifier:type.UMLClassifier, node: Object, kind:string}} */ - this._extendPendings = [] + this._extendPendings = []; /** * @member {{classifier:type.UMLClassifier, node: Object}} */ - this._implementPendings = [] + this._implementPendings = []; /** * @member {{classifier:type.UMLClassifier, association: type.UMLAssociation, node: Object}} */ - this._associationPendings = [] + this._associationPendings = []; /** * @member {{operation:type.UMLOperation, node: Object}} */ - this._throwPendings = [] + this._throwPendings = []; /** * @member {{namespace:type.UMLModelElement, feature:type.UMLStructuralFeature, node: Object}} */ - this._typedFeaturePendings = [] + this._typedFeaturePendings = []; } /** * Add File to Reverse Engineer * @param {File} file */ - addFile (file) { - this._files.push(file) + addFile(file) { + this._files.push(file); } /** * Analyze all files. * @param {Object} options */ - analyze (options) { + analyze(options) { // Perform 1st Phase - this.performFirstPhase(options) + this.performFirstPhase(options); // Perform 2nd Phase - this.performSecondPhase(options) + this.performSecondPhase(options); // Load To Project - var writer = new app.repository.Writer() - writer.writeObj('data', this._root) - var json = writer.current.data - app.project.importFromJson(app.project.getProject(), json) + var writer = new app.repository.Writer(); + writer.writeObj("data", this._root); + var json = writer.current.data; + app.project.importFromJson(app.project.getProject(), json); // Generate Diagrams - this.generateDiagrams(options) - console.log('[Java] done.') + this.generateDiagrams(options); + console.log("[Java] done."); } /** @@ -155,23 +156,23 @@ class JavaCodeAnalyzer { * * @param {Object} options */ - performFirstPhase (options) { - this._files.forEach(file => { - var data = fs.readFileSync(file, 'utf8') + performFirstPhase(options) { + this._files.forEach((file) => { + var data = fs.readFileSync(file, "utf8"); try { /* Not processing empty file @author Rtfsc8(rtfsc8@rtfsc8.top) */ if (!!!data) { - return; + return; } - var ast = java7.parse(data) - this._currentCompilationUnit = ast - this._currentCompilationUnit.file = file - this.translateCompilationUnit(options, this._root, ast) + var ast = java7.parse(data); + this._currentCompilationUnit = ast; + this._currentCompilationUnit.file = file; + this.translateCompilationUnit(options, this._root, ast); } catch (ex) { - console.error('[Java] Failed to parse - ' + file) - console.error(ex) + console.error("[Java] Failed to parse - " + file); + console.error(ex); } - }) + }); } /** @@ -183,170 +184,235 @@ class JavaCodeAnalyzer { * * @param {Object} options */ - performSecondPhase (options) { - var i, len, j, len2, _typeName, _type, _itemTypeName, _itemType, _pathName + performSecondPhase(options) { + var i, len, j, len2, _typeName, _type, _itemTypeName, _itemType, _pathName; // Create Generalizations // if super type not found, create a Class correspond to the super type. for (i = 0, len = this._extendPendings.length; i < len; i++) { - var _extend = this._extendPendings[i] - _typeName = _extend.node.qualifiedName.name - - _type = this._findType(_extend.classifier, _typeName, _extend.compilationUnitNode) + var _extend = this._extendPendings[i]; + _typeName = _extend.node.qualifiedName.name; + + _type = this._findType( + _extend.classifier, + _typeName, + _extend.compilationUnitNode, + ); if (!_type) { - _pathName = this._toPathName(_typeName) - if (_extend.kind === 'interface') { - _type = this._ensureInterface(this._root, _pathName) + _pathName = this._toPathName(_typeName); + if (_extend.kind === "interface") { + _type = this._ensureInterface(this._root, _pathName); } else { - _type = this._ensureClass(this._root, _pathName) + _type = this._ensureClass(this._root, _pathName); } } - var generalization = new type.UMLGeneralization() - generalization._parent = _extend.classifier - generalization.source = _extend.classifier - generalization.target = _type - _extend.classifier.ownedElements.push(generalization) + var generalization = new type.UMLGeneralization(); + generalization._parent = _extend.classifier; + generalization.source = _extend.classifier; + generalization.target = _type; + _extend.classifier.ownedElements.push(generalization); } // Create InterfaceRealizations // if super interface not found, create a Interface correspond to the super interface for (i = 0, len = this._implementPendings.length; i < len; i++) { - var _implement = this._implementPendings[i] - _typeName = _implement.node.qualifiedName.name - _type = this._findType(_implement.classifier, _typeName, _implement.compilationUnitNode) + var _implement = this._implementPendings[i]; + _typeName = _implement.node.qualifiedName.name; + _type = this._findType( + _implement.classifier, + _typeName, + _implement.compilationUnitNode, + ); if (!_type) { - _pathName = this._toPathName(_typeName) - _type = this._ensureInterface(this._root, _pathName) + _pathName = this._toPathName(_typeName); + _type = this._ensureInterface(this._root, _pathName); } - var realization = new type.UMLInterfaceRealization() - realization._parent = _implement.classifier - realization.source = _implement.classifier - realization.target = _type - _implement.classifier.ownedElements.push(realization) + var realization = new type.UMLInterfaceRealization(); + realization._parent = _implement.classifier; + realization.source = _implement.classifier; + realization.target = _type; + _implement.classifier.ownedElements.push(realization); } // Create Associations for (i = 0, len = this._associationPendings.length; i < len; i++) { - var _asso = this._associationPendings[i] - _typeName = _asso.node.type.qualifiedName.name - _type = this._findType(_asso.classifier, _typeName, _asso.node.compilationUnitNode) - _itemTypeName = this._isGenericCollection(_asso.node.type, _asso.node.compilationUnitNode) + var _asso = this._associationPendings[i]; + _typeName = _asso.node.type.qualifiedName.name; + _type = this._findType( + _asso.classifier, + _typeName, + _asso.node.compilationUnitNode, + ); + _itemTypeName = this._isGenericCollection( + _asso.node.type, + _asso.node.compilationUnitNode, + ); if (_itemTypeName) { - _itemType = this._findType(_asso.classifier, _itemTypeName, _asso.node.compilationUnitNode) + _itemType = this._findType( + _asso.classifier, + _itemTypeName, + _asso.node.compilationUnitNode, + ); } else { - _itemType = null + _itemType = null; } // if type found, add as Association if (_type || _itemType) { for (j = 0, len2 = _asso.node.variables.length; j < len2; j++) { - var variableNode = _asso.node.variables[j] + var variableNode = _asso.node.variables[j]; // Create Association - var association = new type.UMLAssociation() - association._parent = _asso.classifier - _asso.classifier.ownedElements.push(association) + var association = new type.UMLAssociation(); + association._parent = _asso.classifier; + _asso.classifier.ownedElements.push(association); // Set End1 - association.end1.reference = _asso.classifier - association.end1.name = '' - association.end1.visibility = type.UMLModelElement.VK_PACKAGE - association.end1.navigable = false + association.end1.reference = _asso.classifier; + association.end1.name = ""; + association.end1.visibility = type.UMLModelElement.VK_PACKAGE; + association.end1.navigable = false; // Set End2 if (_itemType) { - association.end2.reference = _itemType - association.end2.multiplicity = '*' - this._addTag(association.end2, type.Tag.TK_STRING, 'collection', _asso.node.type.qualifiedName.name) + association.end2.reference = _itemType; + association.end2.multiplicity = "*"; + this._addTag( + association.end2, + type.Tag.TK_STRING, + "collection", + _asso.node.type.qualifiedName.name, + ); } else { - association.end2.reference = _type + association.end2.reference = _type; } - association.end2.name = variableNode.name - association.end2.visibility = this._getVisibility(_asso.node.modifiers) - association.end2.navigable = true + association.end2.name = variableNode.name; + association.end2.visibility = this._getVisibility( + _asso.node.modifiers, + ); + association.end2.navigable = true; // Final Modifier - if (_asso.node.modifiers && _asso.node.modifiers.includes('final')) { - association.end2.isReadOnly = true + if (_asso.node.modifiers && _asso.node.modifiers.includes("final")) { + association.end2.isReadOnly = true; } // Static Modifier - if (_asso.node.modifiers && _asso.node.modifiers.includes('static')) { - this._addTag(association.end2, type.Tag.TK_BOOLEAN, 'static', true) + if (_asso.node.modifiers && _asso.node.modifiers.includes("static")) { + this._addTag(association.end2, type.Tag.TK_BOOLEAN, "static", true); } // Volatile Modifier - if (_asso.node.modifiers && _asso.node.modifiers.includes('volatile')) { - this._addTag(association.end2, type.Tag.TK_BOOLEAN, 'volatile', true) + if ( + _asso.node.modifiers && + _asso.node.modifiers.includes("volatile") + ) { + this._addTag( + association.end2, + type.Tag.TK_BOOLEAN, + "volatile", + true, + ); } // Transient Modifier - if (_asso.node.modifiers && _asso.node.modifiers.includes('transient')) { - this._addTag(association.end2, type.Tag.TK_BOOLEAN, 'transient', true) + if ( + _asso.node.modifiers && + _asso.node.modifiers.includes("transient") + ) { + this._addTag( + association.end2, + type.Tag.TK_BOOLEAN, + "transient", + true, + ); } } // if type not found, add as Attribute } else { - this.translateFieldAsAttribute(options, _asso.classifier, _asso.node) + this.translateFieldAsAttribute(options, _asso.classifier, _asso.node); } } // Assign Throws to Operations for (i = 0, len = this._throwPendings.length; i < len; i++) { - var _throw = this._throwPendings[i] - _typeName = _throw.node.name - _type = this._findType(_throw.operation, _typeName, _throw.compilationUnitNode) + var _throw = this._throwPendings[i]; + _typeName = _throw.node.name; + _type = this._findType( + _throw.operation, + _typeName, + _throw.compilationUnitNode, + ); if (!_type) { - _pathName = this._toPathName(_typeName) - _type = this._ensureClass(this._root, _pathName) + _pathName = this._toPathName(_typeName); + _type = this._ensureClass(this._root, _pathName); } - _throw.operation.raisedExceptions.push(_type) + _throw.operation.raisedExceptions.push(_type); } // Resolve Type References for (i = 0, len = this._typedFeaturePendings.length; i < len; i++) { - var _typedFeature = this._typedFeaturePendings[i] + var _typedFeature = this._typedFeaturePendings[i]; //Fix bug: some reverse code error like qualifiedName attribute undefined if (!!!_typedFeature.node.type.qualifiedName) { continue; } - _typeName = _typedFeature.node.type.qualifiedName.name + _typeName = _typedFeature.node.type.qualifiedName.name; // Find type and assign - _type = this._findType(_typedFeature.namespace, _typeName, _typedFeature.node.compilationUnitNode) + _type = this._findType( + _typedFeature.namespace, + _typeName, + _typedFeature.node.compilationUnitNode, + ); // if type is exists if (_type) { - _typedFeature.feature.type = _type + _typedFeature.feature.type = _type; // if type is not exists } else { // if type is generic collection type (e.g. java.util.List) - _itemTypeName = this._isGenericCollection(_typedFeature.node.type, _typedFeature.node.compilationUnitNode) + _itemTypeName = this._isGenericCollection( + _typedFeature.node.type, + _typedFeature.node.compilationUnitNode, + ); if (_itemTypeName) { - _typeName = _itemTypeName - _typedFeature.feature.multiplicity = '*' - this._addTag(_typedFeature.feature, type.Tag.TK_STRING, 'collection', _typedFeature.node.type.qualifiedName.name) + _typeName = _itemTypeName; + _typedFeature.feature.multiplicity = "*"; + this._addTag( + _typedFeature.feature, + type.Tag.TK_STRING, + "collection", + _typedFeature.node.type.qualifiedName.name, + ); } // if type is primitive type if (javaPrimitiveTypes.includes(_typeName)) { - _typedFeature.feature.type = _typeName + _typedFeature.feature.type = _typeName; // otherwise } else { - _pathName = this._toPathName(_typeName) - var _newClass = this._ensureClass(this._root, _pathName) - _typedFeature.feature.type = _newClass + _pathName = this._toPathName(_typeName); + var _newClass = this._ensureClass(this._root, _pathName); + _typedFeature.feature.type = _newClass; } } // Translate type's arrayDimension to multiplicity - if (_typedFeature.node.type.arrayDimension && _typedFeature.node.type.arrayDimension.length > 0) { - var _dim = [] - for (j = 0, len2 = _typedFeature.node.type.arrayDimension.length; j < len2; j++) { - _dim.push('*') + if ( + _typedFeature.node.type.arrayDimension && + _typedFeature.node.type.arrayDimension.length > 0 + ) { + var _dim = []; + for ( + j = 0, len2 = _typedFeature.node.type.arrayDimension.length; + j < len2; + j++ + ) { + _dim.push("*"); } - _typedFeature.feature.multiplicity = _dim.join(',') + _typedFeature.feature.multiplicity = _dim.join(","); } } } @@ -355,20 +421,24 @@ class JavaCodeAnalyzer { * Generate Diagrams (Type Hierarchy, Package Structure, Package Overview) * @param {Object} options */ - generateDiagrams (options) { - var baseModel = app.repository.get(this._root._id) + generateDiagrams(options) { + var baseModel = app.repository.get(this._root._id); if (options.packageStructure) { - app.commands.execute('diagram-generator:package-structure', baseModel, true) + app.commands.execute( + "diagram-generator:package-structure", + baseModel, + true, + ); } if (options.typeHierarchy) { - app.commands.execute('diagram-generator:type-hierarchy', baseModel, true) + app.commands.execute("diagram-generator:type-hierarchy", baseModel, true); } if (options.packageOverview) { - baseModel.traverse(elem => { + baseModel.traverse((elem) => { if (elem instanceof type.UMLPackage) { - app.commands.execute('diagram-generator:overview', elem, true) + app.commands.execute("diagram-generator:overview", elem, true); } - }) + }); } } @@ -377,12 +447,13 @@ class JavaCodeAnalyzer { * @param {string} typeName * @return {Array.} pathName */ - _toPathName (typeName) { - var pathName = (typeName.indexOf('.') > 0 ? typeName.trim().split('.') : null) + _toPathName(typeName) { + var pathName = + typeName.indexOf(".") > 0 ? typeName.trim().split(".") : null; if (!pathName) { - pathName = [ typeName ] + pathName = [typeName]; } - return pathName + return pathName; } /** @@ -393,45 +464,45 @@ class JavaCodeAnalyzer { * @param {Object} compilationUnitNode To search type with import statements. * @return {type.Model} element correspond to the type. */ - _findType (namespace, type, compilationUnitNode) { - var typeName, pathName - var _type = null - - if (type.node === 'Type') { - typeName = type.qualifiedName.name - } else if (typeof type === 'string') { - typeName = type + _findType(namespace, type, compilationUnitNode) { + var typeName, pathName; + var _type = null; + + if (type.node === "Type") { + typeName = type.qualifiedName.name; + } else if (typeof type === "string") { + typeName = type; } - pathName = this._toPathName(typeName) + pathName = this._toPathName(typeName); // 1. Lookdown from context if (pathName.length > 1) { - _type = namespace.lookdown(pathName) + _type = namespace.lookdown(pathName); } else { - _type = namespace.findByName(typeName) + _type = namespace.findByName(typeName); } // 2. Lookup from context if (!_type) { - _type = namespace.lookup(typeName, null, this._root) + _type = namespace.lookup(typeName, null, this._root); } // 3. Find from imported namespaces if (!_type) { if (compilationUnitNode.imports) { - var i, len + var i, len; for (i = 0, len = compilationUnitNode.imports.length; i < len; i++) { - var _import = compilationUnitNode.imports[i] + var _import = compilationUnitNode.imports[i]; // Find in wildcard imports (e.g. import java.lang.*) if (_import.wildcard) { - var _namespace = this._root.lookdown(_import.qualifiedName.name) + var _namespace = this._root.lookdown(_import.qualifiedName.name); if (_namespace) { - _type = _namespace.findByName(typeName) + _type = _namespace.findByName(typeName); } // Find in import exact matches (e.g. import java.lang.String) } else { - _type = this._root.lookdown(_import.qualifiedName.name) + _type = this._root.lookdown(_import.qualifiedName.name); } } } @@ -440,13 +511,13 @@ class JavaCodeAnalyzer { // 4. Lookdown from Root if (!_type) { if (pathName.length > 1) { - _type = this._root.lookdown(pathName) + _type = this._root.lookdown(pathName); } else { - _type = this._root.findByName(typeName) + _type = this._root.findByName(typeName); } } - return _type + return _type; } /** @@ -455,17 +526,17 @@ class JavaCodeAnalyzer { * @param {Array.} modifiers * @return {string} Visibility constants for UML Elements */ - _getVisibility (modifiers) { + _getVisibility(modifiers) { if (modifiers) { - if (modifiers.includes('public')) { - return type.UMLModelElement.VK_PUBLIC - } else if (modifiers.includes('protected')) { - return type.UMLModelElement.VK_PROTECTED - } else if (modifiers.includes('private')) { - return type.UMLModelElement.VK_PRIVATE + if (modifiers.includes("public")) { + return type.UMLModelElement.VK_PUBLIC; + } else if (modifiers.includes("protected")) { + return type.UMLModelElement.VK_PROTECTED; + } else if (modifiers.includes("private")) { + return type.UMLModelElement.VK_PRIVATE; } } - return type.UMLModelElement.VK_PACKAGE + return type.UMLModelElement.VK_PACKAGE; } /** @@ -475,29 +546,29 @@ class JavaCodeAnalyzer { * @param {string} name * @param {?} value Value of Tag */ - _addTag (elem, kind, name, value) { - var tag = new type.Tag() - tag._parent = elem - tag.name = name - tag.kind = kind + _addTag(elem, kind, name, value) { + var tag = new type.Tag(); + tag._parent = elem; + tag.name = name; + tag.kind = kind; switch (kind) { - case type.Tag.TK_STRING: - tag.value = value - break - case type.Tag.TK_BOOLEAN: - tag.checked = value - break - case type.Tag.TK_NUMBER: - tag.number = value - break - case type.Tag.TK_REFERENCE: - tag.reference = value - break - case type.Tag.TK_HIDDEN: - tag.value = value - break + case type.Tag.TK_STRING: + tag.value = value; + break; + case type.Tag.TK_BOOLEAN: + tag.checked = value; + break; + case type.Tag.TK_NUMBER: + tag.number = value; + break; + case type.Tag.TK_REFERENCE: + tag.reference = value; + break; + case type.Tag.TK_HIDDEN: + tag.value = value; + break; } - elem.tags.push(tag) + elem.tags.push(tag); } /** @@ -506,57 +577,57 @@ class JavaCodeAnalyzer { * @param {Array.} pathNames * @return {type.Model} Package element corresponding to the pathNames */ - _ensurePackage (namespace, pathNames) { + _ensurePackage(namespace, pathNames) { if (pathNames.length > 0) { - var name = pathNames.shift() + var name = pathNames.shift(); if (name && name.length > 0) { - var elem = namespace.findByName(name) + var elem = namespace.findByName(name); if (elem !== null) { // Package exists if (pathNames.length > 0) { - return this._ensurePackage(elem, pathNames) + return this._ensurePackage(elem, pathNames); } else { - return elem + return elem; } } else { // Package not exists, then create one. - var _package = new type.UMLPackage() - namespace.ownedElements.push(_package) - _package._parent = namespace - _package.name = name + var _package = new type.UMLPackage(); + namespace.ownedElements.push(_package); + _package._parent = namespace; + _package.name = name; if (pathNames.length > 0) { - return this._ensurePackage(_package, pathNames) + return this._ensurePackage(_package, pathNames); } else { - return _package + return _package; } } } } else { - return namespace + return namespace; } } /** - * Return the class of a given pathNames. If not exists, create the class. - * @param {type.Model} namespace - * @param {Array.} pathNames - * @return {type.Model} Class element corresponding to the pathNames - */ - _ensureClass (namespace, pathNames) { + * Return the class of a given pathNames. If not exists, create the class. + * @param {type.Model} namespace + * @param {Array.} pathNames + * @return {type.Model} Class element corresponding to the pathNames + */ + _ensureClass(namespace, pathNames) { if (pathNames.length > 0) { - var _className = pathNames.pop() - var _package = this._ensurePackage(namespace, pathNames) - var _class = _package.findByName(_className) + var _className = pathNames.pop(); + var _package = this._ensurePackage(namespace, pathNames); + var _class = _package.findByName(_className); if (!_class) { - _class = new type.UMLClass() - _class._parent = _package - _class.name = _className - _class.visibility = type.UMLModelElement.VK_PUBLIC - _package.ownedElements.push(_class) + _class = new type.UMLClass(); + _class._parent = _package; + _class.name = _className; + _class.visibility = type.UMLModelElement.VK_PUBLIC; + _package.ownedElements.push(_class); } - return _class + return _class; } - return null + return null; } /** @@ -565,21 +636,21 @@ class JavaCodeAnalyzer { * @param {Array.} pathNames * @return {type.Model} Interface element corresponding to the pathNames */ - _ensureInterface (namespace, pathNames) { + _ensureInterface(namespace, pathNames) { if (pathNames.length > 0) { - var _interfaceName = pathNames.pop() - var _package = this._ensurePackage(namespace, pathNames) - var _interface = _package.findByName(_interfaceName) + var _interfaceName = pathNames.pop(); + var _package = this._ensurePackage(namespace, pathNames); + var _interface = _package.findByName(_interfaceName); if (!_interface) { - _interface = new type.UMLInterface() - _interface._parent = _package - _interface.name = _interfaceName - _interface.visibility = type.UMLModelElement.VK_PUBLIC - _package.ownedElements.push(_interface) + _interface = new type.UMLInterface(); + _interface._parent = _package; + _interface.name = _interfaceName; + _interface.visibility = type.UMLModelElement.VK_PUBLIC; + _package.ownedElements.push(_interface); } - return _interface + return _interface; } - return null + return null; } /** @@ -587,37 +658,43 @@ class JavaCodeAnalyzer { * @param {Object} typeNode * @return {string} Collection item type name */ - _isGenericCollection (typeNode, compilationUnitNode) { - if (typeNode.qualifiedName.typeParameters && typeNode.qualifiedName.typeParameters.length > 0) { - var _collectionType = typeNode.qualifiedName.name - var _itemType = typeNode.qualifiedName.typeParameters[0].name + _isGenericCollection(typeNode, compilationUnitNode) { + if ( + typeNode.qualifiedName.typeParameters && + typeNode.qualifiedName.typeParameters.length > 0 + ) { + var _collectionType = typeNode.qualifiedName.name; + var _itemType = typeNode.qualifiedName.typeParameters[0].name; // Used Full name (e.g. java.util.List) if (javaUtilCollectionTypes.includes(_collectionType)) { - return _itemType + return _itemType; } // Used name with imports (e.g. List and import java.util.List or java.util.*) if (javaCollectionTypes.includes(_collectionType)) { if (compilationUnitNode.imports) { - var i, len + var i, len; for (i = 0, len = compilationUnitNode.imports.length; i < len; i++) { - var _import = compilationUnitNode.imports[i] + var _import = compilationUnitNode.imports[i]; // Full name import (e.g. import java.util.List) - if (_import.qualifiedName.name === 'java.util.' + _collectionType) { - return _itemType + if (_import.qualifiedName.name === "java.util." + _collectionType) { + return _itemType; } // Wildcard import (e.g. import java.util.*) - if (_import.qualifiedName.name === 'java.util' && _import.wildcard) { - return _itemType + if ( + _import.qualifiedName.name === "java.util" && + _import.wildcard + ) { + return _itemType; } } } } } - return null + return null; } /** @@ -626,18 +703,22 @@ class JavaCodeAnalyzer { * @param {type.Model} namespace * @param {Object} compilationUnitNode */ - translateCompilationUnit (options, namespace, compilationUnitNode) { - var _namespace = namespace - - if (compilationUnitNode['package']) { - var _package = this.translatePackage(options, namespace, compilationUnitNode['package']) + translateCompilationUnit(options, namespace, compilationUnitNode) { + var _namespace = namespace; + + if (compilationUnitNode["package"]) { + var _package = this.translatePackage( + options, + namespace, + compilationUnitNode["package"], + ); if (_package !== null) { - _namespace = _package + _namespace = _package; } } // Translate Types - this.translateTypes(options, _namespace, compilationUnitNode.types) + this.translateTypes(options, _namespace, compilationUnitNode.types); } /** @@ -646,24 +727,24 @@ class JavaCodeAnalyzer { * @param {type.Model} namespace * @param {Array.} typeNodeArray */ - translateTypes (options, namespace, typeNodeArray) { - var i, len + translateTypes(options, namespace, typeNodeArray) { + var i, len; if (Array.isArray(typeNodeArray) && typeNodeArray.length > 0) { for (i = 0, len = typeNodeArray.length; i < len; i++) { - var typeNode = typeNodeArray[i] + var typeNode = typeNodeArray[i]; switch (typeNode.node) { - case 'Class': - this.translateClass(options, namespace, typeNode) - break - case 'Interface': - this.translateInterface(options, namespace, typeNode) - break - case 'Enum': - this.translateEnum(options, namespace, typeNode) - break - case 'AnnotationType': - this.translateAnnotationType(options, namespace, typeNode) - break + case "Class": + this.translateClass(options, namespace, typeNode); + break; + case "Interface": + this.translateInterface(options, namespace, typeNode); + break; + case "Enum": + this.translateEnum(options, namespace, typeNode); + break; + case "AnnotationType": + this.translateAnnotationType(options, namespace, typeNode); + break; } } } @@ -675,12 +756,16 @@ class JavaCodeAnalyzer { * @param {type.Model} namespace * @param {Object} compilationUnitNode */ - translatePackage (options, namespace, packageNode) { - if (packageNode && packageNode.qualifiedName && packageNode.qualifiedName.name) { - var pathNames = packageNode.qualifiedName.name.split('.') - return this._ensurePackage(namespace, pathNames) + translatePackage(options, namespace, packageNode) { + if ( + packageNode && + packageNode.qualifiedName && + packageNode.qualifiedName.name + ) { + var pathNames = packageNode.qualifiedName.name.split("."); + return this._ensurePackage(namespace, pathNames); } - return null + return null; } /** @@ -689,38 +774,45 @@ class JavaCodeAnalyzer { * @param {type.Model} namespace * @param {Array.} memberNodeArray */ - translateMembers (options, namespace, memberNodeArray) { - var i, len + translateMembers(options, namespace, memberNodeArray) { + var i, len; if (Array.isArray(memberNodeArray) && memberNodeArray.length > 0) { for (i = 0, len = memberNodeArray.length; i < len; i++) { - var memberNode = memberNodeArray[i] - if (memberNode && (typeof memberNode.node === 'string')) { - var visibility = this._getVisibility(memberNode.modifiers) + var memberNode = memberNodeArray[i]; + if (memberNode && typeof memberNode.node === "string") { + var visibility = this._getVisibility(memberNode.modifiers); // Generate public members only if publicOnly == true - if (options.publicOnly && visibility !== type.UMLModelElement.VK_PUBLIC) { - continue + if ( + options.publicOnly && + visibility !== type.UMLModelElement.VK_PUBLIC + ) { + continue; } - memberNode.compilationUnitNode = this._currentCompilationUnit + memberNode.compilationUnitNode = this._currentCompilationUnit; switch (memberNode.node) { - case 'Field': - if (options.association) { - this.translateFieldAsAssociation(options, namespace, memberNode) - } else { - this.translateFieldAsAttribute(options, namespace, memberNode) - } - break - case 'Constructor': - this.translateMethod(options, namespace, memberNode, true) - break - case 'Method': - this.translateMethod(options, namespace, memberNode) - break - case 'EnumConstant': - this.translateEnumConstant(options, namespace, memberNode) - break + case "Field": + if (options.association) { + this.translateFieldAsAssociation( + options, + namespace, + memberNode, + ); + } else { + this.translateFieldAsAttribute(options, namespace, memberNode); + } + break; + case "Constructor": + this.translateMethod(options, namespace, memberNode, true); + break; + case "Method": + this.translateMethod(options, namespace, memberNode); + break; + case "EnumConstant": + this.translateEnumConstant(options, namespace, memberNode); + break; } } } @@ -733,19 +825,19 @@ class JavaCodeAnalyzer { * @param {type.Model} namespace * @param {Object} typeParameterNodeArray */ - translateTypeParameters (options, namespace, typeParameterNodeArray) { + translateTypeParameters(options, namespace, typeParameterNodeArray) { if (Array.isArray(typeParameterNodeArray)) { - var i, len, _typeParam + var i, len, _typeParam; for (i = 0, len = typeParameterNodeArray.length; i < len; i++) { - _typeParam = typeParameterNodeArray[i] - if (_typeParam.node === 'TypeParameter') { - var _templateParameter = new type.UMLTemplateParameter() - _templateParameter._parent = namespace - _templateParameter.name = _typeParam.name + _typeParam = typeParameterNodeArray[i]; + if (_typeParam.node === "TypeParameter") { + var _templateParameter = new type.UMLTemplateParameter(); + _templateParameter._parent = namespace; + _templateParameter.name = _typeParam.name; if (_typeParam.type) { - _templateParameter.parameterType = _typeParam.type + _templateParameter.parameterType = _typeParam.type; } - namespace.templateParameters.push(_templateParameter) + namespace.templateParameters.push(_templateParameter); } } } @@ -757,44 +849,44 @@ class JavaCodeAnalyzer { * @param {type.Model} namespace * @param {Object} compilationUnitNode */ - translateClass (options, namespace, classNode) { - var i, len, _class + translateClass(options, namespace, classNode) { + var i, len, _class; // Create Class - _class = new type.UMLClass() - _class._parent = namespace - _class.name = classNode.name + _class = new type.UMLClass(); + _class._parent = namespace; + _class.name = classNode.name; // Access Modifiers - _class.visibility = this._getVisibility(classNode.modifiers) + _class.visibility = this._getVisibility(classNode.modifiers); // Abstract Class - if (classNode.modifiers && classNode.modifiers.includes('abstract')) { - _class.isAbstract = true + if (classNode.modifiers && classNode.modifiers.includes("abstract")) { + _class.isAbstract = true; } // Final Class - if (classNode.modifiers && classNode.modifiers.includes('final')) { - _class.isFinalSpecialization = true - _class.isLeaf = true + if (classNode.modifiers && classNode.modifiers.includes("final")) { + _class.isFinalSpecialization = true; + _class.isLeaf = true; } // JavaDoc if (classNode.comment) { - _class.documentation = classNode.comment + _class.documentation = classNode.comment; } - namespace.ownedElements.push(_class) + namespace.ownedElements.push(_class); // Register Extends for 2nd Phase Translation - if (classNode['extends']) { + if (classNode["extends"]) { var _extendPending = { classifier: _class, - node: classNode['extends'], - kind: 'class', - compilationUnitNode: this._currentCompilationUnit - } - this._extendPendings.push(_extendPending) + node: classNode["extends"], + kind: "class", + compilationUnitNode: this._currentCompilationUnit, + }; + this._extendPendings.push(_extendPending); } // - 1) 타입이 소스에 있는 경우 --> 해당 타입으로 Generalization 생성 @@ -802,23 +894,23 @@ class JavaCodeAnalyzer { // 모든 타입이 생성된 다음에 Generalization (혹은 기타 Relationships)이 연결되어야 하므로, 어딘가에 등록한 다음이 2nd Phase에서 처리. // Register Implements for 2nd Phase Translation - if (classNode['implements']) { - for (i = 0, len = classNode['implements'].length; i < len; i++) { - var _impl = classNode['implements'][i] + if (classNode["implements"]) { + for (i = 0, len = classNode["implements"].length; i < len; i++) { + var _impl = classNode["implements"][i]; var _implementPending = { classifier: _class, node: _impl, - compilationUnitNode: this._currentCompilationUnit - } - this._implementPendings.push(_implementPending) + compilationUnitNode: this._currentCompilationUnit, + }; + this._implementPendings.push(_implementPending); } } // Translate Type Parameters - this.translateTypeParameters(options, _class, classNode.typeParameters) + this.translateTypeParameters(options, _class, classNode.typeParameters); // Translate Types - this.translateTypes(options, _class, classNode.body) + this.translateTypes(options, _class, classNode.body); // Translate Members - this.translateMembers(options, _class, classNode.body) + this.translateMembers(options, _class, classNode.body); } /** @@ -827,41 +919,45 @@ class JavaCodeAnalyzer { * @param {type.Model} namespace * @param {Object} interfaceNode */ - translateInterface (options, namespace, interfaceNode) { - var i, len, _interface + translateInterface(options, namespace, interfaceNode) { + var i, len, _interface; // Create Interface - _interface = new type.UMLInterface() - _interface._parent = namespace - _interface.name = interfaceNode.name - _interface.visibility = this._getVisibility(interfaceNode.modifiers) + _interface = new type.UMLInterface(); + _interface._parent = namespace; + _interface.name = interfaceNode.name; + _interface.visibility = this._getVisibility(interfaceNode.modifiers); // JavaDoc if (interfaceNode.comment) { - _interface.documentation = interfaceNode.comment + _interface.documentation = interfaceNode.comment; } - namespace.ownedElements.push(_interface) + namespace.ownedElements.push(_interface); // Register Extends for 2nd Phase Translation - if (interfaceNode['extends']) { - for (i = 0, len = interfaceNode['extends'].length; i < len; i++) { - var _extend = interfaceNode['extends'][i] + if (interfaceNode["extends"]) { + for (i = 0, len = interfaceNode["extends"].length; i < len; i++) { + var _extend = interfaceNode["extends"][i]; this._extendPendings.push({ classifier: _interface, node: _extend, - kind: 'interface', - compilationUnitNode: this._currentCompilationUnit - }) + kind: "interface", + compilationUnitNode: this._currentCompilationUnit, + }); } } // Translate Type Parameters - this.translateTypeParameters(options, _interface, interfaceNode.typeParameters) + this.translateTypeParameters( + options, + _interface, + interfaceNode.typeParameters, + ); // Translate Types - this.translateTypes(options, _interface, interfaceNode.body) + this.translateTypes(options, _interface, interfaceNode.body); // Translate Members - this.translateMembers(options, _interface, interfaceNode.body) + this.translateMembers(options, _interface, interfaceNode.body); } /** @@ -870,28 +966,28 @@ class JavaCodeAnalyzer { * @param {type.Model} namespace * @param {Object} enumNode */ - translateEnum (options, namespace, enumNode) { - var _enum + translateEnum(options, namespace, enumNode) { + var _enum; // Create Enumeration - _enum = new type.UMLEnumeration() - _enum._parent = namespace - _enum.name = enumNode.name - _enum.visibility = this._getVisibility(enumNode.modifiers) + _enum = new type.UMLEnumeration(); + _enum._parent = namespace; + _enum.name = enumNode.name; + _enum.visibility = this._getVisibility(enumNode.modifiers); // JavaDoc if (enumNode.comment) { - _enum.documentation = enumNode.comment + _enum.documentation = enumNode.comment; } - namespace.ownedElements.push(_enum) + namespace.ownedElements.push(_enum); // Translate Type Parameters - this.translateTypeParameters(options, _enum, enumNode.typeParameters) + this.translateTypeParameters(options, _enum, enumNode.typeParameters); // Translate Types - this.translateTypes(options, _enum, enumNode.body) + this.translateTypes(options, _enum, enumNode.body); // Translate Members - this.translateMembers(options, _enum, enumNode.body) + this.translateMembers(options, _enum, enumNode.body); } /** @@ -900,29 +996,35 @@ class JavaCodeAnalyzer { * @param {type.Model} namespace * @param {Object} annotationTypeNode */ - translateAnnotationType (options, namespace, annotationTypeNode) { - var _annotationType + translateAnnotationType(options, namespace, annotationTypeNode) { + var _annotationType; // Create Class <> - _annotationType = new type.UMLClass() - _annotationType._parent = namespace - _annotationType.name = annotationTypeNode.name - _annotationType.stereotype = 'annotationType' - _annotationType.visibility = this._getVisibility(annotationTypeNode.modifiers) + _annotationType = new type.UMLClass(); + _annotationType._parent = namespace; + _annotationType.name = annotationTypeNode.name; + _annotationType.stereotype = "annotationType"; + _annotationType.visibility = this._getVisibility( + annotationTypeNode.modifiers, + ); // JavaDoc if (annotationTypeNode.comment) { - _annotationType.documentation = annotationTypeNode.comment + _annotationType.documentation = annotationTypeNode.comment; } - namespace.ownedElements.push(_annotationType) + namespace.ownedElements.push(_annotationType); // Translate Type Parameters - this.translateTypeParameters(options, _annotationType, annotationTypeNode.typeParameters) + this.translateTypeParameters( + options, + _annotationType, + annotationTypeNode.typeParameters, + ); // Translate Types - this.translateTypes(options, _annotationType, annotationTypeNode.body) + this.translateTypes(options, _annotationType, annotationTypeNode.body); // Translate Members - this.translateMembers(options, _annotationType, annotationTypeNode.body) + this.translateMembers(options, _annotationType, annotationTypeNode.body); } /** @@ -931,14 +1033,14 @@ class JavaCodeAnalyzer { * @param {type.Model} namespace * @param {Object} fieldNode */ - translateFieldAsAssociation (options, namespace, fieldNode) { + translateFieldAsAssociation(options, namespace, fieldNode) { if (fieldNode.variables && fieldNode.variables.length > 0) { // Add to _associationPendings var _associationPending = { classifier: namespace, - node: fieldNode - } - this._associationPendings.push(_associationPending) + node: fieldNode, + }; + this._associationPendings.push(_associationPending); } } @@ -948,58 +1050,58 @@ class JavaCodeAnalyzer { * @param {type.Model} namespace * @param {Object} fieldNode */ - translateFieldAsAttribute (options, namespace, fieldNode) { - var i, len + translateFieldAsAttribute(options, namespace, fieldNode) { + var i, len; if (fieldNode.variables && fieldNode.variables.length > 0) { for (i = 0, len = fieldNode.variables.length; i < len; i++) { - var variableNode = fieldNode.variables[i] + var variableNode = fieldNode.variables[i]; // Create Attribute - var _attribute = new type.UMLAttribute() - _attribute._parent = namespace - _attribute.name = variableNode.name + var _attribute = new type.UMLAttribute(); + _attribute._parent = namespace; + _attribute.name = variableNode.name; // Access Modifiers - _attribute.visibility = this._getVisibility(fieldNode.modifiers) + _attribute.visibility = this._getVisibility(fieldNode.modifiers); if (variableNode.initializer) { - _attribute.defaultValue = variableNode.initializer + _attribute.defaultValue = variableNode.initializer; } // Static Modifier - if (fieldNode.modifiers && fieldNode.modifiers.includes('static')) { - _attribute.isStatic = true + if (fieldNode.modifiers && fieldNode.modifiers.includes("static")) { + _attribute.isStatic = true; } // Final Modifier - if (fieldNode.modifiers && fieldNode.modifiers.includes('final')) { - _attribute.isLeaf = true - _attribute.isReadOnly = true + if (fieldNode.modifiers && fieldNode.modifiers.includes("final")) { + _attribute.isLeaf = true; + _attribute.isReadOnly = true; } // Volatile Modifier - if (fieldNode.modifiers && fieldNode.modifiers.includes('volatile')) { - this._addTag(_attribute, type.Tag.TK_BOOLEAN, 'volatile', true) + if (fieldNode.modifiers && fieldNode.modifiers.includes("volatile")) { + this._addTag(_attribute, type.Tag.TK_BOOLEAN, "volatile", true); } // Transient Modifier - if (fieldNode.modifiers && fieldNode.modifiers.includes('transient')) { - this._addTag(_attribute, type.Tag.TK_BOOLEAN, 'transient', true) + if (fieldNode.modifiers && fieldNode.modifiers.includes("transient")) { + this._addTag(_attribute, type.Tag.TK_BOOLEAN, "transient", true); } // JavaDoc if (fieldNode.comment) { - _attribute.documentation = fieldNode.comment + _attribute.documentation = fieldNode.comment; } - namespace.attributes.push(_attribute) + namespace.attributes.push(_attribute); // Add to _typedFeaturePendings var _typedFeature = { namespace: namespace, feature: _attribute, - node: fieldNode - } - this._typedFeaturePendings.push(_typedFeature) + node: fieldNode, + }; + this._typedFeaturePendings.push(_typedFeature); } } } @@ -1011,37 +1113,37 @@ class JavaCodeAnalyzer { * @param {Object} methodNode * @param {boolean} isConstructor */ - translateMethod (options, namespace, methodNode, isConstructor) { - var i, len - var _operation = new type.UMLOperation() - _operation._parent = namespace - _operation.name = methodNode.name - namespace.operations.push(_operation) + translateMethod(options, namespace, methodNode, isConstructor) { + var i, len; + var _operation = new type.UMLOperation(); + _operation._parent = namespace; + _operation.name = methodNode.name; + namespace.operations.push(_operation); // Modifiers - _operation.visibility = this._getVisibility(methodNode.modifiers) - if (methodNode.modifiers && methodNode.modifiers.includes('static')) { - _operation.isStatic = true + _operation.visibility = this._getVisibility(methodNode.modifiers); + if (methodNode.modifiers && methodNode.modifiers.includes("static")) { + _operation.isStatic = true; } - if (methodNode.modifiers && methodNode.modifiers.includes('abstract')) { - _operation.isAbstract = true + if (methodNode.modifiers && methodNode.modifiers.includes("abstract")) { + _operation.isAbstract = true; } - if (methodNode.modifiers && methodNode.modifiers.includes('final')) { - _operation.isLeaf = true + if (methodNode.modifiers && methodNode.modifiers.includes("final")) { + _operation.isLeaf = true; } - if (methodNode.modifiers && methodNode.modifiers.includes('synchronized')) { - _operation.concurrency = type.UMLBehavioralFeature.CCK_CONCURRENT + if (methodNode.modifiers && methodNode.modifiers.includes("synchronized")) { + _operation.concurrency = type.UMLBehavioralFeature.CCK_CONCURRENT; } - if (methodNode.modifiers && methodNode.modifiers.includes('native')) { - this._addTag(_operation, type.Tag.TK_BOOLEAN, 'native', true) + if (methodNode.modifiers && methodNode.modifiers.includes("native")) { + this._addTag(_operation, type.Tag.TK_BOOLEAN, "native", true); } - if (methodNode.modifiers && methodNode.modifiers.includes('strictfp')) { - this._addTag(_operation, type.Tag.TK_BOOLEAN, 'strictfp', true) + if (methodNode.modifiers && methodNode.modifiers.includes("strictfp")) { + this._addTag(_operation, type.Tag.TK_BOOLEAN, "strictfp", true); } // Constructor if (isConstructor) { - _operation.stereotype = 'constructor' + _operation.stereotype = "constructor"; } // Stuff to do here to grab the correct Javadoc and put it into parameters and return @@ -1049,52 +1151,61 @@ class JavaCodeAnalyzer { // Formal Parameters if (methodNode.parameters && methodNode.parameters.length > 0) { for (i = 0, len = methodNode.parameters.length; i < len; i++) { - var parameterNode = methodNode.parameters[i] - parameterNode.compilationUnitNode = methodNode.compilationUnitNode - this.translateParameter(options, _operation, parameterNode) + var parameterNode = methodNode.parameters[i]; + parameterNode.compilationUnitNode = methodNode.compilationUnitNode; + this.translateParameter(options, _operation, parameterNode); } } // Return Type if (methodNode.type) { - var _returnParam = new type.UMLParameter() - _returnParam._parent = _operation - _returnParam.name = '' - _returnParam.direction = type.UMLParameter.DK_RETURN + var _returnParam = new type.UMLParameter(); + _returnParam._parent = _operation; + _returnParam.name = ""; + _returnParam.direction = type.UMLParameter.DK_RETURN; // Add to _typedFeaturePendings this._typedFeaturePendings.push({ namespace: namespace, feature: _returnParam, - node: methodNode - }) - _operation.parameters.push(_returnParam) + node: methodNode, + }); + _operation.parameters.push(_returnParam); } // Throws if (methodNode.throws) { for (i = 0, len = methodNode.throws.length; i < len; i++) { - var _throwNode = methodNode.throws[i] + var _throwNode = methodNode.throws[i]; var _throwPending = { operation: _operation, node: _throwNode, - compilationUnitNode: methodNode.compilationUnitNode - } - this._throwPendings.push(_throwPending) + compilationUnitNode: methodNode.compilationUnitNode, + }; + this._throwPendings.push(_throwPending); } } // JavaDoc if (methodNode.comment) { - _operation.documentation = methodNode.comment + _operation.documentation = methodNode.comment; } // "default" for Annotation Type Element if (methodNode.defaultValue) { - this._addTag(_operation, type.Tag.TK_STRING, 'default', methodNode.defaultValue) + this._addTag( + _operation, + type.Tag.TK_STRING, + "default", + methodNode.defaultValue, + ); } // Translate Type Parameters - this.translateTypeParameters(options, _operation, methodNode.typeParameters) + this.translateTypeParameters( + options, + _operation, + methodNode.typeParameters, + ); } /** @@ -1103,17 +1214,17 @@ class JavaCodeAnalyzer { * @param {type.Model} namespace * @param {Object} enumConstantNode */ - translateEnumConstant (options, namespace, enumConstantNode) { - var _literal = new type.UMLEnumerationLiteral() - _literal._parent = namespace - _literal.name = enumConstantNode.name + translateEnumConstant(options, namespace, enumConstantNode) { + var _literal = new type.UMLEnumerationLiteral(); + _literal._parent = namespace; + _literal.name = enumConstantNode.name; // JavaDoc if (enumConstantNode.comment) { - _literal.documentation = enumConstantNode.comment + _literal.documentation = enumConstantNode.comment; } - namespace.literals.push(_literal) + namespace.literals.push(_literal); } /** @@ -1122,18 +1233,18 @@ class JavaCodeAnalyzer { * @param {type.Model} namespace * @param {Object} parameterNode */ - translateParameter (options, namespace, parameterNode) { - var _parameter = new type.UMLParameter() - _parameter._parent = namespace - _parameter.name = parameterNode.variable.name - namespace.parameters.push(_parameter) + translateParameter(options, namespace, parameterNode) { + var _parameter = new type.UMLParameter(); + _parameter._parent = namespace; + _parameter.name = parameterNode.variable.name; + namespace.parameters.push(_parameter); // Add to _typedFeaturePendings this._typedFeaturePendings.push({ namespace: namespace._parent, feature: _parameter, - node: parameterNode - }) + node: parameterNode, + }); } } @@ -1142,32 +1253,32 @@ class JavaCodeAnalyzer { * @param {string} basePath * @param {Object} options */ -function analyze (basePath, options) { - var javaAnalyzer = new JavaCodeAnalyzer() +function analyze(basePath, options) { + var javaAnalyzer = new JavaCodeAnalyzer(); - function visit (base) { - var stat = fs.lstatSync(base) + function visit(base) { + var stat = fs.lstatSync(base); if (stat.isFile()) { - var ext = path.extname(base).toLowerCase() - if (ext === '.java') { - javaAnalyzer.addFile(base) + var ext = path.extname(base).toLowerCase(); + if (ext === ".java") { + javaAnalyzer.addFile(base); } } else if (stat.isDirectory()) { - var files = fs.readdirSync(base) + var files = fs.readdirSync(base); if (files && files.length > 0) { - files.forEach(entry => { - var fullPath = path.join(base, entry) - visit(fullPath) - }) + files.forEach((entry) => { + var fullPath = path.join(base, entry); + visit(fullPath); + }); } } } // Traverse all file entries - visit(basePath) + visit(basePath); // Perform reverse engineering - javaAnalyzer.analyze(options) + javaAnalyzer.analyze(options); } -exports.analyze = analyze +exports.analyze = analyze; diff --git a/code-generator.js b/code-generator.js index 0604f8f..a826d89 100644 --- a/code-generator.js +++ b/code-generator.js @@ -21,9 +21,9 @@ * */ -const fs = require('fs') -const path = require('path') -const codegen = require('./codegen-utils') +const fs = require("fs"); +const path = require("path"); +const codegen = require("./codegen-utils"); /** * Return element's full path including parent's classes or interfaces @@ -31,52 +31,51 @@ const codegen = require('./codegen-utils') * @param {Array.} imports Used to collect import declarations * @return {string} */ -function getElemPath (elem, imports, curPackage) { +function getElemPath(elem, imports, curPackage) { // find package of elem and whole _type string with parents' decarations - var owner = elem._parent - var _name = elem.name + var owner = elem._parent; + var _name = elem.name; while (owner instanceof type.UMLClass || owner instanceof type.UMLInterface) { if (owner.name.length > 0) { - _name = owner.name +'.'+ _name + _name = owner.name + "." + _name; } else { - _name = '.'+ _name + _name = "." + _name; } - elem = owner - owner = owner._parent + elem = owner; + owner = owner._parent; } // generate _import as fullpath of owner package - var _fullImport = elem.name - var _import = '' + var _fullImport = elem.name; + var _import = ""; if (owner != null && owner != curPackage) { while (owner instanceof type.UMLPackage) { - _import = _fullImport //ignore final root package that would be view point - _fullImport = owner.name + '.' + _fullImport - owner = owner._parent + _import = _fullImport; //ignore final root package that would be view point + _fullImport = owner.name + "." + _fullImport; + owner = owner._parent; } - imports.add(_import) + imports.add(_import); } - return _name + return _name; } /** * Java Code Generator */ class JavaCodeGenerator { - /** * @constructor * * @param {type.UMLPackage} baseModel * @param {string} basePath generated files and directories to be placed */ - constructor (baseModel, basePath) { + constructor(baseModel, basePath) { /** @member {type.Model} */ - this.baseModel = baseModel + this.baseModel = baseModel; /** @member {string} */ - this.basePath = basePath + this.basePath = basePath; } /** @@ -84,17 +83,17 @@ class JavaCodeGenerator { * @param {Object} options * @return {string} */ - getIndentString (options) { + getIndentString(options) { if (options.useTab) { - return '\t' + return "\t"; } else { - var i - var len - var indent = [] + var i; + var len; + var indent = []; for (i = 0, len = options.indentSpaces; i < len; i++) { - indent.push(' ') + indent.push(" "); } - return indent.join('') + return indent.join(""); } } @@ -105,99 +104,143 @@ class JavaCodeGenerator { * @param {Object} options * @param {Object} curPackage */ - generate (elem, basePath, options, curPackage) { - var fullPath - var codeWriter - var codeWriter2 + generate(elem, basePath, options, curPackage) { + var fullPath; + var codeWriter; + var codeWriter2; - var imports = new Set() + var imports = new Set(); // Package if (elem instanceof type.UMLPackage) { - fullPath = path.join(basePath, elem.name) - fs.mkdirSync(fullPath) + fullPath = path.join(basePath, elem.name); + fs.mkdirSync(fullPath); if (Array.isArray(elem.ownedElements)) { - elem.ownedElements.forEach(child => { - return this.generate(child, fullPath, options, elem) - }) + elem.ownedElements.forEach((child) => { + return this.generate(child, fullPath, options, elem); + }); } } else if (elem instanceof type.UMLClass) { // AnnotationType - if (elem.stereotype === 'annotationType') { - fullPath = path.join(basePath, elem.name + '.java') - codeWriter = new codegen.CodeWriter(this.getIndentString(options)) - this.writePackageDeclaration(codeWriter, elem, options, imports, curPackage) - - codeWriter2 = new codegen.CodeWriter(this.getIndentString(options)) - this.writeAnnotationType(codeWriter2, elem, options, imports, curPackage) + if (elem.stereotype === "annotationType") { + fullPath = path.join(basePath, elem.name + ".java"); + codeWriter = new codegen.CodeWriter(this.getIndentString(options)); + this.writePackageDeclaration( + codeWriter, + elem, + options, + imports, + curPackage, + ); + + codeWriter2 = new codegen.CodeWriter(this.getIndentString(options)); + this.writeAnnotationType( + codeWriter2, + elem, + options, + imports, + curPackage, + ); if (imports.size > 0) { - codeWriter.writeLine() - imports.forEach(function(v,i,s) {codeWriter.writeLine('import ' + v + ';')}) + codeWriter.writeLine(); + imports.forEach(function (v, i, s) { + codeWriter.writeLine("import " + v + ";"); + }); } - codeWriter.writeLine() - codeWriter.writeLine('import java.io.*;') - codeWriter.writeLine('import java.util.*;') - codeWriter.writeLine('\n') - - fs.writeFileSync(fullPath, codeWriter.getData() + codeWriter2.getData()) - // Class + codeWriter.writeLine(); + codeWriter.writeLine("import java.io.*;"); + codeWriter.writeLine("import java.util.*;"); + codeWriter.writeLine("\n"); + + fs.writeFileSync( + fullPath, + codeWriter.getData() + codeWriter2.getData(), + ); + // Class } else { - fullPath = basePath + '/' + elem.name + '.java' - codeWriter = new codegen.CodeWriter(this.getIndentString(options)) - this.writePackageDeclaration(codeWriter, elem, options, imports, curPackage) + fullPath = basePath + "/" + elem.name + ".java"; + codeWriter = new codegen.CodeWriter(this.getIndentString(options)); + this.writePackageDeclaration( + codeWriter, + elem, + options, + imports, + curPackage, + ); + + codeWriter2 = new codegen.CodeWriter(this.getIndentString(options)); + this.writeClass(codeWriter2, elem, options, imports, curPackage); - codeWriter2 = new codegen.CodeWriter(this.getIndentString(options)) - this.writeClass(codeWriter2, elem, options, imports, curPackage) - if (imports.size > 0) { - codeWriter.writeLine() - imports.forEach(function(v,i,s) {codeWriter.writeLine('import ' + v + ';')}) + codeWriter.writeLine(); + imports.forEach(function (v, i, s) { + codeWriter.writeLine("import " + v + ";"); + }); } - codeWriter.writeLine() - codeWriter.writeLine('import java.io.*;') - codeWriter.writeLine('import java.util.*;') - codeWriter.writeLine('\n') - - fs.writeFileSync(fullPath, codeWriter.getData() + codeWriter2.getData()) + codeWriter.writeLine(); + codeWriter.writeLine("import java.io.*;"); + codeWriter.writeLine("import java.util.*;"); + codeWriter.writeLine("\n"); + + fs.writeFileSync( + fullPath, + codeWriter.getData() + codeWriter2.getData(), + ); } - // Interface + // Interface } else if (elem instanceof type.UMLInterface) { - fullPath = basePath + '/' + elem.name + '.java' - codeWriter = new codegen.CodeWriter(this.getIndentString(options)) - this.writePackageDeclaration(codeWriter, elem, options, imports, curPackage) - - codeWriter2 = new codegen.CodeWriter(this.getIndentString(options)) - this.writeInterface(codeWriter2, elem, options, imports, curPackage) - + fullPath = basePath + "/" + elem.name + ".java"; + codeWriter = new codegen.CodeWriter(this.getIndentString(options)); + this.writePackageDeclaration( + codeWriter, + elem, + options, + imports, + curPackage, + ); + + codeWriter2 = new codegen.CodeWriter(this.getIndentString(options)); + this.writeInterface(codeWriter2, elem, options, imports, curPackage); + if (imports.size > 0) { - codeWriter.writeLine() - imports.forEach(function(v,i,s) {codeWriter.writeLine('import ' + v + ';')}) + codeWriter.writeLine(); + imports.forEach(function (v, i, s) { + codeWriter.writeLine("import " + v + ";"); + }); } - codeWriter.writeLine() - codeWriter.writeLine('import java.io.*;') - codeWriter.writeLine('import java.util.*;') - codeWriter.writeLine('\n') + codeWriter.writeLine(); + codeWriter.writeLine("import java.io.*;"); + codeWriter.writeLine("import java.util.*;"); + codeWriter.writeLine("\n"); - fs.writeFileSync(fullPath, codeWriter.getData() + codeWriter2.getData()) + fs.writeFileSync(fullPath, codeWriter.getData() + codeWriter2.getData()); - // Enum + // Enum } else if (elem instanceof type.UMLEnumeration) { - fullPath = basePath + '/' + elem.name + '.java' - codeWriter = new codegen.CodeWriter(this.getIndentString(options)) - this.writePackageDeclaration(codeWriter, elem, options, imports, curPackage) + fullPath = basePath + "/" + elem.name + ".java"; + codeWriter = new codegen.CodeWriter(this.getIndentString(options)); + this.writePackageDeclaration( + codeWriter, + elem, + options, + imports, + curPackage, + ); + + codeWriter2 = new codegen.CodeWriter(this.getIndentString(options)); + this.writeEnum(codeWriter2, elem, options, imports, curPackage); - codeWriter2 = new codegen.CodeWriter(this.getIndentString(options)) - this.writeEnum(codeWriter2, elem, options, imports, curPackage) - if (imports.size > 0) { - codeWriter.writeLine() - imports.forEach(function(v,i,s) {codeWriter.writeLine('import ' + v + ';')}) + codeWriter.writeLine(); + imports.forEach(function (v, i, s) { + codeWriter.writeLine("import " + v + ";"); + }); } - codeWriter.writeLine('\n') + codeWriter.writeLine("\n"); - fs.writeFileSync(fullPath, codeWriter.getData() + codeWriter2.getData()) + fs.writeFileSync(fullPath, codeWriter.getData() + codeWriter2.getData()); } } @@ -206,16 +249,16 @@ class JavaCodeGenerator { * @param {type.Model} elem * @return {string} */ - getVisibility (elem) { + getVisibility(elem) { switch (elem.visibility) { - case type.UMLModelElement.VK_PUBLIC: - return 'public' - case type.UMLModelElement.VK_PROTECTED: - return 'protected' - case type.UMLModelElement.VK_PRIVATE: - return 'private' - } - return null + case type.UMLModelElement.VK_PUBLIC: + return "public"; + case type.UMLModelElement.VK_PROTECTED: + return "protected"; + case type.UMLModelElement.VK_PRIVATE: + return "private"; + } + return null; } /** @@ -223,29 +266,29 @@ class JavaCodeGenerator { * @param {type.Model} elem * @return {Array.} */ - getModifiers (elem) { - var modifiers = [] - var visibility = this.getVisibility(elem) + getModifiers(elem) { + var modifiers = []; + var visibility = this.getVisibility(elem); if (visibility) { - modifiers.push(visibility) + modifiers.push(visibility); } if (elem.isStatic === true) { - modifiers.push('static') + modifiers.push("static"); } if (elem.isAbstract === true) { - modifiers.push('abstract') + modifiers.push("abstract"); } if (elem.isFinalSpecialization === true || elem.isLeaf === true) { - modifiers.push('final') + modifiers.push("final"); } if (elem.concurrency === type.UMLBehavioralFeature.CCK_CONCURRENT) { - modifiers.push('synchronized') + modifiers.push("synchronized"); } // transient // strictfp // const // native - return modifiers + return modifiers; } /** @@ -253,11 +296,16 @@ class JavaCodeGenerator { * @param {type.Model} elem * @return {Array.} */ - getSuperClasses (elem) { - var generalizations = app.repository.getRelationshipsOf(elem, function (rel) { - return (rel instanceof type.UMLGeneralization && rel.source === elem) - }) - return generalizations.map(function (gen) { return gen.target }) + getSuperClasses(elem) { + var generalizations = app.repository.getRelationshipsOf( + elem, + function (rel) { + return rel instanceof type.UMLGeneralization && rel.source === elem; + }, + ); + return generalizations.map(function (gen) { + return gen.target; + }); } /** @@ -265,14 +313,21 @@ class JavaCodeGenerator { * @param {type.Model} elem * @return {Array.} */ - getSuperInterfaces (elem) { + getSuperInterfaces(elem) { if (elem instanceof type.UMLClass) { - var realizations = app.repository.getRelationshipsOf(elem, function (rel) { - return (rel instanceof type.UMLInterfaceRealization && rel.source === elem) - }) - return realizations.map(function (gen) { return gen.target }) + var realizations = app.repository.getRelationshipsOf( + elem, + function (rel) { + return ( + rel instanceof type.UMLInterfaceRealization && rel.source === elem + ); + }, + ); + return realizations.map(function (gen) { + return gen.target; + }); } else { - return this.getSuperClasses(elem) + return this.getSuperClasses(elem); } } @@ -282,14 +337,14 @@ class JavaCodeGenerator { * @param {Set.} allExtendsSet Used to avoid repeated elements in allExtends array * @param {Array.} allExtends Used to collect super classes in order */ - collectExtends (elem, allExtendsSet, allExtends) { - var _exts = this.getSuperClasses(elem) + collectExtends(elem, allExtendsSet, allExtends) { + var _exts = this.getSuperClasses(elem); for (var i = 0; i < _exts.length; i++) { - var _ext = _exts[i] - this.collectExtends(_ext, allExtendsSet, allExtends) + var _ext = _exts[i]; + this.collectExtends(_ext, allExtendsSet, allExtends); if (!allExtendsSet.has(_ext)) { - allExtendsSet.add(_ext) - allExtends.push(_ext) + allExtendsSet.add(_ext); + allExtends.push(_ext); } } } @@ -300,58 +355,68 @@ class JavaCodeGenerator { * @param {Set.} allImplementsSet Used to avoid repeated elements in allImplements array * @param {Array.} allImplements Used to collect super interfaces in order */ - collectImplements (elem, allImplementsSet, allImplements) { - var _impls = this.getSuperInterfaces(elem) + collectImplements(elem, allImplementsSet, allImplements) { + var _impls = this.getSuperInterfaces(elem); for (var i = 0; i < _impls.length; i++) { - var _impl = _impls[i] - this.collectImplements(_impl, allImplementsSet, allImplements) + var _impl = _impls[i]; + this.collectImplements(_impl, allImplementsSet, allImplements); if (!allImplementsSet.has(_impl)) { - allImplementsSet.add(_impl) - allImplements.push(_impl) + allImplementsSet.add(_impl); + allImplements.push(_impl); } } } - + /** * Return type expression * @param {type.Model} elem * @param {Array.} imports Used to collect import declarations * @return {string} */ - getType (elem, imports, curPackage) { - var _type = 'void' - var typeElem = null - + getType(elem, imports, curPackage) { + var _type = "void"; + var typeElem = null; + // type name if (elem instanceof type.UMLAssociationEnd) { - if (elem.reference instanceof type.UMLModelElement && elem.reference.name.length > 0) { - typeElem = elem.reference + if ( + elem.reference instanceof type.UMLModelElement && + elem.reference.name.length > 0 + ) { + typeElem = elem.reference; // inner types need add owner's name as prefix - _type = getElemPath(typeElem, imports, curPackage) - } + _type = getElemPath(typeElem, imports, curPackage); + } } else { - if (elem.type instanceof type.UMLModelElement && elem.type.name.length > 0) { - typeElem = elem.type + if ( + elem.type instanceof type.UMLModelElement && + elem.type.name.length > 0 + ) { + typeElem = elem.type; // inner types need add owner's name as prefix - _type = getElemPath(typeElem, imports, curPackage) - } else if ((typeof elem.type === 'string') && elem.type.length > 0) { - _type = elem.type + _type = getElemPath(typeElem, imports, curPackage); + } else if (typeof elem.type === "string" && elem.type.length > 0) { + _type = elem.type; } } - + // multiplicity if (elem.multiplicity) { - if (['0..*', '1..*', '*'].includes(elem.multiplicity.trim())) { + if (["0..*", "1..*", "*"].includes(elem.multiplicity.trim())) { if (elem.isOrdered === true) { - _type = 'List<' + _type + '>' + _type = "List<" + _type + ">"; } else { - _type = 'Set<' + _type + '>' + _type = "Set<" + _type + ">"; } - } else if (elem.multiplicity !== '1' && elem.multiplicity.match(/^\d+$/)) { // number - _type += '[]' + } else if ( + elem.multiplicity !== "1" && + elem.multiplicity.match(/^\d+$/) + ) { + // number + _type += "[]"; } } - return _type + return _type; } /** @@ -362,15 +427,15 @@ class JavaCodeGenerator { * @param {Set.} imports * @param {Object} curPackage */ - writeDoc (codeWriter, text, options, imports, curPackage) { - var i, len, lines - if (options.javaDoc && (typeof text === 'string')) { - lines = text.trim().split('\n') - codeWriter.writeLine('/**') + writeDoc(codeWriter, text, options, imports, curPackage) { + var i, len, lines; + if (options.javaDoc && typeof text === "string") { + lines = text.trim().split("\n"); + codeWriter.writeLine("/**"); for (i = 0, len = lines.length; i < len; i++) { - codeWriter.writeLine(' * ' + lines[i]) + codeWriter.writeLine(" * " + lines[i]); } - codeWriter.writeLine(' */') + codeWriter.writeLine(" */"); } } @@ -382,13 +447,18 @@ class JavaCodeGenerator { * @param {Set.} imports * @param {Object} curPackage */ - writePackageDeclaration (codeWriter, elem, options, imports, curPackage) { - var packagePath = null + writePackageDeclaration(codeWriter, elem, options, imports, curPackage) { + var packagePath = null; if (elem._parent) { - packagePath = elem._parent.getPath(this.baseModel).map(function (e) { return e.name }).join('.') + packagePath = elem._parent + .getPath(this.baseModel) + .map(function (e) { + return e.name; + }) + .join("."); } if (packagePath) { - codeWriter.writeLine('package ' + packagePath + ';') + codeWriter.writeLine("package " + packagePath + ";"); } } @@ -398,19 +468,25 @@ class JavaCodeGenerator { * @param {type.Model} elem * @param {Object} options */ - writeConstructor (codeWriter, elem, options, imports, curPackage) { + writeConstructor(codeWriter, elem, options, imports, curPackage) { if (elem.name.length > 0) { - var terms = [] + var terms = []; // Doc - this.writeDoc(codeWriter, 'Default constructor', options, imports, curPackage) + this.writeDoc( + codeWriter, + "Default constructor", + options, + imports, + curPackage, + ); // Visibility - var visibility = this.getVisibility(elem) + var visibility = this.getVisibility(elem); if (visibility) { - terms.push(visibility) + terms.push(visibility); } - terms.push(elem.name + '()') - codeWriter.writeLine(terms.join(' ') + ' {') - codeWriter.writeLine('}') + terms.push(elem.name + "()"); + codeWriter.writeLine(terms.join(" ") + " {"); + codeWriter.writeLine("}"); } } @@ -422,25 +498,31 @@ class JavaCodeGenerator { * @param {Set.} imports * @param {Object} curPackage */ - writeMemberVariable (codeWriter, elem, options, imports, curPackage) { + writeMemberVariable(codeWriter, elem, options, imports, curPackage) { if (elem.name.length > 0) { - var terms = [] + var terms = []; // doc - this.writeDoc(codeWriter, elem.documentation, options, imports, curPackage) + this.writeDoc( + codeWriter, + elem.documentation, + options, + imports, + curPackage, + ); // modifiers - var _modifiers = this.getModifiers(elem) + var _modifiers = this.getModifiers(elem); if (_modifiers.length > 0) { - terms.push(_modifiers.join(' ')) + terms.push(_modifiers.join(" ")); } // type - terms.push(this.getType(elem, imports, curPackage)) + terms.push(this.getType(elem, imports, curPackage)); // name - terms.push(elem.name) + terms.push(elem.name); // initial value if (elem.defaultValue && elem.defaultValue.length > 0) { - terms.push('= ' + elem.defaultValue) + terms.push("= " + elem.defaultValue); } - codeWriter.writeLine(terms.join(' ') + ';') + codeWriter.writeLine(terms.join(" ") + ";"); } } @@ -456,99 +538,123 @@ class JavaCodeGenerator { * @param {Set.} imports * @param {Object} curPackage */ - writeMethod (codeWriter, elem, owner, options, skipBody, skipParams, declaredBy, imports, curPackage) { + writeMethod( + codeWriter, + elem, + owner, + options, + skipBody, + skipParams, + declaredBy, + imports, + curPackage, + ) { if (elem.name.length > 0) { - var terms = [] - var params = elem.getNonReturnParameters() - var returnParam = elem.getReturnParameter() + var terms = []; + var params = elem.getNonReturnParameters(); + var returnParam = elem.getReturnParameter(); // doc - var doc = elem.documentation.trim() + var doc = elem.documentation.trim(); // Erase Javadoc @param and @return - var i - var lines = doc.split('\n') - doc = '' + var i; + var lines = doc.split("\n"); + doc = ""; for (i = 0, len = lines.length; i < len; i++) { - if (lines[i].lastIndexOf('@param', 0) !== 0 && lines[i].lastIndexOf('@return', 0) !== 0) { - doc += '\n' + lines[i] + if ( + lines[i].lastIndexOf("@param", 0) !== 0 && + lines[i].lastIndexOf("@return", 0) !== 0 + ) { + doc += "\n" + lines[i]; } } params.forEach(function (param) { - doc += '\n@param ' + param.name + ' ' + param.documentation - }) + doc += "\n@param " + param.name + " " + param.documentation; + }); if (returnParam) { - doc += '\n@return ' + returnParam.documentation + doc += "\n@return " + returnParam.documentation; } - this.writeDoc(codeWriter, doc, options, imports, curPackage) + this.writeDoc(codeWriter, doc, options, imports, curPackage); // modifiers - var _modifiers = this.getModifiers(elem) + var _modifiers = this.getModifiers(elem); if (_modifiers.length > 0) { - terms.push(_modifiers.join(' ')) + terms.push(_modifiers.join(" ")); } // type if (returnParam) { - terms.push(this.getType(returnParam, imports, curPackage)) + terms.push(this.getType(returnParam, imports, curPackage)); } else { if (elem.name === owner.name) { //constructor has no return - }else{ - terms.push('void') + } else { + terms.push("void"); } } // name + parameters - var paramTerms = [] + var paramTerms = []; if (!skipParams) { - var len + var len; for (i = 0, len = params.length; i < len; i++) { - var p = params[i] - var s = this.getType(p, imports, curPackage) + ' ' + p.name + var p = params[i]; + var s = this.getType(p, imports, curPackage) + " " + p.name; if (p.isReadOnly === true) { - s = 'final ' + s + s = "final " + s; } - paramTerms.push(s) + paramTerms.push(s); } } - terms.push(elem.name + '(' + paramTerms.join(', ') + ')') + terms.push(elem.name + "(" + paramTerms.join(", ") + ")"); // body - if (skipBody === true || _modifiers.includes('abstract')) { - codeWriter.writeLine(terms.join(' ') + ';') + if (skipBody === true || _modifiers.includes("abstract")) { + codeWriter.writeLine(terms.join(" ") + ";"); } else { - codeWriter.writeLine(terms.join(' ') + ' {') - codeWriter.indent() + codeWriter.writeLine(terms.join(" ") + " {"); + codeWriter.indent(); if (declaredBy === owner) { - codeWriter.writeLine('// TODO implement here') + codeWriter.writeLine("// TODO implement here"); } else { - codeWriter.writeLine('// TODO implement ' + declaredBy.name + '.' + elem.name + '() here') + codeWriter.writeLine( + "// TODO implement " + + declaredBy.name + + "." + + elem.name + + "() here", + ); } - + // return statement if (returnParam) { - var returnType = this.getType(returnParam, imports, curPackage) - if (returnType === 'boolean') { - codeWriter.writeLine('return false;') - } else if (returnType === 'int' || returnType === 'long' || returnType === 'short' || returnType === 'byte') { - codeWriter.writeLine('return 0;') - } else if (returnType === 'float') { - codeWriter.writeLine('return 0.0f;') - } else if (returnType === 'double') { - codeWriter.writeLine('return 0.0d;') - } else if (returnType === 'char') { - codeWriter.writeLine('return "0";') - } else if (returnType === 'String') { - codeWriter.writeLine('return "";') + var returnType = this.getType(returnParam, imports, curPackage); + if (returnType === "boolean") { + codeWriter.writeLine("return false;"); + } else if ( + returnType === "int" || + returnType === "long" || + returnType === "short" || + returnType === "byte" + ) { + codeWriter.writeLine("return 0;"); + } else if (returnType === "float") { + codeWriter.writeLine("return 0.0f;"); + } else if (returnType === "double") { + codeWriter.writeLine("return 0.0d;"); + } else if (returnType === "char") { + codeWriter.writeLine('return "0";'); + } else if (returnType === "String") { + codeWriter.writeLine('return "";'); } else { - codeWriter.writeLine('return null;') + codeWriter.writeLine("return null;"); } } - codeWriter.outdent() - codeWriter.writeLine('}') + codeWriter.outdent(); + codeWriter.writeLine("}"); } } } @@ -561,135 +667,208 @@ class JavaCodeGenerator { * @param {Set.} imports * @param {Object} curPackage */ - writeClass (codeWriter, elem, options, imports, curPackage) { - var i, len - var terms = [] + writeClass(codeWriter, elem, options, imports, curPackage) { + var i, len; + var terms = []; // Doc - var doc = elem.documentation.trim() - if (app.project.getProject().author && app.project.getProject().author.length > 0) { - doc += '\n@author ' + app.project.getProject().author + var doc = elem.documentation.trim(); + if ( + app.project.getProject().author && + app.project.getProject().author.length > 0 + ) { + doc += "\n@author " + app.project.getProject().author; } - this.writeDoc(codeWriter, doc, options, imports, curPackage) + this.writeDoc(codeWriter, doc, options, imports, curPackage); // Modifiers - var _modifiers = this.getModifiers(elem) - if (_modifiers.includes('abstract') !== true && elem.operations.some(function (op) { return op.isAbstract === true })) { - _modifiers.push('abstract') + var _modifiers = this.getModifiers(elem); + if ( + _modifiers.includes("abstract") !== true && + elem.operations.some(function (op) { + return op.isAbstract === true; + }) + ) { + _modifiers.push("abstract"); } if (_modifiers.length > 0) { - terms.push(_modifiers.join(' ')) + terms.push(_modifiers.join(" ")); } // Class - terms.push('class') - terms.push(elem.name) + terms.push("class"); + terms.push(elem.name); // Extends - var _extends = this.getSuperClasses(elem) + var _extends = this.getSuperClasses(elem); if (_extends.length > 0) { - terms.push('extends ' + getElemPath(_extends[0], imports, curPackage)) + terms.push("extends " + getElemPath(_extends[0], imports, curPackage)); } // Implements - var _implements = this.getSuperInterfaces(elem) + var _implements = this.getSuperInterfaces(elem); if (_implements.length > 0) { - terms.push('implements ' + _implements.map(function (e) {return getElemPath(e, imports, curPackage)}).join(', ')) + terms.push( + "implements " + + _implements + .map(function (e) { + return getElemPath(e, imports, curPackage); + }) + .join(", "), + ); } - codeWriter.writeLine(terms.join(' ') + ' {') - codeWriter.writeLine() - codeWriter.indent() + codeWriter.writeLine(terms.join(" ") + " {"); + codeWriter.writeLine(); + codeWriter.indent(); // Constructor - this.writeConstructor(codeWriter, elem, options, imports, curPackage) - codeWriter.writeLine() + this.writeConstructor(codeWriter, elem, options, imports, curPackage); + codeWriter.writeLine(); // Member Variables // (from attributes) for (i = 0, len = elem.attributes.length; i < len; i++) { - this.writeMemberVariable(codeWriter, elem.attributes[i], options, imports, curPackage) - codeWriter.writeLine() + this.writeMemberVariable( + codeWriter, + elem.attributes[i], + options, + imports, + curPackage, + ); + codeWriter.writeLine(); } // (from associations) var associations = app.repository.getRelationshipsOf(elem, function (rel) { - return (rel instanceof type.UMLAssociation) - }) + return rel instanceof type.UMLAssociation; + }); for (i = 0, len = associations.length; i < len; i++) { - var asso = associations[i] + var asso = associations[i]; if (asso.end1.reference === elem && asso.end2.navigable === true) { - this.writeMemberVariable(codeWriter, asso.end2, options, imports, curPackage) - codeWriter.writeLine() + this.writeMemberVariable( + codeWriter, + asso.end2, + options, + imports, + curPackage, + ); + codeWriter.writeLine(); } if (asso.end2.reference === elem && asso.end1.navigable === true) { - this.writeMemberVariable(codeWriter, asso.end1, options, imports, curPackage) - codeWriter.writeLine() + this.writeMemberVariable( + codeWriter, + asso.end1, + options, + imports, + curPackage, + ); + codeWriter.writeLine(); } } // Methods for (i = 0, len = elem.operations.length; i < len; i++) { - this.writeMethod(codeWriter, elem.operations[i], elem, options, false, false, elem, imports, curPackage) - codeWriter.writeLine() + this.writeMethod( + codeWriter, + elem.operations[i], + elem, + options, + false, + false, + elem, + imports, + curPackage, + ); + codeWriter.writeLine(); } - + // Extends methods if (_extends.length > 0) { for (i = 0, len = _extends[0].operations.length; i < len; i++) { - var _modifiers2 = this.getModifiers(_extends[0].operations[i]) - if (_modifiers2.includes('abstract') === true) { - this.writeMethod(codeWriter, _extends[0].operations[i], elem, options, false, false, _extends[0], imports, curPackage) - codeWriter.writeLine() + var _modifiers2 = this.getModifiers(_extends[0].operations[i]); + if (_modifiers2.includes("abstract") === true) { + this.writeMethod( + codeWriter, + _extends[0].operations[i], + elem, + options, + false, + false, + _extends[0], + imports, + curPackage, + ); + codeWriter.writeLine(); } } } // Interface methods including all super interfaces - var _allExtendsSet = new Set() - var _allExtends = new Array() - this.collectExtends(elem, _allExtendsSet, _allExtends) + var _allExtendsSet = new Set(); + var _allExtends = new Array(); + this.collectExtends(elem, _allExtendsSet, _allExtends); // collect methods implemented by all extends to _allImplementsSet to be ignored when writeLine - var _allImplementsSet = new Set() - var _allImplements = new Array() + var _allImplementsSet = new Set(); + var _allImplements = new Array(); if (_allExtends.length > 0) { for (i = 0, len = _allExtends.length; i < len; i++) { - this.collectImplements(_allExtends[i], _allImplementsSet, _allImplements) + this.collectImplements( + _allExtends[i], + _allImplementsSet, + _allImplements, + ); } } // collect valid super interfaces - _allImplements.splice(0,_allImplements.length) - this.collectImplements(elem, _allImplementsSet, _allImplements) + _allImplements.splice(0, _allImplements.length); + this.collectImplements(elem, _allImplementsSet, _allImplements); // write methods in valid super interfaces for (var j = 0; j < _allImplements.length; j++) { for (i = 0, len = _allImplements[j].operations.length; i < len; i++) { - this.writeMethod(codeWriter, _allImplements[j].operations[i], elem, options, false, false, _allImplements[j], imports, curPackage) - codeWriter.writeLine() + this.writeMethod( + codeWriter, + _allImplements[j].operations[i], + elem, + options, + false, + false, + _allImplements[j], + imports, + curPackage, + ); + codeWriter.writeLine(); } } // Inner Definitions for (i = 0, len = elem.ownedElements.length; i < len; i++) { - var def = elem.ownedElements[i] + var def = elem.ownedElements[i]; if (def instanceof type.UMLClass) { - if (def.stereotype === 'annotationType') { - this.writeAnnotationType(codeWriter, def, options, imports, curPackage) + if (def.stereotype === "annotationType") { + this.writeAnnotationType( + codeWriter, + def, + options, + imports, + curPackage, + ); } else { - this.writeClass(codeWriter, def, options, imports, curPackage) + this.writeClass(codeWriter, def, options, imports, curPackage); } - codeWriter.writeLine() + codeWriter.writeLine(); } else if (def instanceof type.UMLInterface) { - this.writeInterface(codeWriter, def, options, imports, curPackage) - codeWriter.writeLine() + this.writeInterface(codeWriter, def, options, imports, curPackage); + codeWriter.writeLine(); } else if (def instanceof type.UMLEnumeration) { - this.writeEnum(codeWriter, def, options, imports, curPackage) - codeWriter.writeLine() + this.writeEnum(codeWriter, def, options, imports, curPackage); + codeWriter.writeLine(); } } - codeWriter.outdent() - codeWriter.writeLine('}') + codeWriter.outdent(); + codeWriter.writeLine("}"); } /** @@ -700,81 +879,122 @@ class JavaCodeGenerator { * @param {Set.} imports * @param {Object} curPackage */ - writeInterface (codeWriter, elem, options, imports, curPackage) { - var i, len - var terms = [] + writeInterface(codeWriter, elem, options, imports, curPackage) { + var i, len; + var terms = []; // Doc - this.writeDoc(codeWriter, elem.documentation, options, imports, curPackage) + this.writeDoc(codeWriter, elem.documentation, options, imports, curPackage); // Modifiers - var visibility = this.getVisibility(elem) + var visibility = this.getVisibility(elem); if (visibility) { - terms.push(visibility) + terms.push(visibility); } // Interface - terms.push('interface') - terms.push(elem.name) + terms.push("interface"); + terms.push(elem.name); // Extends - var _extends = this.getSuperClasses(elem) + var _extends = this.getSuperClasses(elem); if (_extends.length > 0) { - terms.push('extends ' + _extends.map(function (e) { return getElemPath(e, imports, curPackage) }).join(', ')) + terms.push( + "extends " + + _extends + .map(function (e) { + return getElemPath(e, imports, curPackage); + }) + .join(", "), + ); } - codeWriter.writeLine(terms.join(' ') + ' {') - codeWriter.writeLine() - codeWriter.indent() + codeWriter.writeLine(terms.join(" ") + " {"); + codeWriter.writeLine(); + codeWriter.indent(); // Member Variables // (from attributes) for (i = 0, len = elem.attributes.length; i < len; i++) { - this.writeMemberVariable(codeWriter, elem.attributes[i], options, imports, curPackage) - codeWriter.writeLine() + this.writeMemberVariable( + codeWriter, + elem.attributes[i], + options, + imports, + curPackage, + ); + codeWriter.writeLine(); } // (from associations) var associations = app.repository.getRelationshipsOf(elem, function (rel) { - return (rel instanceof type.UMLAssociation) - }) + return rel instanceof type.UMLAssociation; + }); for (i = 0, len = associations.length; i < len; i++) { - var asso = associations[i] + var asso = associations[i]; if (asso.end1.reference === elem && asso.end2.navigable === true) { - this.writeMemberVariable(codeWriter, asso.end2, options, imports, curPackage) - codeWriter.writeLine() + this.writeMemberVariable( + codeWriter, + asso.end2, + options, + imports, + curPackage, + ); + codeWriter.writeLine(); } if (asso.end2.reference === elem && asso.end1.navigable === true) { - this.writeMemberVariable(codeWriter, asso.end1, options, imports, curPackage) - codeWriter.writeLine() + this.writeMemberVariable( + codeWriter, + asso.end1, + options, + imports, + curPackage, + ); + codeWriter.writeLine(); } } // Methods for (i = 0, len = elem.operations.length; i < len; i++) { - this.writeMethod(codeWriter, elem.operations[i], elem, options, true, false, elem, imports, curPackage) - codeWriter.writeLine() + this.writeMethod( + codeWriter, + elem.operations[i], + elem, + options, + true, + false, + elem, + imports, + curPackage, + ); + codeWriter.writeLine(); } // Inner Definitions for (i = 0, len = elem.ownedElements.length; i < len; i++) { - var def = elem.ownedElements[i] + var def = elem.ownedElements[i]; if (def instanceof type.UMLClass) { - if (def.stereotype === 'annotationType') { - this.writeAnnotationType(codeWriter, def, options, imports, curPackage) + if (def.stereotype === "annotationType") { + this.writeAnnotationType( + codeWriter, + def, + options, + imports, + curPackage, + ); } else { - this.writeClass(codeWriter, def, options, imports, curPackage) + this.writeClass(codeWriter, def, options, imports, curPackage); } - codeWriter.writeLine() + codeWriter.writeLine(); } else if (def instanceof type.UMLInterface) { - this.writeInterface(codeWriter, def, options, imports, curPackage) - codeWriter.writeLine() + this.writeInterface(codeWriter, def, options, imports, curPackage); + codeWriter.writeLine(); } else if (def instanceof type.UMLEnumeration) { - this.writeEnum(codeWriter, def, options, imports, curPackage) - codeWriter.writeLine() + this.writeEnum(codeWriter, def, options, imports, curPackage); + codeWriter.writeLine(); } } - codeWriter.outdent() - codeWriter.writeLine('}') + codeWriter.outdent(); + codeWriter.writeLine("}"); } /** @@ -785,31 +1005,33 @@ class JavaCodeGenerator { * @param {Set.} imports * @param {Object} curPackage */ - writeEnum (codeWriter, elem, options, imports, curPackage) { - var i, len - var terms = [] + writeEnum(codeWriter, elem, options, imports, curPackage) { + var i, len; + var terms = []; // Doc - this.writeDoc(codeWriter, elem.documentation, options, imports, curPackage) + this.writeDoc(codeWriter, elem.documentation, options, imports, curPackage); // Modifiers - var visibility = this.getVisibility(elem) + var visibility = this.getVisibility(elem); if (visibility) { - terms.push(visibility) + terms.push(visibility); } // Enum - terms.push('enum') - terms.push(elem.name) + terms.push("enum"); + terms.push(elem.name); - codeWriter.writeLine(terms.join(' ') + ' {') - codeWriter.indent() + codeWriter.writeLine(terms.join(" ") + " {"); + codeWriter.indent(); // Literals for (i = 0, len = elem.literals.length; i < len; i++) { - codeWriter.writeLine(elem.literals[i].name + (i < elem.literals.length - 1 ? ',' : '')) + codeWriter.writeLine( + elem.literals[i].name + (i < elem.literals.length - 1 ? "," : ""), + ); } - codeWriter.outdent() - codeWriter.writeLine('}') + codeWriter.outdent(); + codeWriter.writeLine("}"); } /** @@ -820,79 +1042,119 @@ class JavaCodeGenerator { * @param {Set.} imports * @param {Object} curPackage */ - writeAnnotationType (codeWriter, elem, options, imports, curPackage) { - var i, len - var terms = [] + writeAnnotationType(codeWriter, elem, options, imports, curPackage) { + var i, len; + var terms = []; // Doc - var doc = elem.documentation.trim() - if (app.project.getProject().author && app.project.getProject().author.length > 0) { - doc += '\n@author ' + app.project.getProject().author + var doc = elem.documentation.trim(); + if ( + app.project.getProject().author && + app.project.getProject().author.length > 0 + ) { + doc += "\n@author " + app.project.getProject().author; } - this.writeDoc(codeWriter, doc, options, imports, curPackage) + this.writeDoc(codeWriter, doc, options, imports, curPackage); // Modifiers - var _modifiers = this.getModifiers(elem) - if (_modifiers.includes('abstract') !== true && elem.operations.some(function (op) { return op.isAbstract === true })) { - _modifiers.push('abstract') + var _modifiers = this.getModifiers(elem); + if ( + _modifiers.includes("abstract") !== true && + elem.operations.some(function (op) { + return op.isAbstract === true; + }) + ) { + _modifiers.push("abstract"); } if (_modifiers.length > 0) { - terms.push(_modifiers.join(' ')) + terms.push(_modifiers.join(" ")); } // AnnotationType - terms.push('@interface') - terms.push(elem.name) + terms.push("@interface"); + terms.push(elem.name); - codeWriter.writeLine(terms.join(' ') + ' {') - codeWriter.writeLine() - codeWriter.indent() + codeWriter.writeLine(terms.join(" ") + " {"); + codeWriter.writeLine(); + codeWriter.indent(); // Member Variables for (i = 0, len = elem.attributes.length; i < len; i++) { - this.writeMemberVariable(codeWriter, elem.attributes[i], options, imports, curPackage) - codeWriter.writeLine() + this.writeMemberVariable( + codeWriter, + elem.attributes[i], + options, + imports, + curPackage, + ); + codeWriter.writeLine(); } // Methods for (i = 0, len = elem.operations.length; i < len; i++) { - this.writeMethod(codeWriter, elem.operations[i], elem, options, true, true, elem, imports, curPackage) - codeWriter.writeLine() + this.writeMethod( + codeWriter, + elem.operations[i], + elem, + options, + true, + true, + elem, + imports, + curPackage, + ); + codeWriter.writeLine(); } // Extends methods - var _extends = this.getSuperClasses(elem) + var _extends = this.getSuperClasses(elem); if (_extends.length > 0) { for (i = 0, len = _extends[0].operations.length; i < len; i++) { - _modifiers = this.getModifiers(_extends[0].operations[i]) - if (_modifiers.includes('abstract') === true) { - this.writeMethod(codeWriter, _extends[0].operations[i], elem, options, false, false, _extends[0], imports, curPackage) - codeWriter.writeLine() + _modifiers = this.getModifiers(_extends[0].operations[i]); + if (_modifiers.includes("abstract") === true) { + this.writeMethod( + codeWriter, + _extends[0].operations[i], + elem, + options, + false, + false, + _extends[0], + imports, + curPackage, + ); + codeWriter.writeLine(); } } } // Inner Definitions for (i = 0, len = elem.ownedElements.length; i < len; i++) { - var def = elem.ownedElements[i] + var def = elem.ownedElements[i]; if (def instanceof type.UMLClass) { - if (def.stereotype === 'annotationType') { - this.writeAnnotationType(codeWriter, def, options, imports, curPackage) + if (def.stereotype === "annotationType") { + this.writeAnnotationType( + codeWriter, + def, + options, + imports, + curPackage, + ); } else { - this.writeClass(codeWriter, def, options, imports, curPackage) + this.writeClass(codeWriter, def, options, imports, curPackage); } - codeWriter.writeLine() + codeWriter.writeLine(); } else if (def instanceof type.UMLInterface) { - this.writeInterface(codeWriter, def, options, imports, curPackage) - codeWriter.writeLine() + this.writeInterface(codeWriter, def, options, imports, curPackage); + codeWriter.writeLine(); } else if (def instanceof type.UMLEnumeration) { - this.writeEnum(codeWriter, def, options, imports, curPackage) - codeWriter.writeLine() + this.writeEnum(codeWriter, def, options, imports, curPackage); + codeWriter.writeLine(); } } - codeWriter.outdent() - codeWriter.writeLine('}') + codeWriter.outdent(); + codeWriter.writeLine("}"); } } @@ -902,9 +1164,9 @@ class JavaCodeGenerator { * @param {string} basePath * @param {Object} options */ -function generate (baseModel, basePath, options) { - var javaCodeGenerator = new JavaCodeGenerator(baseModel, basePath) - javaCodeGenerator.generate(baseModel, basePath, options, null) +function generate(baseModel, basePath, options) { + var javaCodeGenerator = new JavaCodeGenerator(baseModel, basePath); + javaCodeGenerator.generate(baseModel, basePath, options, null); } -exports.generate = generate +exports.generate = generate; diff --git a/codegen-utils.js b/codegen-utils.js index 4eb4eda..0d553bd 100644 --- a/codegen-utils.js +++ b/codegen-utils.js @@ -28,40 +28,40 @@ class CodeWriter { /** * @constructor */ - constructor (indentString) { + constructor(indentString) { /** @member {Array.} lines */ - this.lines = [] + this.lines = []; /** @member {string} indentString */ - this.indentString = indentString || ' ' // default 4 spaces + this.indentString = indentString || " "; // default 4 spaces /** @member {Array.} indentations */ - this.indentations = [] + this.indentations = []; } /** * Indent */ - indent () { - this.indentations.push(this.indentString) + indent() { + this.indentations.push(this.indentString); } /** * Outdent */ - outdent () { - this.indentations.splice(this.indentations.length - 1, 1) + outdent() { + this.indentations.splice(this.indentations.length - 1, 1); } /** * Write a line * @param {string} line */ - writeLine (line) { + writeLine(line) { if (line) { - this.lines.push(this.indentations.join('') + line) + this.lines.push(this.indentations.join("") + line); } else { - this.lines.push('') + this.lines.push(""); } } @@ -69,10 +69,9 @@ class CodeWriter { * Return as all string data * @return {string} */ - getData () { - return this.lines.join('\n') + getData() { + return this.lines.join("\n"); } - } -exports.CodeWriter = CodeWriter +exports.CodeWriter = CodeWriter; diff --git a/main.js b/main.js index 4ff55c5..e3bbe64 100644 --- a/main.js +++ b/main.js @@ -21,25 +21,25 @@ * */ -const codeGenerator = require('./code-generator') -const codeAnalyzer = require('./code-analyzer') +const codeGenerator = require("./code-generator"); +const codeAnalyzer = require("./code-analyzer"); -function getGenOptions () { +function getGenOptions() { return { - javaDoc: app.preferences.get('java.gen.javaDoc'), - useTab: app.preferences.get('java.gen.useTab'), - indentSpaces: app.preferences.get('java.gen.indentSpaces') - } + javaDoc: app.preferences.get("java.gen.javaDoc"), + useTab: app.preferences.get("java.gen.useTab"), + indentSpaces: app.preferences.get("java.gen.indentSpaces"), + }; } -function getRevOptions () { +function getRevOptions() { return { - association: app.preferences.get('java.rev.association'), - publicOnly: app.preferences.get('java.rev.publicOnly'), - typeHierarchy: app.preferences.get('java.rev.typeHierarchy'), - packageOverview: app.preferences.get('java.rev.packageOverview'), - packageStructure: app.preferences.get('java.rev.packageStructure') - } + association: app.preferences.get("java.rev.association"), + publicOnly: app.preferences.get("java.rev.publicOnly"), + typeHierarchy: app.preferences.get("java.rev.typeHierarchy"), + packageOverview: app.preferences.get("java.rev.packageOverview"), + packageStructure: app.preferences.get("java.rev.packageStructure"), + }; } /** @@ -49,36 +49,52 @@ function getRevOptions () { * @param {string} path * @param {Object} options */ -function _handleGenerate (base, path, options) { +async function _handleGenerate(base, path, options) { // If options is not passed, get from preference - options = options || getGenOptions() + options = options || getGenOptions(); // If base is not assigned, popup ElementPicker if (!base) { - app.elementPickerDialog.showDialog('Select a base model to generate codes', null, type.UMLPackage).then(function ({buttonId, returnValue}) { - if (buttonId === 'ok') { - base = returnValue - // If path is not assigned, popup Open Dialog to select a folder - if (!path) { - var files = app.dialogs.showOpenDialog('Select a folder where generated codes to be located', null, null, { properties: [ 'openDirectory' ] }) - if (files && files.length > 0) { - path = files[0] - codeGenerator.generate(base, path, options) + app.elementPickerDialog + .showDialog( + "Select a base model to generate codes", + null, + type.UMLPackage, + ) + .then(async function ({ buttonId, returnValue }) { + if (buttonId === "ok") { + base = returnValue; + // If path is not assigned, popup Open Dialog to select a folder + if (!path) { + var files = await app.dialogs.showOpenDialogAsync( + "Select a folder where generated codes to be located", + null, + null, + { properties: ["openDirectory"] }, + ); + if (files && files.length > 0) { + path = files[0]; + codeGenerator.generate(base, path, options); + } + } else { + codeGenerator.generate(base, path, options); } - } else { - codeGenerator.generate(base, path, options) } - } - }) + }); } else { // If path is not assigned, popup Open Dialog to select a folder if (!path) { - var files = app.dialogs.showOpenDialog('Select a folder where generated codes to be located', null, null, { properties: [ 'openDirectory' ] }) + var files = await app.dialogs.showOpenDialogAsync( + "Select a folder where generated codes to be located", + null, + null, + { properties: ["openDirectory"] }, + ); if (files && files.length > 0) { - path = files[0] - codeGenerator.generate(base, path, options) + path = files[0]; + codeGenerator.generate(base, path, options); } } else { - codeGenerator.generate(base, path, options) + codeGenerator.generate(base, path, options); } } } @@ -89,15 +105,22 @@ function _handleGenerate (base, path, options) { * @param {string} basePath * @param {Object} options */ -function _handleReverse (basePath, options) { +async function _handleReverse(basePath, options) { // If options is not passed, get from preference - options = getRevOptions() + options = getRevOptions(); // If basePath is not assigned, popup Open Dialog to select a folder if (!basePath) { - var files = app.dialogs.showOpenDialog('Select Folder', null, null, { properties: [ 'openDirectory' ] }) + var files = await app.dialogs.showOpenDialogAsync( + "Select Folder", + null, + null, + { + properties: ["openDirectory"], + }, + ); if (files && files.length > 0) { - basePath = files[0] - codeAnalyzer.analyze(basePath, options) + basePath = files[0]; + codeAnalyzer.analyze(basePath, options); } } } @@ -105,14 +128,14 @@ function _handleReverse (basePath, options) { /** * Popup PreferenceDialog with Java Preference Schema */ -function _handleConfigure () { - app.commands.execute('application:preferences', 'java') +function _handleConfigure() { + app.commands.execute("application:preferences", "java"); } -function init () { - app.commands.register('java:generate', _handleGenerate) - app.commands.register('java:reverse', _handleReverse) - app.commands.register('java:configure', _handleConfigure) +function init() { + app.commands.register("java:generate", _handleGenerate); + app.commands.register("java:reverse", _handleReverse); + app.commands.register("java:configure", _handleConfigure); } -exports.init = init +exports.init = init; diff --git a/package.json b/package.json index a04e85a..c27ba3d 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "keywords": [ "java" ], - "version": "0.9.5", + "version": "0.9.6", "author": { "name": "Minkyu Lee", "email": "niklaus.lee@gmail.com", @@ -15,6 +15,6 @@ }, "license": "MIT", "engines": { - "staruml": ">=3.0.0" + "staruml": ">=6.0.0" } }