ts2famix 1.0.13 → 1.0.15
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.
- package/.eslintrc.json +24 -24
- package/LICENSE +23 -23
- package/README.md +109 -109
- package/dist/analyze.js +107 -0
- package/dist/analyze_functions/processAccesses.js +55 -0
- package/dist/analyze_functions/processFiles.js +554 -0
- package/dist/analyze_functions/processImportClauses.js +70 -0
- package/dist/analyze_functions/processInheritances.js +73 -0
- package/dist/analyze_functions/processInvocations.js +49 -0
- package/dist/famix2puml.js +125 -0
- package/dist/famix_functions/famix_functions.js +525 -0
- package/dist/famix_functions/famix_functions_associations.js +223 -0
- package/dist/famix_functions/famix_functions_index.js +62 -0
- package/dist/famix_functions/famix_functions_types.js +114 -0
- package/dist/fqn.js +126 -0
- package/dist/lib/famix/src/famix_JSON_exporter.js +54 -0
- package/dist/lib/famix/src/famix_base_element.js +13 -0
- package/dist/lib/famix/src/famix_repository.js +199 -0
- package/dist/lib/famix/src/index.js +30 -0
- package/dist/lib/famix/src/model/famix/access.js +39 -0
- package/dist/lib/famix/src/model/famix/accessor.js +16 -0
- package/dist/lib/famix/src/model/famix/alias.js +32 -0
- package/dist/lib/famix/src/model/famix/association.js +36 -0
- package/dist/lib/famix/src/model/famix/behavioral_entity.js +81 -0
- package/dist/lib/famix/src/model/famix/c_source_language.js +16 -0
- package/dist/lib/famix/src/model/famix/class.js +70 -0
- package/dist/lib/famix/src/model/famix/comment.js +38 -0
- package/dist/lib/famix/src/model/famix/container_entity.js +125 -0
- package/dist/lib/famix/src/model/famix/custom_source_language.js +23 -0
- package/dist/lib/famix/src/model/famix/decorator.js +31 -0
- package/dist/lib/famix/src/model/famix/entity.js +16 -0
- package/dist/lib/famix/src/model/famix/enum.js +30 -0
- package/dist/lib/famix/src/model/famix/enum_value.js +24 -0
- package/dist/lib/famix/src/model/famix/function.js +16 -0
- package/dist/lib/famix/src/model/famix/implicit_variable.js +16 -0
- package/dist/lib/famix/src/model/famix/import_clause.js +39 -0
- package/dist/lib/famix/src/model/famix/index.js +87 -0
- package/dist/lib/famix/src/model/famix/indexed_file_anchor.js +37 -0
- package/dist/lib/famix/src/model/famix/inheritance.js +32 -0
- package/dist/lib/famix/src/model/famix/interface.js +63 -0
- package/dist/lib/famix/src/model/famix/invocation.js +53 -0
- package/dist/lib/famix/src/model/famix/method.js +66 -0
- package/dist/lib/famix/src/model/famix/module.js +31 -0
- package/dist/lib/famix/src/model/famix/named_entity.js +77 -0
- package/dist/lib/famix/src/model/famix/namespace.js +24 -0
- package/dist/lib/famix/src/model/famix/parameter.js +24 -0
- package/dist/lib/famix/src/model/famix/parameterizable_class.js +30 -0
- package/dist/lib/famix/src/model/famix/parameterizable_interface.js +30 -0
- package/dist/lib/famix/src/model/famix/parameterized_type.js +36 -0
- package/dist/lib/famix/src/model/famix/primitive_type.js +16 -0
- package/dist/lib/famix/src/model/famix/property.js +44 -0
- package/dist/lib/famix/src/model/famix/reference.js +32 -0
- package/dist/lib/famix/src/model/famix/scoping_entity.js +34 -0
- package/dist/lib/famix/src/model/famix/script_entity.js +30 -0
- package/dist/lib/famix/src/model/famix/source_anchor.js +26 -0
- package/dist/lib/famix/src/model/famix/source_language.js +30 -0
- package/dist/lib/famix/src/model/famix/sourced_entity.js +55 -0
- package/dist/lib/famix/src/model/famix/structural_entity.js +38 -0
- package/dist/lib/famix/src/model/famix/text_anchor.js +37 -0
- package/dist/lib/famix/src/model/famix/type.js +71 -0
- package/dist/lib/famix/src/model/famix/type_parameter.js +24 -0
- package/dist/lib/famix/src/model/famix/variable.js +23 -0
- package/dist/lib/ts-complex/cyclomatic-service.js +83 -0
- package/dist/ts2famix-cli.js +63 -0
- package/dist/ts2famix-tsconfig.js +53 -0
- package/jest.config-old.ts +199 -199
- package/package.json +47 -47
- package/src/analyze.ts +94 -94
- package/src/analyze_functions/processAccesses.ts +57 -57
- package/src/analyze_functions/processFiles.ts +669 -669
- package/src/analyze_functions/processImportClauses.ts +77 -77
- package/src/analyze_functions/processInheritances.ts +84 -84
- package/src/analyze_functions/processInvocations.ts +51 -51
- package/src/famix2puml.ts +119 -119
- package/src/famix_functions/famix_functions.ts +565 -559
- package/src/famix_functions/famix_functions_associations.ts +225 -215
- package/src/famix_functions/famix_functions_index.ts +44 -44
- package/src/famix_functions/famix_functions_types.ts +105 -105
- package/src/generate_uml.sh +16 -16
- package/src/lib/famix/License.md +22 -22
- package/src/lib/famix/package-lock.json +301 -301
- package/src/lib/famix/package.json +27 -27
- package/src/lib/famix/readme.md +4 -4
- package/src/lib/famix/src/famix_JSON_exporter.ts +56 -56
- package/src/lib/famix/src/famix_base_element.ts +18 -18
- package/src/lib/famix/src/famix_repository.ts +212 -199
- package/src/lib/famix/src/index.ts +8 -8
- package/src/lib/famix/src/model/famix/access.ts +53 -53
- package/src/lib/famix/src/model/famix/accessor.ts +15 -15
- package/src/lib/famix/src/model/famix/alias.ts +41 -41
- package/src/lib/famix/src/model/famix/association.ts +44 -44
- package/src/lib/famix/src/model/famix/behavioral_entity.ts +107 -107
- package/src/lib/famix/src/model/famix/c_source_language.ts +15 -15
- package/src/lib/famix/src/model/famix/class.ts +86 -86
- package/src/lib/famix/src/model/famix/comment.ts +50 -50
- package/src/lib/famix/src/model/famix/container_entity.ts +165 -165
- package/src/lib/famix/src/model/famix/custom_source_language.ts +27 -27
- package/src/lib/famix/src/model/famix/decorator.ts +39 -39
- package/src/lib/famix/src/model/famix/entity.ts +15 -15
- package/src/lib/famix/src/model/famix/enum.ts +31 -31
- package/src/lib/famix/src/model/famix/enum_value.ts +29 -29
- package/src/lib/famix/src/model/famix/function.ts +15 -15
- package/src/lib/famix/src/model/famix/implicit_variable.ts +15 -15
- package/src/lib/famix/src/model/famix/import_clause.ts +53 -53
- package/src/lib/famix/src/model/famix/index.ts +42 -42
- package/src/lib/famix/src/model/famix/indexed_file_anchor.ts +49 -49
- package/src/lib/famix/src/model/famix/inheritance.ts +42 -42
- package/src/lib/famix/src/model/famix/interface.ts +75 -75
- package/src/lib/famix/src/model/famix/invocation.ts +68 -68
- package/src/lib/famix/src/model/famix/method.ts +96 -96
- package/src/lib/famix/src/model/famix/module.ts +31 -31
- package/src/lib/famix/src/model/famix/named_entity.ts +98 -98
- package/src/lib/famix/src/model/famix/namespace.ts +28 -28
- package/src/lib/famix/src/model/famix/parameter.ts +29 -29
- package/src/lib/famix/src/model/famix/parameterizable_class.ts +31 -31
- package/src/lib/famix/src/model/famix/parameterizable_interface.ts +31 -31
- package/src/lib/famix/src/model/famix/parameterized_type.ts +40 -40
- package/src/lib/famix/src/model/famix/primitive_type.ts +15 -15
- package/src/lib/famix/src/model/famix/property.ts +54 -54
- package/src/lib/famix/src/model/famix/reference.ts +42 -42
- package/src/lib/famix/src/model/famix/scoping_entity.ts +34 -31
- package/src/lib/famix/src/model/famix/script_entity.ts +38 -38
- package/src/lib/famix/src/model/famix/source_anchor.ts +31 -31
- package/src/lib/famix/src/model/famix/source_language.ts +31 -31
- package/src/lib/famix/src/model/famix/sourced_entity.ts +70 -70
- package/src/lib/famix/src/model/famix/structural_entity.ts +44 -44
- package/src/lib/famix/src/model/famix/text_anchor.ts +49 -49
- package/src/lib/famix/src/model/famix/type.ts +88 -88
- package/src/lib/famix/src/model/famix/type_parameter.ts +33 -33
- package/src/lib/famix/src/model/famix/variable.ts +28 -28
- package/src/lib/famix/tsconfig.json +26 -26
- package/src/lib/famix/tslint.json +14 -14
- package/src/lib/ts-complex/cyclomatic-service.ts +85 -85
- package/src/ts2famix-cli.ts +39 -39
- package/tsconfig.json +69 -69
|
@@ -1,669 +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 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
|
-
}
|
|
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
|
+
}
|