ts2famix 1.0.11 → 1.0.12

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.
Files changed (139) hide show
  1. package/.eslintrc.json +24 -24
  2. package/LICENSE +23 -23
  3. package/README.md +109 -109
  4. package/jest.config-old.ts +199 -199
  5. package/package.json +47 -47
  6. package/src/analyze.ts +94 -94
  7. package/src/analyze_functions/processAccesses.ts +57 -57
  8. package/src/analyze_functions/processFiles.ts +669 -661
  9. package/src/analyze_functions/processImportClauses.ts +77 -77
  10. package/src/analyze_functions/processInheritances.ts +84 -84
  11. package/src/analyze_functions/processInvocations.ts +51 -51
  12. package/src/famix2puml.ts +119 -119
  13. package/src/famix_functions/famix_functions.ts +559 -555
  14. package/src/famix_functions/famix_functions_associations.ts +215 -215
  15. package/src/famix_functions/famix_functions_index.ts +44 -44
  16. package/src/famix_functions/famix_functions_types.ts +105 -100
  17. package/src/generate_uml.sh +16 -16
  18. package/src/lib/famix/License.md +22 -22
  19. package/src/lib/famix/package-lock.json +301 -301
  20. package/src/lib/famix/package.json +27 -27
  21. package/src/lib/famix/readme.md +4 -4
  22. package/src/lib/famix/src/famix_JSON_exporter.ts +56 -56
  23. package/src/lib/famix/src/famix_base_element.ts +18 -18
  24. package/src/lib/famix/src/famix_repository.ts +199 -199
  25. package/src/lib/famix/src/index.ts +8 -8
  26. package/src/lib/famix/src/model/famix/access.ts +53 -53
  27. package/src/lib/famix/src/model/famix/accessor.ts +15 -15
  28. package/src/lib/famix/src/model/famix/alias.ts +41 -41
  29. package/src/lib/famix/src/model/famix/association.ts +44 -44
  30. package/src/lib/famix/src/model/famix/behavioral_entity.ts +107 -107
  31. package/src/lib/famix/src/model/famix/c_source_language.ts +15 -15
  32. package/src/lib/famix/src/model/famix/class.ts +86 -86
  33. package/src/lib/famix/src/model/famix/comment.ts +50 -50
  34. package/src/lib/famix/src/model/famix/container_entity.ts +165 -165
  35. package/src/lib/famix/src/model/famix/custom_source_language.ts +27 -27
  36. package/src/lib/famix/src/model/famix/decorator.ts +39 -39
  37. package/src/lib/famix/src/model/famix/entity.ts +15 -15
  38. package/src/lib/famix/src/model/famix/enum.ts +31 -31
  39. package/src/lib/famix/src/model/famix/enum_value.ts +29 -29
  40. package/src/lib/famix/src/model/famix/function.ts +15 -15
  41. package/src/lib/famix/src/model/famix/implicit_variable.ts +15 -15
  42. package/src/lib/famix/src/model/famix/import_clause.ts +53 -53
  43. package/src/lib/famix/src/model/famix/index.ts +42 -42
  44. package/src/lib/famix/src/model/famix/indexed_file_anchor.ts +49 -49
  45. package/src/lib/famix/src/model/famix/inheritance.ts +42 -42
  46. package/src/lib/famix/src/model/famix/interface.ts +75 -75
  47. package/src/lib/famix/src/model/famix/invocation.ts +68 -68
  48. package/src/lib/famix/src/model/famix/method.ts +96 -96
  49. package/src/lib/famix/src/model/famix/module.ts +31 -31
  50. package/src/lib/famix/src/model/famix/named_entity.ts +98 -98
  51. package/src/lib/famix/src/model/famix/namespace.ts +28 -28
  52. package/src/lib/famix/src/model/famix/parameter.ts +29 -29
  53. package/src/lib/famix/src/model/famix/parameterizable_class.ts +31 -31
  54. package/src/lib/famix/src/model/famix/parameterizable_interface.ts +31 -31
  55. package/src/lib/famix/src/model/famix/parameterized_type.ts +40 -40
  56. package/src/lib/famix/src/model/famix/primitive_type.ts +15 -15
  57. package/src/lib/famix/src/model/famix/property.ts +54 -54
  58. package/src/lib/famix/src/model/famix/reference.ts +42 -42
  59. package/src/lib/famix/src/model/famix/scoping_entity.ts +31 -31
  60. package/src/lib/famix/src/model/famix/script_entity.ts +38 -38
  61. package/src/lib/famix/src/model/famix/source_anchor.ts +31 -31
  62. package/src/lib/famix/src/model/famix/source_language.ts +31 -31
  63. package/src/lib/famix/src/model/famix/sourced_entity.ts +70 -70
  64. package/src/lib/famix/src/model/famix/structural_entity.ts +44 -44
  65. package/src/lib/famix/src/model/famix/text_anchor.ts +49 -49
  66. package/src/lib/famix/src/model/famix/type.ts +88 -88
  67. package/src/lib/famix/src/model/famix/type_parameter.ts +33 -33
  68. package/src/lib/famix/src/model/famix/variable.ts +28 -28
  69. package/src/lib/famix/tsconfig.json +26 -26
  70. package/src/lib/famix/tslint.json +14 -14
  71. package/src/lib/ts-complex/cyclomatic-service.ts +85 -85
  72. package/src/ts2famix-cli.ts +39 -39
  73. package/tsconfig.json +69 -69
  74. package/dist/analyze.js +0 -102
  75. package/dist/analyze_functions/processAccesses.js +0 -47
  76. package/dist/analyze_functions/processFiles.js +0 -540
  77. package/dist/analyze_functions/processImportClauses.js +0 -70
  78. package/dist/analyze_functions/processInheritances.js +0 -73
  79. package/dist/analyze_functions/processInvocations.js +0 -49
  80. package/dist/famix2puml.js +0 -125
  81. package/dist/famix_functions/famix_functions.js +0 -513
  82. package/dist/famix_functions/famix_functions_associations.js +0 -205
  83. package/dist/famix_functions/famix_functions_index.js +0 -62
  84. package/dist/famix_functions/famix_functions_types.js +0 -110
  85. package/dist/fqn.js +0 -126
  86. package/dist/fqp_implementation.js +0 -73
  87. package/dist/lib/famix/src/famix_JSON_exporter.js +0 -54
  88. package/dist/lib/famix/src/famix_base_element.js +0 -13
  89. package/dist/lib/famix/src/famix_repository.js +0 -187
  90. package/dist/lib/famix/src/index.js +0 -30
  91. package/dist/lib/famix/src/model/famix/access.js +0 -39
  92. package/dist/lib/famix/src/model/famix/accessor.js +0 -16
  93. package/dist/lib/famix/src/model/famix/alias.js +0 -32
  94. package/dist/lib/famix/src/model/famix/association.js +0 -36
  95. package/dist/lib/famix/src/model/famix/behavioral_entity.js +0 -81
  96. package/dist/lib/famix/src/model/famix/c_source_language.js +0 -16
  97. package/dist/lib/famix/src/model/famix/class.js +0 -70
  98. package/dist/lib/famix/src/model/famix/comment.js +0 -38
  99. package/dist/lib/famix/src/model/famix/container_entity.js +0 -125
  100. package/dist/lib/famix/src/model/famix/custom_source_language.js +0 -23
  101. package/dist/lib/famix/src/model/famix/decorator.js +0 -31
  102. package/dist/lib/famix/src/model/famix/entity.js +0 -16
  103. package/dist/lib/famix/src/model/famix/enum.js +0 -30
  104. package/dist/lib/famix/src/model/famix/enum_value.js +0 -24
  105. package/dist/lib/famix/src/model/famix/function.js +0 -16
  106. package/dist/lib/famix/src/model/famix/implicit_variable.js +0 -16
  107. package/dist/lib/famix/src/model/famix/import_clause.js +0 -39
  108. package/dist/lib/famix/src/model/famix/index.js +0 -87
  109. package/dist/lib/famix/src/model/famix/indexed_file_anchor.js +0 -37
  110. package/dist/lib/famix/src/model/famix/inheritance.js +0 -32
  111. package/dist/lib/famix/src/model/famix/interface.js +0 -63
  112. package/dist/lib/famix/src/model/famix/invocation.js +0 -53
  113. package/dist/lib/famix/src/model/famix/method.js +0 -66
  114. package/dist/lib/famix/src/model/famix/module.js +0 -30
  115. package/dist/lib/famix/src/model/famix/named_entity.js +0 -77
  116. package/dist/lib/famix/src/model/famix/namespace.js +0 -24
  117. package/dist/lib/famix/src/model/famix/parameter.js +0 -24
  118. package/dist/lib/famix/src/model/famix/parameterizable_class.js +0 -30
  119. package/dist/lib/famix/src/model/famix/parameterizable_interface.js +0 -30
  120. package/dist/lib/famix/src/model/famix/parameterized_type.js +0 -36
  121. package/dist/lib/famix/src/model/famix/primitive_type.js +0 -16
  122. package/dist/lib/famix/src/model/famix/property.js +0 -44
  123. package/dist/lib/famix/src/model/famix/reference.js +0 -32
  124. package/dist/lib/famix/src/model/famix/scoping_entity.js +0 -30
  125. package/dist/lib/famix/src/model/famix/script_entity.js +0 -30
  126. package/dist/lib/famix/src/model/famix/source_anchor.js +0 -26
  127. package/dist/lib/famix/src/model/famix/source_language.js +0 -30
  128. package/dist/lib/famix/src/model/famix/sourced_entity.js +0 -55
  129. package/dist/lib/famix/src/model/famix/structural_entity.js +0 -38
  130. package/dist/lib/famix/src/model/famix/text_anchor.js +0 -37
  131. package/dist/lib/famix/src/model/famix/type.js +0 -71
  132. package/dist/lib/famix/src/model/famix/type_parameter.js +0 -24
  133. package/dist/lib/famix/src/model/famix/variable.js +0 -23
  134. package/dist/lib/ts-complex/cyclomatic-service.js +0 -83
  135. package/dist/ts2famix-cli.js +0 -63
  136. package/dist/ts2famix-tsconfig.js +0 -53
  137. package/metrics.ts +0 -23
  138. package/output.debug.txt +0 -1351
  139. package/src/fqp_implementation.ts +0 -66
@@ -1,28 +1,28 @@
1
- {
2
- "name": "famix",
3
- "version": "1.0.5",
4
- "description": "a FAMIX model written typescript",
5
- "main": "build/index.js",
6
- "types": "build/index.d.ts",
7
- "files": ["dist/**/*"],
8
- "repository": {
9
- "type": "git",
10
- "url": "git+https://github.com/pascalerni/famix.git"
11
- },
12
- "scripts": {
13
- "test": "echo \"Error: no test specified\" && exit 0",
14
- "build" : "tsc",
15
- "lint": "tslint -p tsconfig.json",
16
- "prepare": "npm run build",
17
- "prepublishOnly": "npm test && npm run lint",
18
- "preversion": "npm run lint",
19
- "version": "git add -A src",
20
- "postversion": "git push && git push --tags"
21
- },
22
- "author": "Pascal Erni",
23
- "license": "MIT",
24
- "devDependencies": {
25
- "tslint": "^5.20.0",
26
- "typescript": "^3.6.3"
27
- }
1
+ {
2
+ "name": "famix",
3
+ "version": "1.0.5",
4
+ "description": "a FAMIX model written typescript",
5
+ "main": "build/index.js",
6
+ "types": "build/index.d.ts",
7
+ "files": ["dist/**/*"],
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/pascalerni/famix.git"
11
+ },
12
+ "scripts": {
13
+ "test": "echo \"Error: no test specified\" && exit 0",
14
+ "build" : "tsc",
15
+ "lint": "tslint -p tsconfig.json",
16
+ "prepare": "npm run build",
17
+ "prepublishOnly": "npm test && npm run lint",
18
+ "preversion": "npm run lint",
19
+ "version": "git add -A src",
20
+ "postversion": "git push && git push --tags"
21
+ },
22
+ "author": "Pascal Erni",
23
+ "license": "MIT",
24
+ "devDependencies": {
25
+ "tslint": "^5.20.0",
26
+ "typescript": "^3.6.3"
27
+ }
28
28
  }
@@ -1,5 +1,5 @@
1
- # FAMIX model in typescript
2
-
3
- FAMIX is a family of metamodels to represent source code.
4
-
1
+ # FAMIX model in typescript
2
+
3
+ FAMIX is a family of metamodels to represent source code.
4
+
5
5
  Learn more about the MSE file format and the FAMIX model https://www.researchgate.net/publication/265428652
@@ -1,56 +1,56 @@
1
- import { FamixBaseElement } from "./famix_base_element";
2
-
3
- /**
4
- * This class is used to export Famix elements to JSON
5
- */
6
- export class FamixJSONExporter {
7
-
8
- private element: FamixBaseElement; // A Famix element to export
9
- private bufferArray: any = {}; // A buffer to store the properties of the Famix element
10
- private FamixPrefix = "FamixTypeScript"; // Prefix of the Famix element
11
-
12
- /**
13
- * Constructor of the FamixJSONExporter class
14
- * @param packageClass Name of a Famix class
15
- * @param element A Famix element to export, this element is an instance of the class named "packageClass"
16
- */
17
- constructor(packageClass: string, element: FamixBaseElement) {
18
- this.element = element;
19
- this.bufferArray["FM3"] = this.FamixPrefix + "." + packageClass;
20
- this.bufferArray["id"] = this.element.id;
21
- }
22
-
23
- /**
24
- * Adds a property to the Famix element
25
- * @param name Name of the property
26
- * @param prop A property
27
- */
28
- public addProperty(name: string, prop: unknown): void {
29
- if (prop instanceof Set) {
30
- const valueArray: Array<unknown> = [];
31
- for (const value of Array.from(prop.values())) {
32
- if (value instanceof FamixBaseElement) {
33
- valueArray.push({ "ref": value.id });
34
- }
35
- else {
36
- valueArray.push(value);
37
- }
38
- }
39
- this.bufferArray[name] = valueArray;
40
- }
41
- else if (prop instanceof FamixBaseElement) {
42
- this.bufferArray[name] = { "ref": prop.id };
43
- }
44
- else if (prop !== undefined && !(prop instanceof Set)) {
45
- this.bufferArray[name] = prop;
46
- }
47
- }
48
-
49
- /**
50
- * Gets a JSON representation of the Famix element
51
- * @returns A JSON representation of the Famix element
52
- */
53
- public getJSON(): string {
54
- return JSON.stringify(this.bufferArray);
55
- }
56
- }
1
+ import { FamixBaseElement } from "./famix_base_element";
2
+
3
+ /**
4
+ * This class is used to export Famix elements to JSON
5
+ */
6
+ export class FamixJSONExporter {
7
+
8
+ private element: FamixBaseElement; // A Famix element to export
9
+ private bufferArray: any = {}; // A buffer to store the properties of the Famix element
10
+ private FamixPrefix = "FamixTypeScript"; // Prefix of the Famix element
11
+
12
+ /**
13
+ * Constructor of the FamixJSONExporter class
14
+ * @param packageClass Name of a Famix class
15
+ * @param element A Famix element to export, this element is an instance of the class named "packageClass"
16
+ */
17
+ constructor(packageClass: string, element: FamixBaseElement) {
18
+ this.element = element;
19
+ this.bufferArray["FM3"] = this.FamixPrefix + "." + packageClass;
20
+ this.bufferArray["id"] = this.element.id;
21
+ }
22
+
23
+ /**
24
+ * Adds a property to the Famix element
25
+ * @param name Name of the property
26
+ * @param prop A property
27
+ */
28
+ public addProperty(name: string, prop: unknown): void {
29
+ if (prop instanceof Set) {
30
+ const valueArray: Array<unknown> = [];
31
+ for (const value of Array.from(prop.values())) {
32
+ if (value instanceof FamixBaseElement) {
33
+ valueArray.push({ "ref": value.id });
34
+ }
35
+ else {
36
+ valueArray.push(value);
37
+ }
38
+ }
39
+ this.bufferArray[name] = valueArray;
40
+ }
41
+ else if (prop instanceof FamixBaseElement) {
42
+ this.bufferArray[name] = { "ref": prop.id };
43
+ }
44
+ else if (prop !== undefined && !(prop instanceof Set)) {
45
+ this.bufferArray[name] = prop;
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Gets a JSON representation of the Famix element
51
+ * @returns A JSON representation of the Famix element
52
+ */
53
+ public getJSON(): string {
54
+ return JSON.stringify(this.bufferArray);
55
+ }
56
+ }
@@ -1,18 +1,18 @@
1
- import { FamixJSONExporter } from "./famix_JSON_exporter";
2
- import { FamixRepository } from "./famix_repository";
3
-
4
- export abstract class FamixBaseElement {
5
-
6
- public id: number;
7
-
8
- constructor(repo: FamixRepository) {
9
- repo.addElement(this);
10
- }
11
-
12
- public abstract getJSON(): string;
13
-
14
- // @ts-ignore
15
- // tslint:disable-next-line:no-empty
16
- public addPropertiesToExporter(exporter: FamixJSONExporter): void {
17
- }
18
- }
1
+ import { FamixJSONExporter } from "./famix_JSON_exporter";
2
+ import { FamixRepository } from "./famix_repository";
3
+
4
+ export abstract class FamixBaseElement {
5
+
6
+ public id: number;
7
+
8
+ constructor(repo: FamixRepository) {
9
+ repo.addElement(this);
10
+ }
11
+
12
+ public abstract getJSON(): string;
13
+
14
+ // @ts-ignore
15
+ // tslint:disable-next-line:no-empty
16
+ public addPropertiesToExporter(exporter: FamixJSONExporter): void {
17
+ }
18
+ }
@@ -1,199 +1,199 @@
1
- import { FamixBaseElement } from "./famix_base_element";
2
- import { Class, Interface, Namespace, Method, Function, Type, NamedEntity, ScriptEntity, Module } from "./model/famix";
3
-
4
- /**
5
- * This class is used to store all Famix elements
6
- */
7
- export class FamixRepository {
8
-
9
- private elements = new Set<FamixBaseElement>(); // All Famix elements
10
- private famixClasses = new Set<Class>(); // All Famix classes
11
- private famixInterfaces = new Set<Interface>(); // All Famix interfaces
12
- private famixNamespaces = new Set<Namespace>(); // All Famix namespaces
13
- private famixMethods = new Set<Method>(); // All Famix methods
14
- private famixFunctions = new Set<Function>(); // All Famix functions
15
- private famixFiles = new Set<ScriptEntity | Module>(); // All Famix files
16
- private idCounter = 1; // Id counter
17
-
18
- /**
19
- * Gets a Famix entity by id
20
- * @param id An id of a Famix entity
21
- * @returns The Famix entity corresponding to the id or undefined if it doesn't exist
22
- */
23
- public getFamixEntityById(id: number): FamixBaseElement | undefined {
24
- const entity = Array.from(this.elements.values()).find(e => e.id === id);
25
- return entity;
26
- }
27
-
28
- /**
29
- * Gets a Famix entity by fully qualified name
30
- * @param fullyQualifiedName A fully qualified name
31
- * @returns The Famix entity corresponding to the fully qualified name or undefined if it doesn't exist
32
- */
33
- public getFamixEntityByFullyQualifiedName(fullyQualifiedName: string): FamixBaseElement | undefined {
34
- const allEntities = Array.from(this.elements.values()).filter(e => e instanceof NamedEntity) as Array<NamedEntity>;
35
- const entity = allEntities.find(e => e.getFullyQualifiedName() === fullyQualifiedName);
36
- return entity;
37
- }
38
-
39
-
40
- // Only for tests
41
-
42
- /**
43
- * Gets all Famix entities
44
- * @returns All Famix entities
45
- */
46
- public _getAllEntities(): Set<FamixBaseElement> {
47
- return new Set(Array.from(this.elements.values()));
48
- }
49
-
50
- /**
51
- * Gets all Famix entities of a given type
52
- * @param theType A type of Famix entity
53
- * @returns All Famix entities of the given type
54
- */
55
- public _getAllEntitiesWithType(theType: string): Set<FamixBaseElement> {
56
- return new Set(Array.from(this.elements.values()).filter(e => (e as any).constructor.name === theType));
57
- }
58
-
59
- /**
60
- * Gets a Famix class by name
61
- * @param name A class name
62
- * @returns The Famix class corresponding to the name or undefined if it doesn't exist
63
- */
64
- public _getFamixClass(name: string): Class | undefined {
65
- return Array.from(this.famixClasses.values()).find(ns => ns.getName() === name);
66
- }
67
-
68
- /**
69
- * Gets a Famix interface by name
70
- * @param name An interface name
71
- * @returns The Famix interface corresponding to the name or undefined if it doesn't exist
72
- */
73
- public _getFamixInterface(name: string): Interface | undefined {
74
- return Array.from(this.famixInterfaces.values()).find(ns => ns.getName() === name);
75
- }
76
-
77
- /**
78
- * Gets a Famix method by name
79
- * @param name A method name
80
- * @returns The Famix method corresponding to the name or undefined if it doesn't exist
81
- */
82
- public _getFamixMethod(name: string): Method | undefined {
83
- return Array.from(this.famixMethods.values()).find(ns => ns.getName() === name);
84
- }
85
-
86
- /**
87
- * Gets a Famix function by name
88
- * @param name A function name
89
- * @returns The Famix function corresponding to the name or undefined if it doesn't exist
90
- */
91
- public _getFamixFunction(name: string): Function | undefined {
92
- return Array.from(this.famixFunctions.values()).find(ns => ns.getName() === name);
93
- }
94
-
95
- /**
96
- * Gets a Famix namespace by name
97
- * @param name A namespace name
98
- * @returns The Famix namespace corresponding to the name or undefined if it doesn't exist
99
- */
100
- public _getFamixNamespace(name: string): Namespace | undefined {
101
- return Array.from(this.famixNamespaces.values()).find(ns => ns.getName() === name);
102
- }
103
-
104
- /**
105
- * Gets all Famix namespaces
106
- * @returns All Famix namespaces
107
- */
108
- public _getFamixNamespaces(): Set<Namespace> {
109
- return new Set(Array.from(this.famixNamespaces.values()));
110
- }
111
-
112
- /**
113
- * Gets a Famix file by name
114
- * @param name A file name
115
- * @returns The Famix file corresponding to the name or undefined if it doesn't exist
116
- */
117
- public _getFamixFile(name: string): ScriptEntity | Module | undefined {
118
- return Array.from(this.famixFiles.values()).find(ns => ns.getName() === name);
119
- }
120
-
121
- /**
122
- * Gets all Famix files
123
- * @returns All Famix files
124
- */
125
- public _getFamixFiles(): Set<ScriptEntity | Module> {
126
- return new Set(Array.from(this.famixFiles.values()));
127
- }
128
-
129
- /**
130
- * Gets all method names as a set from a class
131
- * @param className A class name
132
- * @returns The set of class "className" method names
133
- */
134
- public _methodNamesAsSetFromClass(className: string): Set<string> {
135
- const theClass = this._getFamixClass(className) as Class;
136
- return new Set(Array.from(theClass.getMethods()).map(m => m.getName()));
137
- }
138
-
139
- /**
140
- * Gets all method parents as a set from a class
141
- * @param className A class name
142
- * @returns The set of class "className" method parents
143
- */
144
- public _methodParentsAsSetFromClass(className: string): Set<Type> {
145
- const theClass = this._getFamixClass(className) as Class;
146
- return new Set(Array.from(theClass.getMethods()).map(m => m.getParentEntity()));
147
- }
148
-
149
- /**
150
- * Gets the map of Famix element ids and their Famix element from a JSON model
151
- * @param model A JSON model
152
- * @returns The map of Famix element ids and their Famix element from the JSON model
153
- */
154
- public _initMapFromModel(model: string): Map<number, unknown> {
155
- const parsedModel: Array<any> = JSON.parse(model);
156
- const idToElementMap: Map<number, unknown> = new Map();
157
- parsedModel.forEach(element => {
158
- idToElementMap.set(element.id, element);
159
- });
160
- return idToElementMap;
161
- }
162
-
163
-
164
- /**
165
- * Adds a Famix element to the repository
166
- * @param element A Famix element
167
- */
168
- public addElement(element: FamixBaseElement): void {
169
- if (element instanceof Class) {
170
- this.famixClasses.add(element);
171
- } else if (element instanceof Interface) {
172
- this.famixInterfaces.add(element);
173
- } else if (element instanceof Namespace) {
174
- this.famixNamespaces.add(element);
175
- } else if (element instanceof Method) {
176
- this.famixMethods.add(element);
177
- } else if (element instanceof Function) {
178
- this.famixFunctions.add(element);
179
- } else if (element instanceof ScriptEntity || element instanceof Module) {
180
- this.famixFiles.add(element);
181
- }
182
- this.elements.add(element);
183
- element.id = this.idCounter;
184
- this.idCounter++;
185
- }
186
-
187
- /**
188
- * Gets a JSON representation of the repository
189
- * @returns A JSON representation of the repository
190
- */
191
- public getJSON(): string {
192
- let ret = "[";
193
- for (const element of Array.from(this.elements.values())) {
194
- ret = ret + element.getJSON() + ",";
195
- }
196
- ret = ret.substring(0, ret.length - 1);
197
- return ret + "]";
198
- }
199
- }
1
+ import { FamixBaseElement } from "./famix_base_element";
2
+ import { Class, Interface, Namespace, Method, Function, Type, NamedEntity, ScriptEntity, Module } from "./model/famix";
3
+
4
+ /**
5
+ * This class is used to store all Famix elements
6
+ */
7
+ export class FamixRepository {
8
+
9
+ private elements = new Set<FamixBaseElement>(); // All Famix elements
10
+ private famixClasses = new Set<Class>(); // All Famix classes
11
+ private famixInterfaces = new Set<Interface>(); // All Famix interfaces
12
+ private famixNamespaces = new Set<Namespace>(); // All Famix namespaces
13
+ private famixMethods = new Set<Method>(); // All Famix methods
14
+ private famixFunctions = new Set<Function>(); // All Famix functions
15
+ private famixFiles = new Set<ScriptEntity | Module>(); // All Famix files
16
+ private idCounter = 1; // Id counter
17
+
18
+ /**
19
+ * Gets a Famix entity by id
20
+ * @param id An id of a Famix entity
21
+ * @returns The Famix entity corresponding to the id or undefined if it doesn't exist
22
+ */
23
+ public getFamixEntityById(id: number): FamixBaseElement | undefined {
24
+ const entity = Array.from(this.elements.values()).find(e => e.id === id);
25
+ return entity;
26
+ }
27
+
28
+ /**
29
+ * Gets a Famix entity by fully qualified name
30
+ * @param fullyQualifiedName A fully qualified name
31
+ * @returns The Famix entity corresponding to the fully qualified name or undefined if it doesn't exist
32
+ */
33
+ public getFamixEntityByFullyQualifiedName(fullyQualifiedName: string): FamixBaseElement | undefined {
34
+ const allEntities = Array.from(this.elements.values()).filter(e => e instanceof NamedEntity) as Array<NamedEntity>;
35
+ const entity = allEntities.find(e => e.getFullyQualifiedName() === fullyQualifiedName);
36
+ return entity;
37
+ }
38
+
39
+
40
+ // Only for tests
41
+
42
+ /**
43
+ * Gets all Famix entities
44
+ * @returns All Famix entities
45
+ */
46
+ public _getAllEntities(): Set<FamixBaseElement> {
47
+ return new Set(Array.from(this.elements.values()));
48
+ }
49
+
50
+ /**
51
+ * Gets all Famix entities of a given type
52
+ * @param theType A type of Famix entity
53
+ * @returns All Famix entities of the given type
54
+ */
55
+ public _getAllEntitiesWithType(theType: string): Set<FamixBaseElement> {
56
+ return new Set(Array.from(this.elements.values()).filter(e => (e as any).constructor.name === theType));
57
+ }
58
+
59
+ /**
60
+ * Gets a Famix class by name
61
+ * @param name A class name
62
+ * @returns The Famix class corresponding to the name or undefined if it doesn't exist
63
+ */
64
+ public _getFamixClass(name: string): Class | undefined {
65
+ return Array.from(this.famixClasses.values()).find(ns => ns.getName() === name);
66
+ }
67
+
68
+ /**
69
+ * Gets a Famix interface by name
70
+ * @param name An interface name
71
+ * @returns The Famix interface corresponding to the name or undefined if it doesn't exist
72
+ */
73
+ public _getFamixInterface(name: string): Interface | undefined {
74
+ return Array.from(this.famixInterfaces.values()).find(ns => ns.getName() === name);
75
+ }
76
+
77
+ /**
78
+ * Gets a Famix method by name
79
+ * @param name A method name
80
+ * @returns The Famix method corresponding to the name or undefined if it doesn't exist
81
+ */
82
+ public _getFamixMethod(name: string): Method | undefined {
83
+ return Array.from(this.famixMethods.values()).find(ns => ns.getName() === name);
84
+ }
85
+
86
+ /**
87
+ * Gets a Famix function by name
88
+ * @param name A function name
89
+ * @returns The Famix function corresponding to the name or undefined if it doesn't exist
90
+ */
91
+ public _getFamixFunction(name: string): Function | undefined {
92
+ return Array.from(this.famixFunctions.values()).find(ns => ns.getName() === name);
93
+ }
94
+
95
+ /**
96
+ * Gets a Famix namespace by name
97
+ * @param name A namespace name
98
+ * @returns The Famix namespace corresponding to the name or undefined if it doesn't exist
99
+ */
100
+ public _getFamixNamespace(name: string): Namespace | undefined {
101
+ return Array.from(this.famixNamespaces.values()).find(ns => ns.getName() === name);
102
+ }
103
+
104
+ /**
105
+ * Gets all Famix namespaces
106
+ * @returns All Famix namespaces
107
+ */
108
+ public _getFamixNamespaces(): Set<Namespace> {
109
+ return new Set(Array.from(this.famixNamespaces.values()));
110
+ }
111
+
112
+ /**
113
+ * Gets a Famix file by name
114
+ * @param name A file name
115
+ * @returns The Famix file corresponding to the name or undefined if it doesn't exist
116
+ */
117
+ public _getFamixFile(name: string): ScriptEntity | Module | undefined {
118
+ return Array.from(this.famixFiles.values()).find(ns => ns.getName() === name);
119
+ }
120
+
121
+ /**
122
+ * Gets all Famix files
123
+ * @returns All Famix files
124
+ */
125
+ public _getFamixFiles(): Set<ScriptEntity | Module> {
126
+ return new Set(Array.from(this.famixFiles.values()));
127
+ }
128
+
129
+ /**
130
+ * Gets all method names as a set from a class
131
+ * @param className A class name
132
+ * @returns The set of class "className" method names
133
+ */
134
+ public _methodNamesAsSetFromClass(className: string): Set<string> {
135
+ const theClass = this._getFamixClass(className) as Class;
136
+ return new Set(Array.from(theClass.getMethods()).map(m => m.getName()));
137
+ }
138
+
139
+ /**
140
+ * Gets all method parents as a set from a class
141
+ * @param className A class name
142
+ * @returns The set of class "className" method parents
143
+ */
144
+ public _methodParentsAsSetFromClass(className: string): Set<Type> {
145
+ const theClass = this._getFamixClass(className) as Class;
146
+ return new Set(Array.from(theClass.getMethods()).map(m => m.getParentEntity()));
147
+ }
148
+
149
+ /**
150
+ * Gets the map of Famix element ids and their Famix element from a JSON model
151
+ * @param model A JSON model
152
+ * @returns The map of Famix element ids and their Famix element from the JSON model
153
+ */
154
+ public _initMapFromModel(model: string): Map<number, unknown> {
155
+ const parsedModel: Array<any> = JSON.parse(model);
156
+ const idToElementMap: Map<number, unknown> = new Map();
157
+ parsedModel.forEach(element => {
158
+ idToElementMap.set(element.id, element);
159
+ });
160
+ return idToElementMap;
161
+ }
162
+
163
+
164
+ /**
165
+ * Adds a Famix element to the repository
166
+ * @param element A Famix element
167
+ */
168
+ public addElement(element: FamixBaseElement): void {
169
+ if (element instanceof Class) {
170
+ this.famixClasses.add(element);
171
+ } else if (element instanceof Interface) {
172
+ this.famixInterfaces.add(element);
173
+ } else if (element instanceof Namespace) {
174
+ this.famixNamespaces.add(element);
175
+ } else if (element instanceof Method) {
176
+ this.famixMethods.add(element);
177
+ } else if (element instanceof Function) {
178
+ this.famixFunctions.add(element);
179
+ } else if (element instanceof ScriptEntity || element instanceof Module) {
180
+ this.famixFiles.add(element);
181
+ }
182
+ this.elements.add(element);
183
+ element.id = this.idCounter;
184
+ this.idCounter++;
185
+ }
186
+
187
+ /**
188
+ * Gets a JSON representation of the repository
189
+ * @returns A JSON representation of the repository
190
+ */
191
+ public getJSON(): string {
192
+ let ret = "[";
193
+ for (const element of Array.from(this.elements.values())) {
194
+ ret = ret + element.getJSON() + ",";
195
+ }
196
+ ret = ret.substring(0, ret.length - 1);
197
+ return ret + "]";
198
+ }
199
+ }
@@ -1,8 +1,8 @@
1
- import * as Famix from "./model/famix";
2
- import { FamixBaseElement } from "./famix_base_element";
3
- import { FamixJSONExporter } from "./famix_JSON_exporter";
4
- import { FamixRepository } from "./famix_repository";
5
-
6
- const model = { Famix };
7
-
8
- export = { FamixBaseElement, FamixJSONExporter, FamixRepository, model };
1
+ import * as Famix from "./model/famix";
2
+ import { FamixBaseElement } from "./famix_base_element";
3
+ import { FamixJSONExporter } from "./famix_JSON_exporter";
4
+ import { FamixRepository } from "./famix_repository";
5
+
6
+ const model = { Famix };
7
+
8
+ export = { FamixBaseElement, FamixJSONExporter, FamixRepository, model };