ts2famix 1.3.1 → 1.4.0

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