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