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