ts2famix 1.0.11 → 1.0.13

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,540 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.ProcessFiles = void 0;
27
- const ts_morph_1 = require("ts-morph");
28
- const Famix = __importStar(require("../lib/famix/src/model/famix"));
29
- const cyclomatic_service_1 = require("../lib/ts-complex/cyclomatic-service");
30
- /**
31
- * This class is used to build a Famix model for an array of source files
32
- */
33
- class ProcessFiles {
34
- /**
35
- * Initializes the ProcessFiles object
36
- * @param famixFunctions FamixFunctions object, it contains all the functions needed to create Famix entities
37
- */
38
- constructor(famixFunctions) {
39
- this.methodsAndFunctionsWithId = new Map(); // Maps the Famix method, constructor, getter, setter and function ids to their ts-morph method, constructor, getter, setter or function object
40
- this.accesses = new Map(); // Maps the Famix parameter, variable, property and enum value ids to their ts-morph parameter, variable, property or enum member object
41
- this.classes = new Array(); // Array of all the classes of the source files
42
- this.interfaces = new Array(); // Array of all the interfaces of the source files
43
- this.modules = new Array(); // Array of all the source files which are modules
44
- this.exports = new Array(); // Array of all the exports
45
- this.famixFunctions = famixFunctions;
46
- }
47
- /**
48
- * Builds a Famix model for an array of source files
49
- * @param sourceFiles An array of source files
50
- */
51
- processFiles(sourceFiles) {
52
- sourceFiles.forEach(file => {
53
- console.info(`processFiles: File: >>>>>>>>>> ${file.getBaseName()}`);
54
- // Computes the cyclomatic complexity metrics for the current source file
55
- this.currentCC = (0, cyclomatic_service_1.calculate)(file.getFilePath());
56
- this.processFile(file);
57
- });
58
- }
59
- /**
60
- * Gets the map of methods and functions with their id
61
- * @returns The map of methods and functions with their id
62
- */
63
- getMethodsAndFunctionsWithId() {
64
- return this.methodsAndFunctionsWithId;
65
- }
66
- /**
67
- * Gets the map of accesses
68
- * @returns The map of accesses
69
- */
70
- getAccesses() {
71
- return this.accesses;
72
- }
73
- /**
74
- * Gets the array of classes
75
- * @returns The array of classes
76
- */
77
- getClasses() {
78
- return this.classes;
79
- }
80
- /**
81
- * Gets the array of interfaces
82
- * @returns The array of interfaces
83
- */
84
- getInterfaces() {
85
- return this.interfaces;
86
- }
87
- /**
88
- * Gets the array of modules
89
- * @returns The array of modules
90
- */
91
- getModules() {
92
- return this.modules;
93
- }
94
- /**
95
- * Gets the array of exports
96
- * @returns The array of exports
97
- */
98
- getExports() {
99
- return this.exports;
100
- }
101
- /**
102
- * Builds a Famix model for a source file
103
- * @param f A source file
104
- */
105
- processFile(f) {
106
- const isModule = this.isModule(f);
107
- if (isModule) {
108
- this.modules.push(f);
109
- }
110
- const fmxFile = this.famixFunctions.createOrGetFamixFile(f, isModule);
111
- console.info(`processFile: file: ${f.getBaseName()}, fqn = ${fmxFile.getFullyQualifiedName()}`);
112
- this.processComments(f, fmxFile);
113
- this.processAliases(f, fmxFile);
114
- this.processClasses(f, fmxFile);
115
- this.processInterfaces(f, fmxFile);
116
- this.processVariables(f, fmxFile);
117
- this.processEnums(f, fmxFile);
118
- this.processFunctions(f, fmxFile);
119
- this.processNamespaces(f, fmxFile);
120
- }
121
- /**
122
- * Builds a Famix model for a namespace
123
- * @param m A namespace
124
- * @returns A Famix.Namespace representing the namespace
125
- */
126
- processNamespace(m) {
127
- const fmxNamespace = this.famixFunctions.createOrGetFamixNamespace(m);
128
- console.info(`processNamespace: namespace: ${m.getName()}, (${m.getType().getText()}), ${fmxNamespace.getFullyQualifiedName()}`);
129
- this.processComments(m, fmxNamespace);
130
- this.processAliases(m, fmxNamespace);
131
- this.processClasses(m, fmxNamespace);
132
- this.processInterfaces(m, fmxNamespace);
133
- this.processVariables(m, fmxNamespace);
134
- this.processEnums(m, fmxNamespace);
135
- this.processFunctions(m, fmxNamespace);
136
- this.processNamespaces(m, fmxNamespace);
137
- return fmxNamespace;
138
- }
139
- /**
140
- * Builds a Famix model for the aliases of a container
141
- * @param m A container (a source file, a namespace, a function or a method)
142
- * @param fmxScope The Famix model of the container
143
- */
144
- processAliases(m, fmxScope) {
145
- console.info(`processAliases: ---------- Finding Aliases:`);
146
- m.getTypeAliases().forEach(a => {
147
- const fmxAlias = this.processAlias(a);
148
- fmxScope.addAlias(fmxAlias);
149
- });
150
- }
151
- /**
152
- * Builds a Famix model for the classes of a container
153
- * @param m A container (a source file or a namespace)
154
- * @param fmxScope The Famix model of the container
155
- */
156
- processClasses(m, fmxScope) {
157
- console.info(`processClasses: ---------- Finding Classes:`);
158
- m.getClasses().forEach(c => {
159
- const fmxClass = this.processClass(c);
160
- fmxScope.addType(fmxClass);
161
- });
162
- }
163
- /**
164
- * Builds a Famix model for the interfaces of a container
165
- * @param m A container (a source file or a namespace)
166
- * @param fmxScope The Famix model of the container
167
- */
168
- processInterfaces(m, fmxScope) {
169
- console.info(`processInterfaces: ---------- Finding Interfaces:`);
170
- m.getInterfaces().forEach(i => {
171
- const fmxInterface = this.processInterface(i);
172
- fmxScope.addType(fmxInterface);
173
- });
174
- }
175
- /**
176
- * Builds a Famix model for the variables of a container
177
- * @param m A container (a source file, a namespace, a function or a method)
178
- * @param fmxScope The Famix model of the container
179
- */
180
- processVariables(m, fmxScope) {
181
- console.info(`processVariables: ---------- Finding Variables:`);
182
- m.getVariableStatements().forEach(v => {
183
- const fmxVariables = this.processVariableStatement(v);
184
- fmxVariables.forEach(fmxVariable => {
185
- fmxScope.addVariable(fmxVariable);
186
- });
187
- });
188
- }
189
- /**
190
- * Builds a Famix model for the enums of a container
191
- * @param m A container (a source file, a namespace, a function or a method)
192
- * @param fmxScope The Famix model of the container
193
- */
194
- processEnums(m, fmxScope) {
195
- console.info(`processEnums: ---------- Finding Enums:`);
196
- m.getEnums().forEach(e => {
197
- const fmxEnum = this.processEnum(e);
198
- fmxScope.addType(fmxEnum);
199
- });
200
- }
201
- /**
202
- * Builds a Famix model for the functions of a container
203
- * @param m A container (a source file, a namespace, a function or a method)
204
- * @param fmxScope The Famix model of the container
205
- */
206
- processFunctions(m, fmxScope) {
207
- console.info(`processFunctions: ---------- Finding Functions:`);
208
- m.getFunctions().forEach(f => {
209
- const fmxFunction = this.processFunction(f);
210
- fmxScope.addFunction(fmxFunction);
211
- });
212
- }
213
- /**
214
- * Builds a Famix model for the namespaces of a container
215
- * @param m A container (a source file or a namespace)
216
- * @param fmxScope The Famix model of the container
217
- */
218
- processNamespaces(m, fmxScope) {
219
- console.info(`processNamespaces: ---------- Finding Namespaces:`);
220
- m.getModules().forEach(md => {
221
- const fmxNsp = this.processNamespace(md);
222
- fmxScope.addNamespace(fmxNsp);
223
- });
224
- }
225
- /**
226
- * Builds a Famix model for an alias
227
- * @param a An alias
228
- * @returns A Famix.Alias representing the alias
229
- */
230
- processAlias(a) {
231
- const fmxAlias = this.famixFunctions.createFamixAlias(a);
232
- console.info(`processAlias: alias: ${a.getName()}, (${a.getType().getText()}), fqn = ${fmxAlias.getFullyQualifiedName()}`);
233
- this.processComments(a, fmxAlias);
234
- return fmxAlias;
235
- }
236
- /**
237
- * Builds a Famix model for a class
238
- * @param c A class
239
- * @returns A Famix.Class or a Famix.ParameterizableClass representing the class
240
- */
241
- processClass(c) {
242
- this.classes.push(c);
243
- const fmxClass = this.famixFunctions.createOrGetFamixClass(c);
244
- console.info(`processClass: class: ${c.getName()}, (${c.getType().getText()}), fqn = ${fmxClass.getFullyQualifiedName()}`);
245
- this.processComments(c, fmxClass);
246
- this.processDecorators(c, fmxClass);
247
- this.processStructuredType(c, fmxClass);
248
- c.getConstructors().forEach(con => {
249
- const fmxCon = this.processMethod(con);
250
- fmxClass.addMethod(fmxCon);
251
- });
252
- c.getGetAccessors().forEach(acc => {
253
- const fmxAcc = this.processMethod(acc);
254
- fmxClass.addMethod(fmxAcc);
255
- });
256
- c.getSetAccessors().forEach(acc => {
257
- const fmxAcc = this.processMethod(acc);
258
- fmxClass.addMethod(fmxAcc);
259
- });
260
- return fmxClass;
261
- }
262
- /**
263
- * Builds a Famix model for an interface
264
- * @param i An interface
265
- * @returns A Famix.Interface or a Famix.ParameterizableInterface representing the interface
266
- */
267
- processInterface(i) {
268
- this.interfaces.push(i);
269
- const fmxInterface = this.famixFunctions.createOrGetFamixInterface(i);
270
- console.info(`processInterface: interface: ${i.getName()}, (${i.getType().getText()}), fqn = ${fmxInterface.getFullyQualifiedName()}`);
271
- this.processComments(i, fmxInterface);
272
- this.processStructuredType(i, fmxInterface);
273
- return fmxInterface;
274
- }
275
- /**
276
- * Builds a Famix model for the type parameters, properties and methods of a structured type
277
- * @param c A structured type (a class or an interface)
278
- * @param fmxScope The Famix model of the structured type
279
- */
280
- processStructuredType(c, fmxScope) {
281
- console.info(`processStructuredType: ---------- Finding Properties and Methods:`);
282
- if (fmxScope instanceof Famix.ParameterizableClass || fmxScope instanceof Famix.ParameterizableInterface) {
283
- this.processTypeParameters(c, fmxScope);
284
- }
285
- c.getProperties().forEach(prop => {
286
- const fmxProperty = this.processProperty(prop);
287
- fmxScope.addProperty(fmxProperty);
288
- });
289
- c.getMethods().forEach(m => {
290
- const fmxMethod = this.processMethod(m);
291
- fmxScope.addMethod(fmxMethod);
292
- });
293
- }
294
- /**
295
- * Builds a Famix model for a property
296
- * @param p A property
297
- * @returns A Famix.Property representing the property
298
- */
299
- processProperty(p) {
300
- const fmxProperty = this.famixFunctions.createFamixProperty(p);
301
- console.info(`processProperty: property: ${p.getName()}, (${p.getType().getText()}), fqn = ${fmxProperty.getFullyQualifiedName()}`);
302
- this.processComments(p, fmxProperty);
303
- if (!(p instanceof ts_morph_1.PropertySignature)) {
304
- this.processDecorators(p, fmxProperty);
305
- this.accesses.set(fmxProperty.id, p);
306
- }
307
- return fmxProperty;
308
- }
309
- /**
310
- * Builds a Famix model for a method or an accessor
311
- * @param m A method or an accessor
312
- * @returns A Famix.Method or a Famix.Accessor representing the method or the accessor
313
- */
314
- processMethod(m) {
315
- const fmxMethod = this.famixFunctions.createFamixMethod(m, this.currentCC);
316
- console.info(`processMethod: method: ${!(m instanceof ts_morph_1.ConstructorDeclaration) ? m.getName() : "constructor"}, (${m.getType().getText()}), parent: ${m.getParent().getName()}, fqn = ${fmxMethod.getFullyQualifiedName()}`);
317
- this.processComments(m, fmxMethod);
318
- this.processTypeParameters(m, fmxMethod);
319
- this.processParameters(m, fmxMethod);
320
- if (!(m instanceof ts_morph_1.MethodSignature)) {
321
- this.processAliases(m, fmxMethod);
322
- this.processVariables(m, fmxMethod);
323
- this.processEnums(m, fmxMethod);
324
- this.processFunctions(m, fmxMethod);
325
- this.processFunctionExpressions(m, fmxMethod);
326
- this.methodsAndFunctionsWithId.set(fmxMethod.id, m);
327
- }
328
- if (m instanceof ts_morph_1.MethodDeclaration || m instanceof ts_morph_1.GetAccessorDeclaration || m instanceof ts_morph_1.SetAccessorDeclaration) {
329
- this.processDecorators(m, fmxMethod);
330
- }
331
- return fmxMethod;
332
- }
333
- /**
334
- * Builds a Famix model for a function
335
- * @param f A function
336
- * @returns A Famix.Function representing the function
337
- */
338
- processFunction(f) {
339
- const fmxFunction = this.famixFunctions.createFamixFunction(f, this.currentCC);
340
- console.info(`processFunction: function: ${(f.getName()) ? f.getName() : "anonymous"}, (${f.getType().getText()}), fqn = ${fmxFunction.getFullyQualifiedName()}`);
341
- this.processComments(f, fmxFunction);
342
- this.processAliases(f, fmxFunction);
343
- this.processTypeParameters(f, fmxFunction);
344
- this.processParameters(f, fmxFunction);
345
- this.processVariables(f, fmxFunction);
346
- this.processEnums(f, fmxFunction);
347
- this.processFunctions(f, fmxFunction);
348
- if (f instanceof ts_morph_1.FunctionDeclaration && !(f.getParent() instanceof ts_morph_1.Block)) {
349
- this.processFunctionExpressions(f, fmxFunction);
350
- }
351
- this.methodsAndFunctionsWithId.set(fmxFunction.id, f);
352
- return fmxFunction;
353
- }
354
- /**
355
- * Builds a Famix model for the function expressions of a function or a method
356
- * @param f A function or a method
357
- * @param fmxScope The Famix model of the function or the method
358
- */
359
- processFunctionExpressions(f, fmxScope) {
360
- console.info(`processFunctionExpressions: ---------- Finding Function Expressions:`);
361
- const functionExpressions = f.getDescendantsOfKind(ts_morph_1.SyntaxKind.FunctionExpression);
362
- functionExpressions.forEach((func) => {
363
- const fmxFunc = this.processFunction(func);
364
- fmxScope.addFunction(fmxFunc);
365
- });
366
- }
367
- /**
368
- * Builds a Famix model for the parameters of a method or a function
369
- * @param m A method or a function
370
- * @param fmxScope The Famix model of the method or the function
371
- */
372
- processParameters(m, fmxScope) {
373
- console.info(`processParameters: ---------- Finding Parameters:`);
374
- m.getParameters().forEach(param => {
375
- const fmxParam = this.processParameter(param);
376
- fmxScope.addParameter(fmxParam);
377
- });
378
- }
379
- /**
380
- * Builds a Famix model for a parameter
381
- * @param p A parameter
382
- * @returns A Famix.Parameter representing the parameter
383
- */
384
- processParameter(p) {
385
- const fmxParam = this.famixFunctions.createFamixParameter(p);
386
- console.info(`processParameter: parameter: ${p.getName()}, (${p.getType().getText()}), fqn = ${fmxParam.getFullyQualifiedName()}`);
387
- this.processComments(p, fmxParam);
388
- this.processDecorators(p, fmxParam);
389
- const parent = p.getParent();
390
- if (!(parent instanceof ts_morph_1.MethodSignature)) {
391
- this.accesses.set(fmxParam.id, p);
392
- }
393
- return fmxParam;
394
- }
395
- /**
396
- * Builds a Famix model for the type parameters of a class, an interface, a method or a function
397
- * @param e A class, an interface, a method or a function
398
- * @param fmxScope The Famix model of the class, the interface, the method or the function
399
- */
400
- processTypeParameters(e, fmxScope) {
401
- console.info(`processTypeParameters: ---------- Finding Type Parameters:`);
402
- e.getTypeParameters().forEach(tp => {
403
- const fmxParam = this.processTypeParameter(tp);
404
- fmxScope.addTypeParameter(fmxParam);
405
- });
406
- }
407
- /**
408
- * Builds a Famix model for a type parameter
409
- * @param tp A type parameter
410
- * @returns A Famix.TypeParameter representing the type parameter
411
- */
412
- processTypeParameter(tp) {
413
- const fmxTypeParameter = this.famixFunctions.createFamixTypeParameter(tp);
414
- console.info(`processTypeParameter: type parameter: ${tp.getName()}, (${tp.getType().getText()}), fqn = ${fmxTypeParameter.getFullyQualifiedName()}`);
415
- this.processComments(tp, fmxTypeParameter);
416
- return fmxTypeParameter;
417
- }
418
- /**
419
- * Builds a Famix model for the variables of a variable statement
420
- * @param v A variable statement
421
- * @returns An array of Famix.Variable representing the variables
422
- */
423
- processVariableStatement(v) {
424
- const fmxVariables = new Array();
425
- console.info(`processVariableStatement: variable statement: variable statement, (${v.getType().getText()}), ${v.getDeclarationKindKeyword().getText()}`);
426
- v.getDeclarations().forEach(variable => {
427
- const fmxVar = this.processVariable(variable);
428
- this.processComments(v, fmxVar);
429
- fmxVariables.push(fmxVar);
430
- });
431
- return fmxVariables;
432
- }
433
- /**
434
- * Builds a Famix model for a variable
435
- * @param v A variable
436
- * @returns A Famix.Variable representing the variable
437
- */
438
- processVariable(v) {
439
- const fmxVar = this.famixFunctions.createFamixVariable(v);
440
- console.info(`processVariable: variable: ${v.getName()}, (${v.getType().getText()}), ${v.getInitializer() ? "initializer: " + v.getInitializer().getText() : "initializer: "}, fqn = ${fmxVar.getFullyQualifiedName()}`);
441
- this.processComments(v, fmxVar);
442
- this.accesses.set(fmxVar.id, v);
443
- return fmxVar;
444
- }
445
- /**
446
- * Builds a Famix model for an enum
447
- * @param e An enum
448
- * @returns A Famix.Enum representing the enum
449
- */
450
- processEnum(e) {
451
- const fmxEnum = this.famixFunctions.createFamixEnum(e);
452
- console.info(`processEnum: enum: ${e.getName()}, (${e.getType().getText()}), fqn = ${fmxEnum.getFullyQualifiedName()}`);
453
- this.processComments(e, fmxEnum);
454
- e.getMembers().forEach(m => {
455
- const fmxEnumValue = this.processEnumValue(m);
456
- fmxEnum.addValue(fmxEnumValue);
457
- });
458
- return fmxEnum;
459
- }
460
- /**
461
- * Builds a Famix model for an enum member
462
- * @param v An enum member
463
- * @returns A Famix.EnumValue representing the enum member
464
- */
465
- processEnumValue(v) {
466
- const fmxEnumValue = this.famixFunctions.createFamixEnumValue(v);
467
- console.info(`processEnumValue: enum value: ${v.getName()}, (${v.getType().getText()}), fqn = ${fmxEnumValue.getFullyQualifiedName()}`);
468
- this.processComments(v, fmxEnumValue);
469
- this.accesses.set(fmxEnumValue.id, v);
470
- return fmxEnumValue;
471
- }
472
- /**
473
- * Builds a Famix model for the decorators of a class, a method, a parameter or a property
474
- * @param e A class, a method, a parameter or a property
475
- * @param fmxScope The Famix model of the class, the method, the parameter or the property
476
- */
477
- processDecorators(e, fmxScope) {
478
- console.info(`processDecorators: ---------- Finding Decorators:`);
479
- e.getDecorators().forEach(dec => {
480
- const fmxDec = this.processDecorator(dec, e);
481
- fmxScope.addDecorator(fmxDec);
482
- });
483
- }
484
- /**
485
- * Builds a Famix model for a decorator
486
- * @param d A decorator
487
- * @param e A class, a method, a parameter or a property
488
- * @returns A Famix.Decorator representing the decorator
489
- */
490
- processDecorator(d, e) {
491
- const fmxDec = this.famixFunctions.createOrGetFamixDecorator(d, e);
492
- console.info(`processDecorator: decorator: ${d.getName()}, (${d.getType().getText()}), fqn = ${fmxDec.getFullyQualifiedName()}`);
493
- this.processComments(d, fmxDec);
494
- return fmxDec;
495
- }
496
- /**
497
- * Builds a Famix model for the comments
498
- * @param e A ts-morph element
499
- * @param fmxScope The Famix model of the named entity
500
- */
501
- processComments(e, fmxScope) {
502
- console.info(`processComments: ---------- Finding Comments:`);
503
- e.getLeadingCommentRanges().forEach(c => {
504
- const fmxComment = this.processComment(c, fmxScope);
505
- fmxScope.addComment(fmxComment);
506
- });
507
- e.getTrailingCommentRanges().forEach(c => {
508
- const fmxComment = this.processComment(c, fmxScope);
509
- fmxScope.addComment(fmxComment);
510
- });
511
- }
512
- /**
513
- * Builds a Famix model for a comment
514
- * @param c A comment
515
- * @param fmxScope The Famix model of the comment's container
516
- * @returns A Famix.Comment representing the comment
517
- */
518
- processComment(c, fmxScope) {
519
- let isJSDoc = false;
520
- if (c.getText().substring(0, 3) === "/**") {
521
- isJSDoc = true;
522
- }
523
- const fmxComment = this.famixFunctions.createFamixComment(c, fmxScope, isJSDoc);
524
- console.info(`processComment: comment: ${c.getText()}`);
525
- return fmxComment;
526
- }
527
- /**
528
- * Checks if the file has any imports or exports to be considered a module
529
- * @param sourceFile A source file
530
- * @returns A boolean indicating if the file is a module
531
- */
532
- isModule(sourceFile) {
533
- if (sourceFile.getImportDeclarations().length > 0 || sourceFile.getExportedDeclarations().size > 0) {
534
- this.exports.push(sourceFile.getExportedDeclarations());
535
- return true;
536
- }
537
- return false;
538
- }
539
- }
540
- exports.ProcessFiles = ProcessFiles;
@@ -1,70 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ProcessImportClauses = void 0;
4
- /**
5
- * This class is used to build a Famix model for the import clauses
6
- */
7
- class ProcessImportClauses {
8
- /**
9
- * Initializes the ProcessImportClauses object
10
- * @param famixFunctions FamixFunctions object, it contains all the functions needed to create Famix entities
11
- */
12
- constructor(famixFunctions) {
13
- this.famixFunctions = famixFunctions;
14
- }
15
- /**
16
- * Builds a Famix model for the import clauses of the source files which are modules
17
- * @param modules An array of modules
18
- * @param exports An array of maps of exported declarations
19
- */
20
- processImportClauses(modules, exports) {
21
- console.info(`processImportClauses: Creating import clauses:`);
22
- modules.forEach(f => {
23
- f.getImportDeclarations().forEach(i => {
24
- const path = this.getModulePath(i);
25
- i.getNamedImports().forEach(ni => {
26
- console.info(`processImportClauses: Importing (named) ${ni.getName()} from ${i.getModuleSpecifierValue()}`);
27
- const importedEntityName = ni.getName();
28
- let bool = false;
29
- exports.forEach(e => {
30
- if (e.has(importedEntityName)) {
31
- bool = true;
32
- }
33
- });
34
- this.famixFunctions.createFamixImportClause(f, i.getModuleSpecifierValue(), path, ni, bool, false);
35
- });
36
- const defaultImport = i.getDefaultImport();
37
- if (defaultImport !== undefined) {
38
- console.info(`processImportClauses: Importing (default) ${defaultImport.getText()} from ${i.getModuleSpecifierValue()}`);
39
- this.famixFunctions.createFamixImportClause(f, i.getModuleSpecifierValue(), path, defaultImport, false, true);
40
- }
41
- const namespaceImport = i.getNamespaceImport();
42
- if (namespaceImport !== undefined) {
43
- console.info(`processImportClauses: Importing (namespace) ${namespaceImport.getText()} from ${i.getModuleSpecifierValue()}`);
44
- this.famixFunctions.createFamixImportClause(f, i.getModuleSpecifierValue(), path, namespaceImport, false, false);
45
- }
46
- });
47
- });
48
- }
49
- /**
50
- * Gets the path of a module to be imported
51
- * @param i An import declaration
52
- * @returns The path of the module to be imported
53
- */
54
- getModulePath(i) {
55
- let path;
56
- if (i.getModuleSpecifierSourceFile() === undefined) {
57
- if (i.getModuleSpecifierValue().substring(i.getModuleSpecifierValue().length - 3) === ".ts") {
58
- path = i.getModuleSpecifierValue();
59
- }
60
- else {
61
- path = i.getModuleSpecifierValue() + ".ts";
62
- }
63
- }
64
- else {
65
- path = i.getModuleSpecifierSourceFile().getFilePath();
66
- }
67
- return path;
68
- }
69
- }
70
- exports.ProcessImportClauses = ProcessImportClauses;
@@ -1,73 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ProcessInheritances = void 0;
4
- const ts_morph_1 = require("ts-morph");
5
- /**
6
- * This class is used to build a Famix model for the inheritances
7
- */
8
- class ProcessInheritances {
9
- /**
10
- * Initializes the ProcessInheritances object
11
- * @param famixFunctions FamixFunctions object, it contains all the functions needed to create Famix entities
12
- */
13
- constructor(famixFunctions) {
14
- this.famixFunctions = famixFunctions;
15
- }
16
- /**
17
- * Builds a Famix model for the inheritances of the classes and interfaces of the source files
18
- * @param classes An array of classes
19
- * @param interfaces An array of interfaces
20
- */
21
- processInheritances(classes, interfaces) {
22
- console.info(`processInheritances: Creating inheritances:`);
23
- classes.forEach(cls => {
24
- console.info(`processInheritances: Checking class inheritance for ${cls.getName()}`);
25
- const extClass = cls.getBaseClass();
26
- if (extClass !== undefined) {
27
- this.famixFunctions.createFamixInheritance(cls, extClass);
28
- console.info(`processInheritances: class: ${cls.getName()}, (${cls.getType().getText()}), extClass: ${extClass.getName()}, (${extClass.getType().getText()})`);
29
- }
30
- console.info(`processInheritances: Checking interface inheritance for ${cls.getName()}`);
31
- const implementedInterfaces = this.getImplementedOrExtendedInterfaces(interfaces, cls);
32
- implementedInterfaces.forEach(impInter => {
33
- this.famixFunctions.createFamixInheritance(cls, impInter);
34
- console.info(`processInheritances: class: ${cls.getName()}, (${cls.getType().getText()}), impInter: ${(impInter instanceof ts_morph_1.InterfaceDeclaration) ? impInter.getName() : impInter.getExpression().getText()}, (${(impInter instanceof ts_morph_1.InterfaceDeclaration) ? impInter.getType().getText() : impInter.getExpression().getText()})`);
35
- });
36
- });
37
- interfaces.forEach(inter => {
38
- console.info(`processInheritances: Checking interface inheritance for ${inter.getName()}`);
39
- const extendedInterfaces = this.getImplementedOrExtendedInterfaces(interfaces, inter);
40
- extendedInterfaces.forEach(extInter => {
41
- this.famixFunctions.createFamixInheritance(inter, extInter);
42
- console.info(`processInheritances: inter: ${inter.getName()}, (${inter.getType().getText()}), extInter: ${(extInter instanceof ts_morph_1.InterfaceDeclaration) ? extInter.getName() : extInter.getExpression().getText()}, (${(extInter instanceof ts_morph_1.InterfaceDeclaration) ? extInter.getType().getText() : extInter.getExpression().getText()})`);
43
- });
44
- });
45
- }
46
- /**
47
- * Gets the interfaces implemented or extended by a class or an interface
48
- * @param interfaces An array of interfaces
49
- * @param subClass A class or an interface
50
- * @returns An array of InterfaceDeclaration and ExpressionWithTypeArguments containing the interfaces implemented or extended by the subClass
51
- */
52
- getImplementedOrExtendedInterfaces(interfaces, subClass) {
53
- let impOrExtInterfaces;
54
- if (subClass instanceof ts_morph_1.ClassDeclaration) {
55
- impOrExtInterfaces = subClass.getImplements();
56
- }
57
- else {
58
- impOrExtInterfaces = subClass.getExtends();
59
- }
60
- const interfacesNames = interfaces.map(i => i.getName());
61
- const implementedOrExtendedInterfaces = new Array();
62
- impOrExtInterfaces.forEach(i => {
63
- if (interfacesNames.includes(i.getExpression().getText())) {
64
- implementedOrExtendedInterfaces.push(interfaces[interfacesNames.indexOf(i.getExpression().getText())]);
65
- }
66
- else {
67
- implementedOrExtendedInterfaces.push(i);
68
- }
69
- });
70
- return implementedOrExtendedInterfaces;
71
- }
72
- }
73
- exports.ProcessInheritances = ProcessInheritances;