ts2famix 1.0.10 → 1.0.12

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