ts2famix 1.0.1

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