ts2famix 1.3.1 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/analyze.js +38 -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 +48 -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,562 +0,0 @@
1
- import { ClassDeclaration, ConstructorDeclaration, FunctionDeclaration, Identifier, InterfaceDeclaration, MethodDeclaration, MethodSignature, ModuleDeclaration, PropertyDeclaration, PropertySignature, SourceFile, TypeParameterDeclaration, VariableDeclaration, ParameterDeclaration, Decorator, GetAccessorDeclaration, SetAccessorDeclaration, ImportSpecifier, CommentRange, EnumDeclaration, EnumMember, TypeAliasDeclaration, FunctionExpression, ExpressionWithTypeArguments, ImportDeclaration } from "ts-morph";
2
- import * as Famix from "../lib/famix/src/model/famix";
3
- import { FamixRepository } from "../lib/famix/src/famix_repository";
4
- import { FQNFunctions } from "../fqn";
5
- import { FamixFunctionsIndex } from "./famix_functions_index";
6
- import { FamixFunctionsAssociations } from "./famix_functions_associations";
7
- import { FamixFunctionsTypes } from "./famix_functions_types";
8
- import { logger } from "../analyze";
9
-
10
- /**
11
- * This class contains all the functions needed to create Famix entities
12
- */
13
- export class FamixFunctions {
14
-
15
- private famixRep = new FamixRepository(); // The Famix repository
16
- private FQNFunctions = new FQNFunctions(); // The fully qualified name functions
17
- private fmxAliasMap = new Map<string, Famix.Alias>(); // Maps the alias names to their Famix model
18
- private fmxClassMap = new Map<string, Famix.Class | Famix.ParameterizableClass>(); // Maps the fully qualifiedclass names to their Famix model
19
- private fmxInterfaceMap = new Map<string, Famix.Interface | Famix.ParameterizableInterface>(); // Maps the interface names to their Famix model
20
- private fmxNamespaceMap = new Map<string, Famix.Namespace>(); // Maps the namespace names to their Famix model
21
- private fmxFileMap = new Map<string, Famix.ScriptEntity | Famix.Module>(); // Maps the source file names to their Famix model
22
- private famixFunctionsIndex = new FamixFunctionsIndex(this.famixRep); // FamixFunctionsIndex object, it contains all the functions needed to create Famix index file anchors
23
- private famixFunctionsAssociations = new FamixFunctionsAssociations(this.famixRep, this.fmxClassMap, this.fmxInterfaceMap); // FamixFunctionsAssociations object, it contains all the functions needed to create Famix associations
24
- private famixFunctionsTypes = new FamixFunctionsTypes(this.famixRep); // FamixFunctionsTypes object, it contains all the functions needed to create Famix types
25
- private UNKNOWN_VALUE = '(unknown due to parsing error)'; // The value to use when a name is not usable
26
-
27
- /**
28
- * Gets the Famix repository
29
- * @returns The Famix repository
30
- */
31
- public getFamixRepository(): FamixRepository {
32
- return this.famixRep;
33
- }
34
-
35
- /**
36
- * Creates or gets a Famix script entity or module
37
- * @param f A source file
38
- * @param isModule A boolean indicating if the source file is a module
39
- * @returns The Famix model of the source file
40
- */
41
- public createOrGetFamixFile(f: SourceFile, isModule: boolean): Famix.ScriptEntity | Famix.Module {
42
- let fmxFile: Famix.ScriptEntity | Famix.Module;
43
- const fileName = f.getBaseName();
44
- const fullyQualifiedFilename = f.getFilePath();
45
- if (!this.fmxFileMap.has(fullyQualifiedFilename)) {
46
- if (isModule) {
47
- fmxFile = new Famix.Module(this.famixRep);
48
- }
49
- else {
50
- fmxFile = new Famix.ScriptEntity(this.famixRep);
51
- }
52
- fmxFile.setName(fileName);
53
- fmxFile.setNumberOfLinesOfText(f.getEndLineNumber() - f.getStartLineNumber());
54
- fmxFile.setNumberOfCharacters(f.getFullText().length);
55
-
56
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(f, fmxFile);
57
-
58
- this.fmxFileMap.set(fullyQualifiedFilename, fmxFile);
59
- }
60
- else {
61
- fmxFile = this.fmxFileMap.get(fullyQualifiedFilename);
62
- }
63
- return fmxFile;
64
- }
65
-
66
- /**
67
- * Creates or gets a Famix namespace
68
- * @param m A namespace
69
- * @returns The Famix model of the namespace
70
- */
71
- public createOrGetFamixNamespace(m: ModuleDeclaration): Famix.Namespace {
72
- let fmxNamespace: Famix.Namespace;
73
- const namespaceName = m.getName();
74
- if (!this.fmxNamespaceMap.has(namespaceName)) {
75
- fmxNamespace = new Famix.Namespace(this.famixRep);
76
- fmxNamespace.setName(namespaceName);
77
-
78
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(m, fmxNamespace);
79
-
80
- this.fmxNamespaceMap.set(namespaceName, fmxNamespace);
81
- }
82
- else {
83
- fmxNamespace = this.fmxNamespaceMap.get(namespaceName);
84
- }
85
- return fmxNamespace;
86
- }
87
-
88
- /**
89
- * Creates a Famix alias
90
- * @param a An alias
91
- * @returns The Famix model of the alias
92
- */
93
- public createFamixAlias(a: TypeAliasDeclaration): Famix.Alias {
94
- let fmxAlias: Famix.Alias;
95
- const aliasName = a.getName();
96
- const aliasFullyQualifiedName = a.getType().getText(); // this.FQNFunctions.getFQN(a);
97
- if (!this.fmxAliasMap.has(aliasFullyQualifiedName)) {
98
- fmxAlias = new Famix.Alias(this.famixRep);
99
- fmxAlias.setName(a.getName());
100
- const aliasNameWithGenerics = aliasName + (a.getTypeParameters().length ? ("<" + a.getTypeParameters().map(tp => tp.getName()).join(", ") + ">") : "");
101
- logger.debug(`> NOTE: alias ${aliasName} has fully qualified name ${aliasFullyQualifiedName} and name with generics ${aliasNameWithGenerics}.`);
102
-
103
- const fmxType = this.createOrGetFamixType(aliasNameWithGenerics, a);
104
- fmxAlias.setAliasedEntity(fmxType);
105
-
106
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(a, fmxAlias);
107
-
108
- this.fmxAliasMap.set(aliasFullyQualifiedName, fmxAlias);
109
- }
110
- else {
111
- fmxAlias = this.fmxAliasMap.get(aliasFullyQualifiedName);
112
- }
113
- return fmxAlias;
114
- }
115
-
116
- /**
117
- * Creates or gets a Famix class or parameterizable class
118
- * @param cls A class
119
- * @returns The Famix model of the class
120
- */
121
- public createOrGetFamixClass(cls: ClassDeclaration): Famix.Class | Famix.ParameterizableClass {
122
- let fmxClass: Famix.Class | Famix.ParameterizableClass;
123
- const isAbstract = cls.isAbstract();
124
- const classFullyQualifiedName = this.FQNFunctions.getFQN(cls);
125
- const clsName = cls.getName();
126
- if (!this.fmxClassMap.has(classFullyQualifiedName)) {
127
- const isGeneric = cls.getTypeParameters().length;
128
- if (isGeneric) {
129
- fmxClass = new Famix.ParameterizableClass(this.famixRep);
130
- }
131
- else {
132
- fmxClass = new Famix.Class(this.famixRep);
133
- }
134
-
135
- fmxClass.setName(clsName);
136
- fmxClass.setFullyQualifiedName(classFullyQualifiedName);
137
- fmxClass.setIsAbstract(isAbstract);
138
-
139
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(cls, fmxClass);
140
-
141
- this.fmxClassMap.set(classFullyQualifiedName, fmxClass);
142
- }
143
- else {
144
- fmxClass = this.fmxClassMap.get(classFullyQualifiedName) as (Famix.Class | Famix.ParameterizableClass);
145
- }
146
- return fmxClass;
147
- }
148
-
149
- /**
150
- * Creates or gets a Famix interface or parameterizable interface
151
- * @param inter An interface
152
- * @returns The Famix model of the interface
153
- */
154
- public createOrGetFamixInterface(inter: InterfaceDeclaration): Famix.Interface | Famix.ParameterizableInterface {
155
- let fmxInterface: Famix.Interface | Famix.ParameterizableInterface;
156
- const interName = inter.getName();
157
- const interFullyQualifiedName = this.FQNFunctions.getFQN(inter);
158
- if (!this.fmxInterfaceMap.has(interName)) {
159
- const isGeneric = inter.getTypeParameters().length;
160
- if (isGeneric) {
161
- fmxInterface = new Famix.ParameterizableInterface(this.famixRep);
162
- }
163
- else {
164
- fmxInterface = new Famix.Interface(this.famixRep);
165
- }
166
-
167
- fmxInterface.setName(interName);
168
-
169
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(inter, fmxInterface);
170
-
171
- this.fmxInterfaceMap.set(interFullyQualifiedName, fmxInterface);
172
- }
173
- else {
174
- fmxInterface = this.fmxInterfaceMap.get(interName) as (Famix.Interface | Famix.ParameterizableInterface);
175
- }
176
- return fmxInterface;
177
- }
178
-
179
- /**
180
- * Creates a Famix property
181
- * @param property A property
182
- * @returns The Famix model of the property
183
- */
184
- public createFamixProperty(property: PropertyDeclaration | PropertySignature): Famix.Property {
185
- const fmxProperty = new Famix.Property(this.famixRep);
186
- const isSignature = property instanceof PropertySignature;
187
- fmxProperty.setName(property.getName());
188
-
189
- let propTypeName = this.UNKNOWN_VALUE;
190
- try {
191
- propTypeName = property.getType().getText().trim();
192
- } catch (error) {
193
- logger.error(`> WARNING: got exception ${error}. Failed to get usable name for property: ${property.getName()}. Continuing...`);
194
- }
195
-
196
- const fmxType = this.createOrGetFamixType(propTypeName, property);
197
- fmxProperty.setDeclaredType(fmxType);
198
-
199
- property.getModifiers().forEach(m => fmxProperty.addModifier(m.getText()));
200
- if (!isSignature && property.getExclamationTokenNode()) {
201
- fmxProperty.addModifier("!");
202
- }
203
- if (property.getQuestionTokenNode()) {
204
- fmxProperty.addModifier("?");
205
- }
206
- if (property.getName().substring(0, 1) === "#") {
207
- fmxProperty.addModifier("#");
208
- }
209
-
210
- if (fmxProperty.getModifiers().has("static")) {
211
- fmxProperty.setIsClassSide(true);
212
- }
213
- else {
214
- fmxProperty.setIsClassSide(false);
215
- }
216
-
217
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(property, fmxProperty);
218
-
219
- return fmxProperty;
220
- }
221
-
222
- /**
223
- * Creates a Famix method or accessor
224
- * @param method A method or an accessor
225
- * @param currentCC The cyclomatic complexity metrics of the current source file
226
- * @returns The Famix model of the method or the accessor
227
- */
228
- public createFamixMethod(method: MethodDeclaration | ConstructorDeclaration | MethodSignature | GetAccessorDeclaration | SetAccessorDeclaration, currentCC: unknown): Famix.Method | Famix.Accessor {
229
- let fmxMethod: Famix.Method | Famix.Accessor;
230
- if (method instanceof GetAccessorDeclaration || method instanceof SetAccessorDeclaration) {
231
- fmxMethod = new Famix.Accessor(this.famixRep);
232
- const isGetter = method instanceof GetAccessorDeclaration;
233
- const isSetter = method instanceof SetAccessorDeclaration;
234
- if (isGetter) {(fmxMethod as Famix.Accessor).setKind("getter");}
235
- if (isSetter) {(fmxMethod as Famix.Accessor).setKind("setter");}
236
- }
237
- else {
238
- fmxMethod = new Famix.Method(this.famixRep);
239
- }
240
- const isConstructor = method instanceof ConstructorDeclaration;
241
- const isSignature = method instanceof MethodSignature;
242
- const isGeneric = method.getTypeParameters().length > 0;
243
- fmxMethod.setIsGeneric(isGeneric);
244
-
245
- let isAbstract = false;
246
- let isStatic = false;
247
- if (method instanceof MethodDeclaration || method instanceof GetAccessorDeclaration || method instanceof SetAccessorDeclaration) {
248
- isAbstract = method.isAbstract();
249
- isStatic = method.isStatic();
250
- }
251
-
252
- if (isConstructor) {(fmxMethod as Famix.Accessor).setKind("constructor");}
253
- fmxMethod.setIsAbstract(isAbstract);
254
- fmxMethod.setIsClassSide(isStatic);
255
- fmxMethod.setIsPrivate((method instanceof MethodDeclaration || method instanceof GetAccessorDeclaration || method instanceof SetAccessorDeclaration) ? (method.getModifiers().find(x => x.getText() === 'private')) !== undefined : false);
256
- fmxMethod.setIsProtected((method instanceof MethodDeclaration || method instanceof GetAccessorDeclaration || method instanceof SetAccessorDeclaration) ? (method.getModifiers().find(x => x.getText() === 'protected')) !== undefined : false);
257
- fmxMethod.setSignature(this.computeSignature(method.getText()));
258
-
259
- let methodName: string;
260
- if (isConstructor) {
261
- methodName = "constructor";
262
- }
263
- else {
264
- methodName = (method as MethodDeclaration | MethodSignature | GetAccessorDeclaration | SetAccessorDeclaration).getName();
265
- }
266
- fmxMethod.setName(methodName);
267
-
268
- if (!isConstructor) {
269
- if (method.getName().substring(0, 1) === "#") {
270
- fmxMethod.setIsPrivate(true);
271
- }
272
- }
273
-
274
- if (!fmxMethod.getIsPrivate() && !fmxMethod.getIsProtected()) {
275
- fmxMethod.setIsPublic(true);
276
- }
277
- else {
278
- fmxMethod.setIsPublic(false);
279
- }
280
-
281
- if (!isSignature) {
282
- fmxMethod.setCyclomaticComplexity(currentCC[fmxMethod.getName()]);
283
- }
284
- else {
285
- fmxMethod.setCyclomaticComplexity(0);
286
- }
287
-
288
- let methodTypeName = this.UNKNOWN_VALUE;
289
- try {
290
- methodTypeName = method.getReturnType().getText().trim();
291
- } catch (error) {
292
- logger.error(`> WARNING: got exception ${error}. Failed to get usable name for return type of method: ${fmxMethod.getName()}. Continuing...`);
293
- }
294
-
295
- const fmxType = this.createOrGetFamixType(methodTypeName, method);
296
- fmxMethod.setDeclaredType(fmxType);
297
- fmxMethod.setNumberOfLinesOfCode(method.getEndLineNumber() - method.getStartLineNumber());
298
- const parameters = method.getParameters();
299
- fmxMethod.setNumberOfParameters(parameters.length);
300
-
301
- if (!isSignature) {
302
- fmxMethod.setNumberOfStatements(method.getStatements().length);
303
- }
304
- else {
305
- fmxMethod.setNumberOfStatements(0);
306
- }
307
-
308
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(method, fmxMethod);
309
-
310
- return fmxMethod;
311
- }
312
-
313
- /**
314
- * Creates a Famix function
315
- * @param func A function
316
- * @param currentCC The cyclomatic complexity metrics of the current source file
317
- * @returns The Famix model of the function
318
- */
319
- public createFamixFunction(func: FunctionDeclaration | FunctionExpression, currentCC: unknown): Famix.Function {
320
- const fmxFunction = new Famix.Function(this.famixRep);
321
- if (func.getName()) {
322
- fmxFunction.setName(func.getName());
323
- }
324
- else {
325
- fmxFunction.setName("anonymous");
326
- }
327
- fmxFunction.setSignature(this.computeSignature(func.getText()));
328
- fmxFunction.setCyclomaticComplexity(currentCC[fmxFunction.getName()]);
329
- const isGeneric = func.getTypeParameters().length > 0;
330
- fmxFunction.setIsGeneric(isGeneric);
331
-
332
- let functionTypeName = this.UNKNOWN_VALUE;
333
- try {
334
- functionTypeName = func.getReturnType().getText().trim();
335
- } catch (error) {
336
- logger.error(`> WARNING: got exception ${error}. Failed to get usable name for return type of function: ${func.getName()}. Continuing...`);
337
- }
338
-
339
- const fmxType = this.createOrGetFamixType(functionTypeName, func);
340
- fmxFunction.setDeclaredType(fmxType);
341
- fmxFunction.setNumberOfLinesOfCode(func.getEndLineNumber() - func.getStartLineNumber());
342
- const parameters = func.getParameters();
343
- fmxFunction.setNumberOfParameters(parameters.length);
344
- fmxFunction.setNumberOfStatements(func.getStatements().length);
345
-
346
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(func, fmxFunction);
347
-
348
- return fmxFunction;
349
- }
350
-
351
- /**
352
- * Creates a Famix parameter
353
- * @param param A parameter
354
- * @returns The Famix model of the parameter
355
- */
356
- public createFamixParameter(param: ParameterDeclaration): Famix.Parameter {
357
- const fmxParam = new Famix.Parameter(this.famixRep);
358
-
359
- let paramTypeName = this.UNKNOWN_VALUE;
360
- try {
361
- paramTypeName = param.getType().getText().trim();
362
- } catch (error) {
363
- logger.error(`> WARNING: got exception ${error}. Failed to get usable name for parameter: ${param.getName()}. Continuing...`);
364
- }
365
-
366
- const fmxType = this.createOrGetFamixType(paramTypeName, param);
367
- fmxParam.setDeclaredType(fmxType);
368
- fmxParam.setName(param.getName());
369
-
370
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(param, fmxParam);
371
-
372
- return fmxParam;
373
- }
374
-
375
- /**
376
- * Creates a Famix type parameter
377
- * @param tp A type parameter
378
- * @returns The Famix model of the type parameter
379
- */
380
- public createFamixParameterType(tp: TypeParameterDeclaration): Famix.ParameterType {
381
- const fmxParameterType = new Famix.ParameterType(this.famixRep);
382
- fmxParameterType.setName(tp.getName());
383
-
384
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(tp, fmxParameterType);
385
-
386
- return fmxParameterType;
387
- }
388
-
389
- /**
390
- * Creates a Famix variable
391
- * @param variable A variable
392
- * @returns The Famix model of the variable
393
- */
394
- public createFamixVariable(variable: VariableDeclaration): Famix.Variable {
395
- const fmxVariable = new Famix.Variable(this.famixRep);
396
-
397
- let variableTypeName = this.UNKNOWN_VALUE;
398
- try {
399
- variableTypeName = variable.getType().getText().trim();
400
- } catch (error) {
401
- logger.error(`> WARNING: got exception ${error}. Failed to get usable name for variable: ${variable.getName()}. Continuing...`);
402
- }
403
-
404
- const fmxType = this.createOrGetFamixType(variableTypeName, variable);
405
- fmxVariable.setDeclaredType(fmxType);
406
- fmxVariable.setName(variable.getName());
407
-
408
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(variable, fmxVariable);
409
-
410
- return fmxVariable;
411
- }
412
-
413
- /**
414
- * Creates a Famix enum
415
- * @param enumEntity An enum
416
- * @returns The Famix model of the enum
417
- */
418
- public createFamixEnum(enumEntity: EnumDeclaration): Famix.Enum {
419
- const fmxEnum = new Famix.Enum(this.famixRep);
420
- fmxEnum.setName(enumEntity.getName());
421
-
422
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(enumEntity, fmxEnum);
423
-
424
- return fmxEnum;
425
- }
426
-
427
- /**
428
- * Creates a Famix enum value
429
- * @param enumMember An enum member
430
- * @returns The Famix model of the enum member
431
- */
432
- public createFamixEnumValue(enumMember: EnumMember): Famix.EnumValue {
433
- const fmxEnumValue = new Famix.EnumValue(this.famixRep);
434
-
435
- let enumValueTypeName = this.UNKNOWN_VALUE;
436
- try {
437
- enumValueTypeName = enumMember.getType().getText().trim();
438
- } catch (error) {
439
- logger.error(`> WARNING: got exception ${error}. Failed to get usable name for enum value: ${enumMember.getName()}. Continuing...`);
440
- }
441
-
442
- const fmxType = this.createOrGetFamixType(enumValueTypeName, enumMember);
443
- fmxEnumValue.setDeclaredType(fmxType);
444
- fmxEnumValue.setName(enumMember.getName());
445
-
446
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(enumMember, fmxEnumValue);
447
-
448
- return fmxEnumValue;
449
- }
450
-
451
- /**
452
- * Creates or gets a Famix decorator
453
- * @param decorator A decorator
454
- * @param decoratedEntity A class, a method, a parameter or a property
455
- * @returns The Famix model of the decorator
456
- */
457
- public createOrGetFamixDecorator(decorator: Decorator, decoratedEntity: ClassDeclaration | MethodDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | ParameterDeclaration | PropertyDeclaration): Famix.Decorator {
458
- const fmxDecorator = new Famix.Decorator(this.famixRep);
459
- const decoratorName = "@" + decorator.getName();
460
- const decoratorExpression = decorator.getText().substring(1);
461
-
462
- fmxDecorator.setName(decoratorName);
463
- fmxDecorator.setDecoratorExpression(decoratorExpression);
464
- const decoratedEntityFullyQualifiedName = this.FQNFunctions.getFQN(decoratedEntity);
465
- const fmxDecoratedEntity = this.getFamixEntityByFullyQualifiedName(decoratedEntityFullyQualifiedName) as Famix.NamedEntity;
466
- fmxDecorator.setDecoratedEntity(fmxDecoratedEntity);
467
-
468
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(decorator, fmxDecorator);
469
-
470
- return fmxDecorator;
471
- }
472
-
473
- /**
474
- * Creates a Famix comment
475
- * @param comment A comment
476
- * @param fmxScope The Famix model of the comment's container
477
- * @param isJSDoc A boolean indicating if the comment is a JSDoc
478
- * @returns The Famix model of the comment
479
- */
480
- public createFamixComment(comment: CommentRange, fmxScope: Famix.NamedEntity, isJSDoc: boolean): Famix.Comment {
481
- logger.debug(`> NOTE: creating comment ${comment.getText()} in scope ${fmxScope.getName()}.`);
482
- const fmxComment = new Famix.Comment(this.famixRep);
483
- fmxComment.setContainer(fmxScope); // adds comment to the container's comments collection
484
- fmxComment.setIsJSDoc(isJSDoc);
485
-
486
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(comment, fmxComment);
487
-
488
- return fmxComment;
489
- }
490
-
491
- /**
492
- * Creates or gets a Famix type
493
- * @param typeName A type name
494
- * @param element A ts-morph element
495
- * @returns The Famix model of the type
496
- */
497
- private createOrGetFamixType(typeName: string, element: TypeAliasDeclaration | PropertyDeclaration | PropertySignature | MethodDeclaration | ConstructorDeclaration | MethodSignature | GetAccessorDeclaration | SetAccessorDeclaration | FunctionDeclaration | FunctionExpression | ParameterDeclaration | VariableDeclaration | EnumMember): Famix.Type | Famix.PrimitiveType | Famix.ParameterizedType {
498
- return this.famixFunctionsTypes.createOrGetFamixType(typeName, element);
499
- }
500
-
501
- /**
502
- * Creates a Famix access
503
- * @param node A node
504
- * @param id An id of a parameter, a variable, a property or an enum member
505
- */
506
- public createFamixAccess(node: Identifier, id: number): void {
507
- this.famixFunctionsAssociations.createFamixAccess(node, id);
508
- }
509
-
510
- /**
511
- * Creates a Famix invocation
512
- * @param node A node
513
- * @param m A method or a function
514
- * @param id The id of the method or the function
515
- */
516
- public createFamixInvocation(node: Identifier, m: MethodDeclaration | ConstructorDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | FunctionDeclaration | FunctionExpression, id: number): void {
517
- this.famixFunctionsAssociations.createFamixInvocation(node, m, id);
518
- }
519
-
520
- /**
521
- * Creates a Famix inheritance
522
- * @param cls A class or an interface (subclass)
523
- * @param inhClass The inherited class or interface (superclass)
524
- */
525
- public createFamixInheritance(cls: ClassDeclaration | InterfaceDeclaration, inhClass: ClassDeclaration | InterfaceDeclaration | ExpressionWithTypeArguments): void {
526
- this.famixFunctionsAssociations.createFamixInheritance(cls, inhClass);
527
- }
528
-
529
- /**
530
- * Creates a Famix import clause
531
- * @param importClauseInfo An import clause
532
- * @param importDeclaration An import declaration (optional)
533
- * @param importer A source file which is a module
534
- * @param moduleSpecifier The name of the module where the export declaration is
535
- * @param moduleSpecifierFilePath The path of the module where the export declaration is
536
- * @param importElement The imported entity
537
- * @param isInExports A boolean indicating if the imported entity is in the exports
538
- * @param isDefaultExport A boolean indicating if the imported entity is a default export
539
- */
540
- public createFamixImportClause(importClauseInfo: {importDeclaration?: ImportDeclaration, importer: SourceFile, moduleSpecifierFilePath: string, importElement: ImportSpecifier | Identifier, isInExports: boolean, isDefaultExport: boolean}): void {
541
- this.famixFunctionsAssociations.createFamixImportClause(importClauseInfo);
542
- }
543
-
544
- /**
545
- * Gets a Famix entity by fully qualified name
546
- * @param fullyQualifiedName A fully qualified name
547
- * @returns The Famix entity corresponding to the fully qualified name
548
- */
549
- private getFamixEntityByFullyQualifiedName(fullyQualifiedName: string): Famix.Entity {
550
- return this.famixRep.getFamixEntityByFullyQualifiedName(fullyQualifiedName) as Famix.Entity;
551
- }
552
-
553
- /**
554
- * Gets the signature of a method or a function
555
- * @param text A method or a function source code
556
- * @returns The signature of the method or the function
557
- */
558
- private computeSignature(text: string): string {
559
- const endSignatureText = text.indexOf("{");
560
- return text.substring(0, endSignatureText).trim();
561
- }
562
- }