sol2uml 2.5.19 → 2.5.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/associations.js +48 -9
- package/package.json +1 -1
package/lib/associations.js
CHANGED
|
@@ -13,10 +13,17 @@ const findAssociatedClass = (association, sourceUmlClass, umlClasses, searchedAb
|
|
|
13
13
|
// If a link was found
|
|
14
14
|
if (umlClass)
|
|
15
15
|
return umlClass;
|
|
16
|
-
// Could not find
|
|
16
|
+
// Could not find association so now need to recursively look at imports of imports
|
|
17
17
|
// add to already recursively processed files to avoid getting stuck in circular imports
|
|
18
18
|
searchedAbsolutePaths.push(sourceUmlClass.absolutePath);
|
|
19
|
-
|
|
19
|
+
const importedType = findChainedImport(association, sourceUmlClass, umlClasses, searchedAbsolutePaths);
|
|
20
|
+
if (importedType)
|
|
21
|
+
return importedType;
|
|
22
|
+
// Still could not find association so now need to recursively look for inherited types
|
|
23
|
+
const inheritedType = findInheritedType(association, sourceUmlClass, umlClasses);
|
|
24
|
+
if (inheritedType)
|
|
25
|
+
return inheritedType;
|
|
26
|
+
return undefined;
|
|
20
27
|
};
|
|
21
28
|
exports.findAssociatedClass = findAssociatedClass;
|
|
22
29
|
// Tests if source class can be linked to the target class via an association
|
|
@@ -36,19 +43,18 @@ const isAssociated = (association, sourceUmlClass, targetUmlClass, targetParentU
|
|
|
36
43
|
sourceUmlClass.imports.some((importLink) => importLink.absolutePath === targetUmlClass.absolutePath &&
|
|
37
44
|
importLink.classNames.some((importedClass) =>
|
|
38
45
|
// If a parent contract with no import alias
|
|
39
|
-
(association.
|
|
46
|
+
(association.targetUmlClassName ===
|
|
47
|
+
targetUmlClass.name &&
|
|
40
48
|
association.parentUmlClassName ===
|
|
41
49
|
importedClass.className &&
|
|
42
|
-
importedClass.className ===
|
|
43
|
-
targetUmlClass.name &&
|
|
44
50
|
importedClass.alias == undefined) ||
|
|
45
51
|
// If a parent contract with import alias
|
|
46
|
-
(association.
|
|
52
|
+
(association.targetUmlClassName ===
|
|
53
|
+
targetUmlClass.name &&
|
|
47
54
|
association.parentUmlClassName ===
|
|
48
|
-
importedClass.alias
|
|
49
|
-
importedClass.className ===
|
|
50
|
-
targetUmlClass.name))));
|
|
55
|
+
importedClass.alias))));
|
|
51
56
|
}
|
|
57
|
+
// No parent class in the association
|
|
52
58
|
return (
|
|
53
59
|
// class is in the same source file
|
|
54
60
|
(association.targetUmlClassName === targetUmlClass.name &&
|
|
@@ -70,6 +76,39 @@ const isAssociated = (association, sourceUmlClass, targetUmlClass, targetParentU
|
|
|
70
76
|
importedClass.alias &&
|
|
71
77
|
importedClass.className === targetUmlClass.name))));
|
|
72
78
|
};
|
|
79
|
+
const findInheritedType = (association, sourceUmlClass, umlClasses) => {
|
|
80
|
+
// Get all realized associations.
|
|
81
|
+
const parentAssociations = sourceUmlClass.getParentContracts();
|
|
82
|
+
// For each parent association
|
|
83
|
+
for (const parentAssociation of parentAssociations) {
|
|
84
|
+
const parent = (0, exports.findAssociatedClass)(parentAssociation, sourceUmlClass, umlClasses);
|
|
85
|
+
if (!parent)
|
|
86
|
+
continue;
|
|
87
|
+
// For each struct on the parent
|
|
88
|
+
for (const structId of parent.structs) {
|
|
89
|
+
const structUmlClass = umlClasses.find((c) => c.id === structId);
|
|
90
|
+
if (!structUmlClass)
|
|
91
|
+
continue;
|
|
92
|
+
if (structUmlClass.name === association.targetUmlClassName) {
|
|
93
|
+
return structUmlClass;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// For each enum on the parent
|
|
97
|
+
for (const enumId of parent.enums) {
|
|
98
|
+
const enumUmlClass = umlClasses.find((c) => c.id === enumId);
|
|
99
|
+
if (!enumUmlClass)
|
|
100
|
+
continue;
|
|
101
|
+
if (enumUmlClass.name === association.targetUmlClassName) {
|
|
102
|
+
return enumUmlClass;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// Recursively look for inherited types
|
|
106
|
+
const targetClass = findInheritedType(association, parent, umlClasses);
|
|
107
|
+
if (targetClass)
|
|
108
|
+
return targetClass;
|
|
109
|
+
}
|
|
110
|
+
return undefined;
|
|
111
|
+
};
|
|
73
112
|
const findChainedImport = (association, sourceUmlClass, umlClasses, searchedRelativePaths) => {
|
|
74
113
|
// Get all valid imports. That is, imports that do not explicitly import contracts or interfaces
|
|
75
114
|
// or explicitly import the source class
|