Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ec55e2e

Browse files
committed
Reverse JavaDoc to Documentation and add test cases for reverse.
1 parent d8f67dc commit ec55e2e

22 files changed

+996
-422
lines changed

JavaReverseEngineer.js

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
*
2222
*/
2323

24-
25-
// TODO: JavaDoc to Documentation.
26-
2724
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50, regexp: true */
2825
/*global define, $, _, window, staruml, type, document, java7 */
2926
define(function (require, exports, module) {
@@ -211,7 +208,6 @@ define(function (require, exports, module) {
211208
self._currentCompilationUnit = ast;
212209
self._currentCompilationUnit.file = file;
213210
self.translateCompilationUnit(options, self._root, ast);
214-
// self._currentCompilationUnit = null;
215211
result.resolve();
216212
} else {
217213
result.reject(err);
@@ -236,6 +232,7 @@ define(function (require, exports, module) {
236232
for (i = 0, len = this._extendPendings.length; i < len; i++) {
237233
var _extend = this._extendPendings[i];
238234
_typeName = _extend.node.qualifiedName.name;
235+
239236
_type = this._findType(_extend.classifier, _typeName, _extend.compilationUnitNode);
240237
if (!_type) {
241238
_pathName = this._toPathName(_typeName);
@@ -745,7 +742,7 @@ define(function (require, exports, module) {
745742
}
746743
break;
747744
case "Constructor":
748-
this.translateMethod(options, namespace, memberNode);
745+
this.translateMethod(options, namespace, memberNode, true);
749746
break;
750747
case "Method":
751748
this.translateMethod(options, namespace, memberNode);
@@ -810,6 +807,11 @@ define(function (require, exports, module) {
810807
_class.isLeaf = true;
811808
}
812809

810+
// JavaDoc
811+
if (classNode.comment) {
812+
_class.documentation = classNode.comment;
813+
}
814+
813815
namespace.ownedElements.push(_class);
814816

815817
// Register Extends for 2nd Phase Translation
@@ -822,7 +824,7 @@ define(function (require, exports, module) {
822824
};
823825
this._extendPendings.push(_extendPending);
824826
}
825-
827+
826828
// - 1) 타입이 소스에 있는 경우 --> 해당 타입으로 Generalization 생성
827829
// - 2) 타입이 소스에 없는 경우 (e.g. java.util.ArrayList) --> 타입을 생성(어디에?)한 뒤 Generalization 생성
828830
// 모든 타입이 생성된 다음에 Generalization (혹은 기타 Relationships)이 연결되어야 하므로, 어딘가에 등록한 다음이 2nd Phase에서 처리.
@@ -860,6 +862,12 @@ define(function (require, exports, module) {
860862
_interface._parent = namespace;
861863
_interface.name = interfaceNode.name;
862864
_interface.visibility = this._getVisibility(interfaceNode.modifiers);
865+
866+
// JavaDoc
867+
if (interfaceNode.comment) {
868+
_interface.documentation = interfaceNode.comment;
869+
}
870+
863871
namespace.ownedElements.push(_interface);
864872

865873
// Register Extends for 2nd Phase Translation
@@ -869,7 +877,8 @@ define(function (require, exports, module) {
869877
this._extendPendings.push({
870878
classifier: _interface,
871879
node: _extend,
872-
kind: "interface"
880+
kind: "interface",
881+
compilationUnitNode: this._currentCompilationUnit
873882
});
874883
}
875884
}
@@ -895,6 +904,12 @@ define(function (require, exports, module) {
895904
_enum._parent = namespace;
896905
_enum.name = enumNode.name;
897906
_enum.visibility = this._getVisibility(enumNode.modifiers);
907+
908+
// JavaDoc
909+
if (enumNode.comment) {
910+
_enum.documentation = enumNode.comment;
911+
}
912+
898913
namespace.ownedElements.push(_enum);
899914

900915
// Translate Type Parameters
@@ -919,6 +934,12 @@ define(function (require, exports, module) {
919934
_annotationType.name = annotationTypeNode.name;
920935
_annotationType.stereotype = "annotationType";
921936
_annotationType.visibility = this._getVisibility(annotationTypeNode.modifiers);
937+
938+
// JavaDoc
939+
if (annotationTypeNode.comment) {
940+
_annotationType.documentation = annotationTypeNode.comment;
941+
}
942+
922943
namespace.ownedElements.push(_annotationType);
923944

924945
// Translate Type Parameters
@@ -989,6 +1010,11 @@ define(function (require, exports, module) {
9891010
this._addTag(_attribute, Core.TK_BOOLEAN, "transient", true);
9901011
}
9911012

1013+
// JavaDoc
1014+
if (fieldNode.comment) {
1015+
_attribute.documentation = fieldNode.comment;
1016+
}
1017+
9921018
namespace.attributes.push(_attribute);
9931019

9941020
// Add to _typedFeaturePendings
@@ -1007,7 +1033,7 @@ define(function (require, exports, module) {
10071033
/**
10081034
* Translate Method
10091035
*/
1010-
JavaAnalyzer.prototype.translateMethod = function (options, namespace, methodNode) {
1036+
JavaAnalyzer.prototype.translateMethod = function (options, namespace, methodNode, isConstructor) {
10111037
var i, len,
10121038
_operation = new type.UMLOperation();
10131039
_operation._parent = namespace;
@@ -1035,6 +1061,11 @@ define(function (require, exports, module) {
10351061
this._addTag(_operation, Core.TK_BOOLEAN, "strictfp", true);
10361062
}
10371063

1064+
// Constructor
1065+
if (isConstructor) {
1066+
_operation.stereotype = "constructor";
1067+
}
1068+
10381069
// Formal Parameters
10391070
if (methodNode.parameters && methodNode.parameters.length > 0) {
10401071
for (i = 0, len = methodNode.parameters.length; i < len; i++) {
@@ -1066,12 +1097,22 @@ define(function (require, exports, module) {
10661097
var _throwPending = {
10671098
operation: _operation,
10681099
node: _throwNode,
1069-
compilationUnitNode: this._currentCompilationUnit
1100+
compilationUnitNode: methodNode.compilationUnitNode
10701101
};
10711102
this._throwPendings.push(_throwPending);
10721103
}
10731104
}
10741105

1106+
// JavaDoc
1107+
if (methodNode.comment) {
1108+
_operation.documentation = methodNode.comment;
1109+
}
1110+
1111+
// "default" for Annotation Type Element
1112+
if (methodNode.defaultValue) {
1113+
this._addTag(_operation, Core.TK_STRING, "default", methodNode.defaultValue);
1114+
}
1115+
10751116
// Translate Type Parameters
10761117
this.translateTypeParameters(options, _operation, methodNode.typeParameters);
10771118
};
@@ -1083,6 +1124,12 @@ define(function (require, exports, module) {
10831124
var _literal = new type.UMLEnumerationLiteral();
10841125
_literal._parent = namespace;
10851126
_literal.name = enumConstantNode.name;
1127+
1128+
// JavaDoc
1129+
if (enumConstantNode.comment) {
1130+
_literal.documentation = enumConstantNode.comment;
1131+
}
1132+
10861133
namespace.literals.push(_literal);
10871134
};
10881135

@@ -1105,16 +1152,8 @@ define(function (require, exports, module) {
11051152
};
11061153

11071154
/**
1108-
*
1155+
* @param {string} basePath
11091156
* @param {Object} options
1110-
* options = {
1111-
* path: "/User/niklaus/...",
1112-
* association: true,
1113-
* publicOnly: true,
1114-
* typeHiarachy: true,
1115-
* packageOverview: true,
1116-
* packageStructure: true
1117-
* }
11181157
* @return {$.Promise}
11191158
*/
11201159
function analyze(basePath, options) {

README.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Java Extension for StarUML 2
22
============================
33

4-
This extension for StarUML(http://staruml.io) support to generate Java code from UML model and to reverse Java code to UML model. Install this extension from Extension Manager of StarUML.
4+
This extension for StarUML(http://staruml.io) support to generate Java code from UML model and to reverse Java code to UML model. Install this extension from Extension Manager of StarUML. It is based on Java 1.7 specification.
55

66
Java Code Generation
77
--------------------
@@ -102,12 +102,13 @@ Belows are the rules to convert from Java source code to UML model elements.
102102

103103
* converted to _UMLClass_.
104104
* Class name to `name` property.
105+
* Type parameters to _UMLTemplateParameter_.
105106
* Access modifier `public`, `protected` and `private` to `visibility` property.
106107
* `abstract` modifier to `isAbstract` property.
107108
* `final` modifier to `isLeaf` property.
108-
* Default constructor is generated.
109+
* Constructors to _UMLOperation_ with stereotype `<<constructor>>`.
109110
* All contained types (_UMLClass_, _UMLInterface_, _UMLEnumeration_) are generated as inner type definition.
110-
* Documentation property to JavaDoc comment.
111+
* JavaDoc comment to Documentation.
111112

112113

113114
### Java Field (to UMLAttribute)
@@ -126,6 +127,7 @@ Belows are the rules to convert from Java source code to UML model elements.
126127
* `transient` modifier to a Tag with `name="transient"` and `checked=true` .
127128
* `volatile` modifier to a Tag with `name="volatile"` and `checked=true`.
128129
* Initial value to `defaultValue` property.
130+
* JavaDoc comment to Documentation.
129131

130132
### Java Field (to UMLAssociation)
131133

@@ -137,16 +139,41 @@ Belows are the rules to convert from Java source code to UML model elements.
137139
* Otherwise : converted to _UMLAttribute_, not _UMLAssociation_.
138140

139141
* Access modifier `public`, `protected` and `private` to `visibility` property.
140-
142+
* JavaDoc comment to Documentation.
141143

142144
### Java Method
143145

144146
* converted to _UMLOperation_.
147+
* Type parameters to _UMLTemplateParameter_.
145148
* Access modifier `public`, `protected` and `private` to `visibility` property.
149+
* `static` modifier to `isStatic` property.
150+
* `abstract` modifier to `isAbstract` property.
151+
* `final` modifier to `isLeaf` property.
152+
* `synchronized` modifier to `concurrency="concurrent"` property.
153+
* `native` modifier to a Tag with `name="native"` and `checked=true`.
154+
* `strictfp` modifier to a Tag with `name="strictfp"` and `checked=true`.
155+
* `throws` clauses to `raisedExceptions` property.
156+
* JavaDoc comment to Documentation.
146157

147158
### Java Interface
148159

160+
* converted to _UMLInterface_.
161+
* Class name to `name` property.
162+
* Type parameters to _UMLTemplateParameter_.
163+
* Access modifier `public`, `protected` and `private` to `visibility` property.
164+
* JavaDoc comment to Documentation.
165+
149166
### Java Enum
150167

168+
* converted to _UMLEnumeration_.
169+
* Enum name to `name` property.
170+
* Type parameters to _UMLTemplateParameter_.
171+
* Access modifier `public`, `protected` and `private` to `visibility` property.
172+
* Enum constants are converted to _UMLEnumerationLiteral_.
173+
* JavaDoc comment to Documentation.
174+
151175
### Java AnnotationType
152176

177+
* converted to _UMLClass_ with stereotype `<<annotationType>>`.
178+
* Annotation type elements to _UMLOperation_. (Default value to a Tag with `name="default"`).
179+
* JavaDoc comment to Documentation.

0 commit comments

Comments
 (0)