ts2famix 1.0.12 → 1.0.14

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