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