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

Skip to content

Commit e0e3621

Browse files
committed
update 2nd phase
1 parent 839acfd commit e0e3621

File tree

2 files changed

+102
-12
lines changed

2 files changed

+102
-12
lines changed

JavaReverseEngineer.js

Lines changed: 100 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,73 @@ define(function (require, exports, module) {
171171
* - Resolve Type References
172172
*/
173173
JavaAnalyzer.prototype.perform2ndPhase = function (options) {
174-
var i, len;
174+
var i, len, _type;
175+
176+
// Create Generalizations
175177
for (i = 0, len = this._generalizations.length; i < len; i++) {
176-
var gen = this._generalizations[i];
177-
console.log(gen);
178+
var _gen = this._generalizations[i];
179+
_type = this._findType(_gen.classifier, _gen.node.qualifiedName.name);
180+
if (_type) {
181+
var gen = new type.UMLGeneralization();
182+
gen._parent = _gen.classifier;
183+
gen.source = _gen.classifier;
184+
gen.target = _type;
185+
_gen.classifier.ownedElements.push(gen);
186+
}
187+
}
188+
189+
// Create InterfaceRealizations
190+
for (i = 0, len = this._realizations.length; i < len; i++) {
191+
var _real = this._realizations[i];
192+
_type = this._findType(_real.classifier, _real.node.qualifiedName.name);
193+
if (_type) {
194+
var real = new type.UMLInterfaceRealization();
195+
real._parent = _real.classifier;
196+
real.source = _real.classifier;
197+
real.target = _type;
198+
_real.classifier.ownedElements.push(real);
199+
}
200+
}
201+
202+
};
203+
204+
/**
205+
* Find Type.
206+
*
207+
* @param {Element} context
208+
* @param {string} typeName
209+
*/
210+
JavaAnalyzer.prototype._findType = function (context, typeName) {
211+
var root = this._builder.getBaseModel(),
212+
pathName = (typeName.indexOf(".") > 0 ? typeName.trim().split(".") : []),
213+
_type = null;
214+
215+
// 1. Lookdown from context
216+
if (pathName.length > 1) {
217+
_type = context.lookdown(pathName);
218+
} else {
219+
_type = context.findByName(typeName);
220+
}
221+
222+
// 2. Lookup from context
223+
if (!_type) {
224+
_type = context.lookup(typeName, null, root);
225+
}
226+
227+
// 3. Find from imported namespaces
228+
if (!_type) {
229+
// TODO: import에서 찾기.
230+
}
178231

179-
// TODO: 타입을 찾는 함수 필요. (Context에서 찾고(InnerClass?), 동일 패키지에서 찾고, import에서 찾고)
232+
// 4. Lookdown from Root
233+
if (!_type) {
234+
if (pathName.length > 1) {
235+
_type = root.lookdown(pathName);
236+
} else {
237+
_type = root.findByName(typeName);
238+
}
180239
}
240+
return _type;
181241
};
182242

183243

@@ -324,9 +384,10 @@ define(function (require, exports, module) {
324384
* @param {Object} compilationUnitNode
325385
*/
326386
JavaAnalyzer.prototype.translateClass = function (options, parent, classNode) {
327-
var i,
328-
len,
329-
_class = new type.UMLClass();
387+
var i, len, _class;
388+
389+
// Create Class
390+
_class = new type.UMLClass();
330391
_class._parent = parent;
331392
_class.name = classNode.name;
332393
_class.visibility = this._getVisibility(classNode.modifiers);
@@ -360,18 +421,35 @@ define(function (require, exports, module) {
360421
};
361422

362423
JavaAnalyzer.prototype.translateInterface = function (options, parent, interfaceNode) {
363-
var _interface = new type.UMLInterface();
424+
var i, len, _interface;
425+
426+
// Create Interface
427+
_interface = new type.UMLInterface();
364428
_interface._parent = parent;
365429
_interface.name = interfaceNode.name;
366430
_interface.visibility = this._getVisibility(interfaceNode.modifiers);
367431
parent.ownedElements.push(_interface);
368432

433+
// Register Extends for 2nd Phase Translation
434+
if (interfaceNode["extends"]) {
435+
for (i = 0, len = interfaceNode["extends"].length; i < len; i++) {
436+
var _ext = interfaceNode["extends"][i];
437+
this._generalizations.push({
438+
classifier: _interface,
439+
node: _ext
440+
});
441+
}
442+
}
443+
369444
// Translate Members
370445
this.translateMembers(options, _interface, interfaceNode.body);
371446
};
372447

373448
JavaAnalyzer.prototype.translateEnum = function (options, parent, enumNode) {
374-
var _enum = new type.UMLEnumeration();
449+
var _enum;
450+
451+
// Create Enumeration
452+
_enum = new type.UMLEnumeration();
375453
_enum._parent = parent;
376454
_enum.name = enumNode.name;
377455
_enum.visibility = this._getVisibility(enumNode.modifiers);
@@ -382,7 +460,10 @@ define(function (require, exports, module) {
382460
};
383461

384462
JavaAnalyzer.prototype.translateAnnotationType = function (options, parent, annotationTypeNode) {
385-
var _annotationType = new type.UMLClass();
463+
var _annotationType;
464+
465+
// Create Class <<annotationType>>
466+
_annotationType = new type.UMLClass();
386467
_annotationType._parent = parent;
387468
_annotationType.name = annotationTypeNode.name;
388469
_annotationType.stereotype = "annotationType";
@@ -415,6 +496,9 @@ define(function (require, exports, module) {
415496
}
416497
};
417498

499+
/**
500+
* Translate Method
501+
*/
418502
JavaAnalyzer.prototype.translateMethod = function (options, parent, methodNode) {
419503
var i, len,
420504
_operation = new type.UMLOperation();
@@ -433,6 +517,9 @@ define(function (require, exports, module) {
433517
parent.operations.push(_operation);
434518
};
435519

520+
/**
521+
* Translate Enumeration Constant
522+
*/
436523
JavaAnalyzer.prototype.translateEnumConstant = function (options, parent, enumConstantNode) {
437524
var _literal = new type.UMLEnumerationLiteral();
438525
_literal._parent = parent;
@@ -441,6 +528,9 @@ define(function (require, exports, module) {
441528
};
442529

443530

531+
/**
532+
* Translate Method Parameters
533+
*/
444534
JavaAnalyzer.prototype.translateParameter = function (options, parent, parameterNode) {
445535
var _parameter = new type.UMLParameter();
446536
_parameter._parent = parent;

unittests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,13 +641,13 @@ define(function (require, exports, module) {
641641

642642
it("can reverse Generalization of Java Class", function () {
643643
runs(function () {
644-
// extends java.util.Vector
644+
// extends GenericClassTest
645645
});
646646
});
647647

648648
it("can reverse Interface Realization of Java Class", function () {
649649
runs(function () {
650-
// implements java.lang.Runnable, java.lang.Serializable
650+
// implements InterfaceTest, java.lang.Serializable
651651
});
652652
});
653653

0 commit comments

Comments
 (0)