ts2famix 1.0.11 → 1.0.12
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/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 -661
- 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 -555
- 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 -100
- 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
- package/dist/analyze.js +0 -102
- package/dist/analyze_functions/processAccesses.js +0 -47
- package/dist/analyze_functions/processFiles.js +0 -540
- package/dist/analyze_functions/processImportClauses.js +0 -70
- package/dist/analyze_functions/processInheritances.js +0 -73
- package/dist/analyze_functions/processInvocations.js +0 -49
- package/dist/famix2puml.js +0 -125
- package/dist/famix_functions/famix_functions.js +0 -513
- package/dist/famix_functions/famix_functions_associations.js +0 -205
- package/dist/famix_functions/famix_functions_index.js +0 -62
- package/dist/famix_functions/famix_functions_types.js +0 -110
- package/dist/fqn.js +0 -126
- package/dist/fqp_implementation.js +0 -73
- package/dist/lib/famix/src/famix_JSON_exporter.js +0 -54
- package/dist/lib/famix/src/famix_base_element.js +0 -13
- package/dist/lib/famix/src/famix_repository.js +0 -187
- package/dist/lib/famix/src/index.js +0 -30
- package/dist/lib/famix/src/model/famix/access.js +0 -39
- package/dist/lib/famix/src/model/famix/accessor.js +0 -16
- package/dist/lib/famix/src/model/famix/alias.js +0 -32
- package/dist/lib/famix/src/model/famix/association.js +0 -36
- package/dist/lib/famix/src/model/famix/behavioral_entity.js +0 -81
- package/dist/lib/famix/src/model/famix/c_source_language.js +0 -16
- package/dist/lib/famix/src/model/famix/class.js +0 -70
- package/dist/lib/famix/src/model/famix/comment.js +0 -38
- package/dist/lib/famix/src/model/famix/container_entity.js +0 -125
- package/dist/lib/famix/src/model/famix/custom_source_language.js +0 -23
- package/dist/lib/famix/src/model/famix/decorator.js +0 -31
- package/dist/lib/famix/src/model/famix/entity.js +0 -16
- package/dist/lib/famix/src/model/famix/enum.js +0 -30
- package/dist/lib/famix/src/model/famix/enum_value.js +0 -24
- package/dist/lib/famix/src/model/famix/function.js +0 -16
- package/dist/lib/famix/src/model/famix/implicit_variable.js +0 -16
- package/dist/lib/famix/src/model/famix/import_clause.js +0 -39
- package/dist/lib/famix/src/model/famix/index.js +0 -87
- package/dist/lib/famix/src/model/famix/indexed_file_anchor.js +0 -37
- package/dist/lib/famix/src/model/famix/inheritance.js +0 -32
- package/dist/lib/famix/src/model/famix/interface.js +0 -63
- package/dist/lib/famix/src/model/famix/invocation.js +0 -53
- package/dist/lib/famix/src/model/famix/method.js +0 -66
- package/dist/lib/famix/src/model/famix/module.js +0 -30
- package/dist/lib/famix/src/model/famix/named_entity.js +0 -77
- package/dist/lib/famix/src/model/famix/namespace.js +0 -24
- package/dist/lib/famix/src/model/famix/parameter.js +0 -24
- package/dist/lib/famix/src/model/famix/parameterizable_class.js +0 -30
- package/dist/lib/famix/src/model/famix/parameterizable_interface.js +0 -30
- package/dist/lib/famix/src/model/famix/parameterized_type.js +0 -36
- package/dist/lib/famix/src/model/famix/primitive_type.js +0 -16
- package/dist/lib/famix/src/model/famix/property.js +0 -44
- package/dist/lib/famix/src/model/famix/reference.js +0 -32
- package/dist/lib/famix/src/model/famix/scoping_entity.js +0 -30
- package/dist/lib/famix/src/model/famix/script_entity.js +0 -30
- package/dist/lib/famix/src/model/famix/source_anchor.js +0 -26
- package/dist/lib/famix/src/model/famix/source_language.js +0 -30
- package/dist/lib/famix/src/model/famix/sourced_entity.js +0 -55
- package/dist/lib/famix/src/model/famix/structural_entity.js +0 -38
- package/dist/lib/famix/src/model/famix/text_anchor.js +0 -37
- package/dist/lib/famix/src/model/famix/type.js +0 -71
- package/dist/lib/famix/src/model/famix/type_parameter.js +0 -24
- package/dist/lib/famix/src/model/famix/variable.js +0 -23
- package/dist/lib/ts-complex/cyclomatic-service.js +0 -83
- package/dist/ts2famix-cli.js +0 -63
- package/dist/ts2famix-tsconfig.js +0 -53
- package/metrics.ts +0 -23
- package/output.debug.txt +0 -1351
- package/src/fqp_implementation.ts +0 -66
|
@@ -1,215 +1,215 @@
|
|
|
1
|
-
import { ClassDeclaration, ConstructorDeclaration, FunctionDeclaration, Identifier, InterfaceDeclaration, MethodDeclaration, SourceFile, GetAccessorDeclaration, SetAccessorDeclaration, Node, ImportSpecifier, SyntaxKind, FunctionExpression, ExpressionWithTypeArguments } from "ts-morph";
|
|
2
|
-
import * as Famix from "../lib/famix/src/model/famix";
|
|
3
|
-
import { FamixRepository } from "../lib/famix/src/famix_repository";
|
|
4
|
-
import { FQNFunctions } from "../fqn";
|
|
5
|
-
import { FamixFunctionsIndex } from "./famix_functions_index";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* This class is used to build a Famix model for the associations
|
|
9
|
-
*/
|
|
10
|
-
export class FamixFunctionsAssociations {
|
|
11
|
-
|
|
12
|
-
private famixRep: FamixRepository; // The Famix repository
|
|
13
|
-
private FQNFunctions = new FQNFunctions(); // The fully qualified name functions
|
|
14
|
-
private famixClassMap: Map<string, Famix.Class | Famix.ParameterizableClass>; // Maps the class names to their Famix model
|
|
15
|
-
private famixInterfaceMap: Map<string, Famix.Interface | Famix.ParameterizableInterface>; // Maps the interface names to their Famix model
|
|
16
|
-
private famixFunctionsIndex: FamixFunctionsIndex; // FamixFunctionsIndex object, it contains all the functions needed to create Famix index file anchors
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Initializes the FamixFunctionsAssociations object
|
|
20
|
-
* @param famixRep The Famix repository
|
|
21
|
-
* @param fmxClassMap The map of the class names and their Famix model
|
|
22
|
-
* @param fmxInterfaceMap The map of the interface names and their Famix model
|
|
23
|
-
*/
|
|
24
|
-
constructor(famixRep: FamixRepository, fmxClassMap: Map<string, Famix.Class | Famix.ParameterizableClass>, fmxInterfaceMap: Map<string, Famix.Interface | Famix.ParameterizableInterface>) {
|
|
25
|
-
this.famixRep = famixRep;
|
|
26
|
-
this.famixClassMap = fmxClassMap;
|
|
27
|
-
this.famixInterfaceMap = fmxInterfaceMap;
|
|
28
|
-
this.famixFunctionsIndex = new FamixFunctionsIndex(famixRep);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Creates a Famix access
|
|
33
|
-
* @param node A node
|
|
34
|
-
* @param id An id of a parameter, a variable, a property or an enum member
|
|
35
|
-
*/
|
|
36
|
-
public createFamixAccess(node: Identifier, id: number): void {
|
|
37
|
-
const fmxVar = this.famixRep.getFamixEntityById(id) as Famix.StructuralEntity;
|
|
38
|
-
const nodeReferenceAncestor = this.findAncestor(node);
|
|
39
|
-
const ancestorFullyQualifiedName = this.FQNFunctions.getFQN(nodeReferenceAncestor);
|
|
40
|
-
const accessor = this.getFamixEntityByFullyQualifiedName(ancestorFullyQualifiedName) as Famix.ContainerEntity;
|
|
41
|
-
|
|
42
|
-
const fmxAccess = new Famix.Access(this.famixRep);
|
|
43
|
-
fmxAccess.setAccessor(accessor);
|
|
44
|
-
fmxAccess.setVariable(fmxVar);
|
|
45
|
-
|
|
46
|
-
this.famixFunctionsIndex.makeFamixIndexFileAnchor(node, fmxAccess);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Creates a Famix invocation
|
|
51
|
-
* @param node A node
|
|
52
|
-
* @param m A method or a function
|
|
53
|
-
* @param id The id of the method or the function
|
|
54
|
-
*/
|
|
55
|
-
public createFamixInvocation(node: Identifier, m: MethodDeclaration | ConstructorDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | FunctionDeclaration | FunctionExpression, id: number): void {
|
|
56
|
-
const fmxMethodOrFunction = this.getFamixEntityById(id) as Famix.BehavioralEntity;
|
|
57
|
-
const nodeReferenceAncestor = this.findAncestor(node);
|
|
58
|
-
const ancestorFullyQualifiedName = this.FQNFunctions.getFQN(nodeReferenceAncestor);
|
|
59
|
-
const sender = this.getFamixEntityByFullyQualifiedName(ancestorFullyQualifiedName) as Famix.ContainerEntity;
|
|
60
|
-
const receiverFullyQualifiedName = this.FQNFunctions.getFQN(m.getParent());
|
|
61
|
-
const receiver = this.getFamixEntityByFullyQualifiedName(receiverFullyQualifiedName) as Famix.NamedEntity;
|
|
62
|
-
|
|
63
|
-
const fmxInvocation = new Famix.Invocation(this.famixRep);
|
|
64
|
-
fmxInvocation.setSender(sender);
|
|
65
|
-
fmxInvocation.setReceiver(receiver);
|
|
66
|
-
fmxInvocation.addCandidate(fmxMethodOrFunction);
|
|
67
|
-
fmxInvocation.setSignature(fmxMethodOrFunction.getSignature());
|
|
68
|
-
|
|
69
|
-
this.famixFunctionsIndex.makeFamixIndexFileAnchor(node, fmxInvocation);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Creates a Famix inheritance
|
|
74
|
-
* @param cls A class or an interface (subclass)
|
|
75
|
-
* @param inhClass The inherited class or interface (superclass)
|
|
76
|
-
*/
|
|
77
|
-
public createFamixInheritance(cls: ClassDeclaration | InterfaceDeclaration, inhClass: ClassDeclaration | InterfaceDeclaration | ExpressionWithTypeArguments): void {
|
|
78
|
-
const fmxInheritance = new Famix.Inheritance(this.famixRep);
|
|
79
|
-
// const clsName = cls.getName();
|
|
80
|
-
const classFullyQualifiedName = this.FQNFunctions.getFQN(cls);
|
|
81
|
-
console.info(`createFamixInheritance: classFullyQualifiedName: class fqn = ${classFullyQualifiedName}`);
|
|
82
|
-
let subClass: Famix.Class | Famix.Interface;
|
|
83
|
-
if (cls instanceof ClassDeclaration) {
|
|
84
|
-
subClass = this.famixClassMap.get(classFullyQualifiedName);
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
subClass = this.famixInterfaceMap.get(classFullyQualifiedName);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
let inhClassName: string;
|
|
91
|
-
let inhClassFullyQualifiedName: string;
|
|
92
|
-
let superClass: Famix.Class | Famix.Interface;
|
|
93
|
-
if (inhClass instanceof ClassDeclaration || inhClass instanceof InterfaceDeclaration) {
|
|
94
|
-
inhClassName = inhClass.getName();
|
|
95
|
-
inhClassFullyQualifiedName = this.FQNFunctions.getFQN(inhClass);
|
|
96
|
-
if (inhClass instanceof ClassDeclaration) {
|
|
97
|
-
superClass = this.famixClassMap.get(inhClassFullyQualifiedName);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
superClass = this.famixInterfaceMap.get(inhClassFullyQualifiedName);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
// inhClass is an ExpressionWithTypeArguments
|
|
105
|
-
inhClassName = inhClass.getExpression().getText();
|
|
106
|
-
// what is inhClassFullyQualifiedName? TODO
|
|
107
|
-
inhClassFullyQualifiedName = 'Undefined_Scope_from_importer.' + inhClassName;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (superClass === undefined) {
|
|
111
|
-
if (inhClass instanceof ClassDeclaration) {
|
|
112
|
-
superClass = new Famix.Class(this.famixRep);
|
|
113
|
-
this.famixClassMap.set(inhClassFullyQualifiedName, superClass);
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
superClass = new Famix.Interface(this.famixRep);
|
|
117
|
-
this.famixInterfaceMap.set(inhClassFullyQualifiedName, superClass);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
superClass.setName(inhClassName);
|
|
121
|
-
superClass.setFullyQualifiedName(inhClassFullyQualifiedName);
|
|
122
|
-
superClass.setIsStub(true);
|
|
123
|
-
|
|
124
|
-
this.famixFunctionsIndex.makeFamixIndexFileAnchor(inhClass, superClass);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
fmxInheritance.setSubclass(subClass);
|
|
128
|
-
fmxInheritance.setSuperclass(superClass);
|
|
129
|
-
|
|
130
|
-
this.famixFunctionsIndex.makeFamixIndexFileAnchor(null, fmxInheritance);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Creates a Famix import clause
|
|
135
|
-
* @param importer A source file which is a module
|
|
136
|
-
* @param moduleSpecifier The name of the module where the export declaration is
|
|
137
|
-
* @param moduleSpecifierFilePath The path of the module where the export declaration is
|
|
138
|
-
* @param importElement The imported entity
|
|
139
|
-
* @param isInExports A boolean indicating if the imported entity is in the exports
|
|
140
|
-
* @param isDefaultExport A boolean indicating if the imported entity is a default export
|
|
141
|
-
*/
|
|
142
|
-
public createFamixImportClause(importer: SourceFile, moduleSpecifier: string, moduleSpecifierFilePath: string, importElement: ImportSpecifier | Identifier, isInExports: boolean, isDefaultExport: boolean): void {
|
|
143
|
-
const fmxImportClause = new Famix.ImportClause(this.famixRep);
|
|
144
|
-
|
|
145
|
-
let importedEntity: Famix.NamedEntity;
|
|
146
|
-
let importedEntityName: string;
|
|
147
|
-
let pathName = "\"" + moduleSpecifierFilePath + "\".";
|
|
148
|
-
if (importElement instanceof ImportSpecifier) {
|
|
149
|
-
importedEntityName = importElement.getName();
|
|
150
|
-
pathName = pathName + importedEntityName;
|
|
151
|
-
if (isInExports) {
|
|
152
|
-
importedEntity = this.getFamixEntityByFullyQualifiedName(pathName) as Famix.NamedEntity;
|
|
153
|
-
}
|
|
154
|
-
if (importedEntity === undefined) {
|
|
155
|
-
importedEntity = new Famix.NamedEntity(this.famixRep);
|
|
156
|
-
importedEntity.setName(importedEntityName);
|
|
157
|
-
if (!isInExports) {
|
|
158
|
-
importedEntity.setIsStub(true);
|
|
159
|
-
}
|
|
160
|
-
this.famixFunctionsIndex.makeFamixIndexFileAnchor(importElement, importedEntity);
|
|
161
|
-
importedEntity.setFullyQualifiedName(pathName);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
importedEntityName = importElement.getText();
|
|
166
|
-
if (isDefaultExport) {
|
|
167
|
-
pathName = pathName + "defaultExport";
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
pathName = pathName + "namespaceExport";
|
|
171
|
-
}
|
|
172
|
-
importedEntity = new Famix.NamedEntity(this.famixRep);
|
|
173
|
-
importedEntity.setName(importedEntityName);
|
|
174
|
-
this.famixFunctionsIndex.makeFamixIndexFileAnchor(importElement, importedEntity);
|
|
175
|
-
importedEntity.setFullyQualifiedName(pathName);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
const importerFullyQualifiedName = this.FQNFunctions.getFQN(importer);
|
|
179
|
-
const fmxImporter = this.getFamixEntityByFullyQualifiedName(importerFullyQualifiedName) as Famix.Module;
|
|
180
|
-
fmxImportClause.setImporter(fmxImporter);
|
|
181
|
-
fmxImportClause.setImportedEntity(importedEntity);
|
|
182
|
-
fmxImportClause.setModuleSpecifier(moduleSpecifier);
|
|
183
|
-
|
|
184
|
-
this.famixFunctionsIndex.makeFamixIndexFileAnchor(null, fmxImportClause);
|
|
185
|
-
|
|
186
|
-
fmxImporter.addImportClause(fmxImportClause);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Gets a Famix entity by id
|
|
191
|
-
* @param famixId An id of a Famix entity
|
|
192
|
-
* @returns The Famix entity corresponding to the id
|
|
193
|
-
*/
|
|
194
|
-
private getFamixEntityById(famixId: number): Famix.Entity {
|
|
195
|
-
return this.famixRep.getFamixEntityById(famixId) as Famix.Entity;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Gets a Famix entity by fully qualified name
|
|
200
|
-
* @param fullyQualifiedName A fully qualified name
|
|
201
|
-
* @returns The Famix entity corresponding to the fully qualified name
|
|
202
|
-
*/
|
|
203
|
-
private getFamixEntityByFullyQualifiedName(fullyQualifiedName: string): Famix.Entity {
|
|
204
|
-
return this.famixRep.getFamixEntityByFullyQualifiedName(fullyQualifiedName) as Famix.Entity;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Finds the ancestor of a node
|
|
209
|
-
* @param node A node
|
|
210
|
-
* @returns The ancestor of the node
|
|
211
|
-
*/
|
|
212
|
-
private findAncestor(node: Identifier): Node {
|
|
213
|
-
return node.getAncestors().find(a => a.getKind() === SyntaxKind.MethodDeclaration || a.getKind() === SyntaxKind.Constructor || a.getKind() === SyntaxKind.FunctionDeclaration || a.getKind() === SyntaxKind.FunctionExpression || a.getKind() === SyntaxKind.ModuleDeclaration || a.getKind() === SyntaxKind.SourceFile || a.getKindName() === "GetAccessor" || a.getKindName() === "SetAccessor" || a.getKind() === SyntaxKind.ClassDeclaration);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
1
|
+
import { ClassDeclaration, ConstructorDeclaration, FunctionDeclaration, Identifier, InterfaceDeclaration, MethodDeclaration, SourceFile, GetAccessorDeclaration, SetAccessorDeclaration, Node, ImportSpecifier, SyntaxKind, FunctionExpression, ExpressionWithTypeArguments } from "ts-morph";
|
|
2
|
+
import * as Famix from "../lib/famix/src/model/famix";
|
|
3
|
+
import { FamixRepository } from "../lib/famix/src/famix_repository";
|
|
4
|
+
import { FQNFunctions } from "../fqn";
|
|
5
|
+
import { FamixFunctionsIndex } from "./famix_functions_index";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* This class is used to build a Famix model for the associations
|
|
9
|
+
*/
|
|
10
|
+
export class FamixFunctionsAssociations {
|
|
11
|
+
|
|
12
|
+
private famixRep: FamixRepository; // The Famix repository
|
|
13
|
+
private FQNFunctions = new FQNFunctions(); // The fully qualified name functions
|
|
14
|
+
private famixClassMap: Map<string, Famix.Class | Famix.ParameterizableClass>; // Maps the class names to their Famix model
|
|
15
|
+
private famixInterfaceMap: Map<string, Famix.Interface | Famix.ParameterizableInterface>; // Maps the interface names to their Famix model
|
|
16
|
+
private famixFunctionsIndex: FamixFunctionsIndex; // FamixFunctionsIndex object, it contains all the functions needed to create Famix index file anchors
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Initializes the FamixFunctionsAssociations object
|
|
20
|
+
* @param famixRep The Famix repository
|
|
21
|
+
* @param fmxClassMap The map of the class names and their Famix model
|
|
22
|
+
* @param fmxInterfaceMap The map of the interface names and their Famix model
|
|
23
|
+
*/
|
|
24
|
+
constructor(famixRep: FamixRepository, fmxClassMap: Map<string, Famix.Class | Famix.ParameterizableClass>, fmxInterfaceMap: Map<string, Famix.Interface | Famix.ParameterizableInterface>) {
|
|
25
|
+
this.famixRep = famixRep;
|
|
26
|
+
this.famixClassMap = fmxClassMap;
|
|
27
|
+
this.famixInterfaceMap = fmxInterfaceMap;
|
|
28
|
+
this.famixFunctionsIndex = new FamixFunctionsIndex(famixRep);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Creates a Famix access
|
|
33
|
+
* @param node A node
|
|
34
|
+
* @param id An id of a parameter, a variable, a property or an enum member
|
|
35
|
+
*/
|
|
36
|
+
public createFamixAccess(node: Identifier, id: number): void {
|
|
37
|
+
const fmxVar = this.famixRep.getFamixEntityById(id) as Famix.StructuralEntity;
|
|
38
|
+
const nodeReferenceAncestor = this.findAncestor(node);
|
|
39
|
+
const ancestorFullyQualifiedName = this.FQNFunctions.getFQN(nodeReferenceAncestor);
|
|
40
|
+
const accessor = this.getFamixEntityByFullyQualifiedName(ancestorFullyQualifiedName) as Famix.ContainerEntity;
|
|
41
|
+
|
|
42
|
+
const fmxAccess = new Famix.Access(this.famixRep);
|
|
43
|
+
fmxAccess.setAccessor(accessor);
|
|
44
|
+
fmxAccess.setVariable(fmxVar);
|
|
45
|
+
|
|
46
|
+
this.famixFunctionsIndex.makeFamixIndexFileAnchor(node, fmxAccess);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Creates a Famix invocation
|
|
51
|
+
* @param node A node
|
|
52
|
+
* @param m A method or a function
|
|
53
|
+
* @param id The id of the method or the function
|
|
54
|
+
*/
|
|
55
|
+
public createFamixInvocation(node: Identifier, m: MethodDeclaration | ConstructorDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | FunctionDeclaration | FunctionExpression, id: number): void {
|
|
56
|
+
const fmxMethodOrFunction = this.getFamixEntityById(id) as Famix.BehavioralEntity;
|
|
57
|
+
const nodeReferenceAncestor = this.findAncestor(node);
|
|
58
|
+
const ancestorFullyQualifiedName = this.FQNFunctions.getFQN(nodeReferenceAncestor);
|
|
59
|
+
const sender = this.getFamixEntityByFullyQualifiedName(ancestorFullyQualifiedName) as Famix.ContainerEntity;
|
|
60
|
+
const receiverFullyQualifiedName = this.FQNFunctions.getFQN(m.getParent());
|
|
61
|
+
const receiver = this.getFamixEntityByFullyQualifiedName(receiverFullyQualifiedName) as Famix.NamedEntity;
|
|
62
|
+
|
|
63
|
+
const fmxInvocation = new Famix.Invocation(this.famixRep);
|
|
64
|
+
fmxInvocation.setSender(sender);
|
|
65
|
+
fmxInvocation.setReceiver(receiver);
|
|
66
|
+
fmxInvocation.addCandidate(fmxMethodOrFunction);
|
|
67
|
+
fmxInvocation.setSignature(fmxMethodOrFunction.getSignature());
|
|
68
|
+
|
|
69
|
+
this.famixFunctionsIndex.makeFamixIndexFileAnchor(node, fmxInvocation);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Creates a Famix inheritance
|
|
74
|
+
* @param cls A class or an interface (subclass)
|
|
75
|
+
* @param inhClass The inherited class or interface (superclass)
|
|
76
|
+
*/
|
|
77
|
+
public createFamixInheritance(cls: ClassDeclaration | InterfaceDeclaration, inhClass: ClassDeclaration | InterfaceDeclaration | ExpressionWithTypeArguments): void {
|
|
78
|
+
const fmxInheritance = new Famix.Inheritance(this.famixRep);
|
|
79
|
+
// const clsName = cls.getName();
|
|
80
|
+
const classFullyQualifiedName = this.FQNFunctions.getFQN(cls);
|
|
81
|
+
console.info(`createFamixInheritance: classFullyQualifiedName: class fqn = ${classFullyQualifiedName}`);
|
|
82
|
+
let subClass: Famix.Class | Famix.Interface;
|
|
83
|
+
if (cls instanceof ClassDeclaration) {
|
|
84
|
+
subClass = this.famixClassMap.get(classFullyQualifiedName);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
subClass = this.famixInterfaceMap.get(classFullyQualifiedName);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
let inhClassName: string;
|
|
91
|
+
let inhClassFullyQualifiedName: string;
|
|
92
|
+
let superClass: Famix.Class | Famix.Interface;
|
|
93
|
+
if (inhClass instanceof ClassDeclaration || inhClass instanceof InterfaceDeclaration) {
|
|
94
|
+
inhClassName = inhClass.getName();
|
|
95
|
+
inhClassFullyQualifiedName = this.FQNFunctions.getFQN(inhClass);
|
|
96
|
+
if (inhClass instanceof ClassDeclaration) {
|
|
97
|
+
superClass = this.famixClassMap.get(inhClassFullyQualifiedName);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
superClass = this.famixInterfaceMap.get(inhClassFullyQualifiedName);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
// inhClass is an ExpressionWithTypeArguments
|
|
105
|
+
inhClassName = inhClass.getExpression().getText();
|
|
106
|
+
// what is inhClassFullyQualifiedName? TODO
|
|
107
|
+
inhClassFullyQualifiedName = 'Undefined_Scope_from_importer.' + inhClassName;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (superClass === undefined) {
|
|
111
|
+
if (inhClass instanceof ClassDeclaration) {
|
|
112
|
+
superClass = new Famix.Class(this.famixRep);
|
|
113
|
+
this.famixClassMap.set(inhClassFullyQualifiedName, superClass);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
superClass = new Famix.Interface(this.famixRep);
|
|
117
|
+
this.famixInterfaceMap.set(inhClassFullyQualifiedName, superClass);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
superClass.setName(inhClassName);
|
|
121
|
+
superClass.setFullyQualifiedName(inhClassFullyQualifiedName);
|
|
122
|
+
superClass.setIsStub(true);
|
|
123
|
+
|
|
124
|
+
this.famixFunctionsIndex.makeFamixIndexFileAnchor(inhClass, superClass);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
fmxInheritance.setSubclass(subClass);
|
|
128
|
+
fmxInheritance.setSuperclass(superClass);
|
|
129
|
+
|
|
130
|
+
this.famixFunctionsIndex.makeFamixIndexFileAnchor(null, fmxInheritance);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Creates a Famix import clause
|
|
135
|
+
* @param importer A source file which is a module
|
|
136
|
+
* @param moduleSpecifier The name of the module where the export declaration is
|
|
137
|
+
* @param moduleSpecifierFilePath The path of the module where the export declaration is
|
|
138
|
+
* @param importElement The imported entity
|
|
139
|
+
* @param isInExports A boolean indicating if the imported entity is in the exports
|
|
140
|
+
* @param isDefaultExport A boolean indicating if the imported entity is a default export
|
|
141
|
+
*/
|
|
142
|
+
public createFamixImportClause(importer: SourceFile, moduleSpecifier: string, moduleSpecifierFilePath: string, importElement: ImportSpecifier | Identifier, isInExports: boolean, isDefaultExport: boolean): void {
|
|
143
|
+
const fmxImportClause = new Famix.ImportClause(this.famixRep);
|
|
144
|
+
|
|
145
|
+
let importedEntity: Famix.NamedEntity;
|
|
146
|
+
let importedEntityName: string;
|
|
147
|
+
let pathName = "\"" + moduleSpecifierFilePath + "\".";
|
|
148
|
+
if (importElement instanceof ImportSpecifier) {
|
|
149
|
+
importedEntityName = importElement.getName();
|
|
150
|
+
pathName = pathName + importedEntityName;
|
|
151
|
+
if (isInExports) {
|
|
152
|
+
importedEntity = this.getFamixEntityByFullyQualifiedName(pathName) as Famix.NamedEntity;
|
|
153
|
+
}
|
|
154
|
+
if (importedEntity === undefined) {
|
|
155
|
+
importedEntity = new Famix.NamedEntity(this.famixRep);
|
|
156
|
+
importedEntity.setName(importedEntityName);
|
|
157
|
+
if (!isInExports) {
|
|
158
|
+
importedEntity.setIsStub(true);
|
|
159
|
+
}
|
|
160
|
+
this.famixFunctionsIndex.makeFamixIndexFileAnchor(importElement, importedEntity);
|
|
161
|
+
importedEntity.setFullyQualifiedName(pathName);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
importedEntityName = importElement.getText();
|
|
166
|
+
if (isDefaultExport) {
|
|
167
|
+
pathName = pathName + "defaultExport";
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
pathName = pathName + "namespaceExport";
|
|
171
|
+
}
|
|
172
|
+
importedEntity = new Famix.NamedEntity(this.famixRep);
|
|
173
|
+
importedEntity.setName(importedEntityName);
|
|
174
|
+
this.famixFunctionsIndex.makeFamixIndexFileAnchor(importElement, importedEntity);
|
|
175
|
+
importedEntity.setFullyQualifiedName(pathName);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const importerFullyQualifiedName = this.FQNFunctions.getFQN(importer);
|
|
179
|
+
const fmxImporter = this.getFamixEntityByFullyQualifiedName(importerFullyQualifiedName) as Famix.Module;
|
|
180
|
+
fmxImportClause.setImporter(fmxImporter);
|
|
181
|
+
fmxImportClause.setImportedEntity(importedEntity);
|
|
182
|
+
fmxImportClause.setModuleSpecifier(moduleSpecifier);
|
|
183
|
+
|
|
184
|
+
this.famixFunctionsIndex.makeFamixIndexFileAnchor(null, fmxImportClause);
|
|
185
|
+
|
|
186
|
+
fmxImporter.addImportClause(fmxImportClause);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Gets a Famix entity by id
|
|
191
|
+
* @param famixId An id of a Famix entity
|
|
192
|
+
* @returns The Famix entity corresponding to the id
|
|
193
|
+
*/
|
|
194
|
+
private getFamixEntityById(famixId: number): Famix.Entity {
|
|
195
|
+
return this.famixRep.getFamixEntityById(famixId) as Famix.Entity;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Gets a Famix entity by fully qualified name
|
|
200
|
+
* @param fullyQualifiedName A fully qualified name
|
|
201
|
+
* @returns The Famix entity corresponding to the fully qualified name
|
|
202
|
+
*/
|
|
203
|
+
private getFamixEntityByFullyQualifiedName(fullyQualifiedName: string): Famix.Entity {
|
|
204
|
+
return this.famixRep.getFamixEntityByFullyQualifiedName(fullyQualifiedName) as Famix.Entity;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Finds the ancestor of a node
|
|
209
|
+
* @param node A node
|
|
210
|
+
* @returns The ancestor of the node
|
|
211
|
+
*/
|
|
212
|
+
private findAncestor(node: Identifier): Node {
|
|
213
|
+
return node.getAncestors().find(a => a.getKind() === SyntaxKind.MethodDeclaration || a.getKind() === SyntaxKind.Constructor || a.getKind() === SyntaxKind.FunctionDeclaration || a.getKind() === SyntaxKind.FunctionExpression || a.getKind() === SyntaxKind.ModuleDeclaration || a.getKind() === SyntaxKind.SourceFile || a.getKindName() === "GetAccessor" || a.getKindName() === "SetAccessor" || a.getKind() === SyntaxKind.ClassDeclaration);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import { ClassDeclaration, ConstructorDeclaration, FunctionDeclaration, Identifier, InterfaceDeclaration, MethodDeclaration, MethodSignature, ModuleDeclaration, PropertyDeclaration, PropertySignature, SourceFile, TypeParameterDeclaration, VariableDeclaration, ParameterDeclaration, Decorator, GetAccessorDeclaration, SetAccessorDeclaration, ImportSpecifier, CommentRange, EnumDeclaration, EnumMember, TypeAliasDeclaration, FunctionExpression, ExpressionWithTypeArguments } from "ts-morph";
|
|
2
|
-
import * as Famix from "../lib/famix/src/model/famix";
|
|
3
|
-
import { FamixRepository } from "../lib/famix/src/famix_repository";
|
|
4
|
-
import { FQNFunctions } from "../fqn";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* This class is used to build a Famix model for the index file anchors
|
|
8
|
-
*/
|
|
9
|
-
export class FamixFunctionsIndex {
|
|
10
|
-
|
|
11
|
-
private famixRep: FamixRepository; // The Famix repository
|
|
12
|
-
private FQNFunctions = new FQNFunctions(); // The fully qualified name functions
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Initializes the FamixFunctionsIndex object
|
|
16
|
-
* @param famixRep The Famix repository
|
|
17
|
-
*/
|
|
18
|
-
constructor(famixRep: FamixRepository) {
|
|
19
|
-
this.famixRep = famixRep;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Makes a Famix index file anchor
|
|
24
|
-
* @param sourceElement A source element
|
|
25
|
-
* @param famixElement The Famix model of the source element
|
|
26
|
-
*/
|
|
27
|
-
public makeFamixIndexFileAnchor(sourceElement: SourceFile | ModuleDeclaration | ClassDeclaration | InterfaceDeclaration | MethodDeclaration | ConstructorDeclaration | MethodSignature | FunctionDeclaration | FunctionExpression | ParameterDeclaration | VariableDeclaration | PropertyDeclaration | PropertySignature | TypeParameterDeclaration | Identifier | Decorator | GetAccessorDeclaration | SetAccessorDeclaration | ImportSpecifier | CommentRange | EnumDeclaration | EnumMember | TypeAliasDeclaration | ExpressionWithTypeArguments, famixElement: Famix.SourcedEntity): void {
|
|
28
|
-
const fmxIndexFileAnchor = new Famix.IndexedFileAnchor(this.famixRep);
|
|
29
|
-
fmxIndexFileAnchor.setElement(famixElement);
|
|
30
|
-
|
|
31
|
-
if (sourceElement !== null) {
|
|
32
|
-
fmxIndexFileAnchor.setFileName(sourceElement.getSourceFile().getFilePath());
|
|
33
|
-
|
|
34
|
-
if (!(sourceElement instanceof CommentRange)) {
|
|
35
|
-
fmxIndexFileAnchor.setStartPos(sourceElement.getStart());
|
|
36
|
-
fmxIndexFileAnchor.setEndPos(sourceElement.getEnd());
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (!(famixElement instanceof Famix.Association) && !(famixElement instanceof Famix.Comment) && !(sourceElement instanceof CommentRange) && !(sourceElement instanceof Identifier) && !(sourceElement instanceof ImportSpecifier) && !(sourceElement instanceof ExpressionWithTypeArguments)) {
|
|
40
|
-
(famixElement as Famix.NamedEntity).setFullyQualifiedName(this.FQNFunctions.getFQN(sourceElement));
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
1
|
+
import { ClassDeclaration, ConstructorDeclaration, FunctionDeclaration, Identifier, InterfaceDeclaration, MethodDeclaration, MethodSignature, ModuleDeclaration, PropertyDeclaration, PropertySignature, SourceFile, TypeParameterDeclaration, VariableDeclaration, ParameterDeclaration, Decorator, GetAccessorDeclaration, SetAccessorDeclaration, ImportSpecifier, CommentRange, EnumDeclaration, EnumMember, TypeAliasDeclaration, FunctionExpression, ExpressionWithTypeArguments } from "ts-morph";
|
|
2
|
+
import * as Famix from "../lib/famix/src/model/famix";
|
|
3
|
+
import { FamixRepository } from "../lib/famix/src/famix_repository";
|
|
4
|
+
import { FQNFunctions } from "../fqn";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This class is used to build a Famix model for the index file anchors
|
|
8
|
+
*/
|
|
9
|
+
export class FamixFunctionsIndex {
|
|
10
|
+
|
|
11
|
+
private famixRep: FamixRepository; // The Famix repository
|
|
12
|
+
private FQNFunctions = new FQNFunctions(); // The fully qualified name functions
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Initializes the FamixFunctionsIndex object
|
|
16
|
+
* @param famixRep The Famix repository
|
|
17
|
+
*/
|
|
18
|
+
constructor(famixRep: FamixRepository) {
|
|
19
|
+
this.famixRep = famixRep;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Makes a Famix index file anchor
|
|
24
|
+
* @param sourceElement A source element
|
|
25
|
+
* @param famixElement The Famix model of the source element
|
|
26
|
+
*/
|
|
27
|
+
public makeFamixIndexFileAnchor(sourceElement: SourceFile | ModuleDeclaration | ClassDeclaration | InterfaceDeclaration | MethodDeclaration | ConstructorDeclaration | MethodSignature | FunctionDeclaration | FunctionExpression | ParameterDeclaration | VariableDeclaration | PropertyDeclaration | PropertySignature | TypeParameterDeclaration | Identifier | Decorator | GetAccessorDeclaration | SetAccessorDeclaration | ImportSpecifier | CommentRange | EnumDeclaration | EnumMember | TypeAliasDeclaration | ExpressionWithTypeArguments, famixElement: Famix.SourcedEntity): void {
|
|
28
|
+
const fmxIndexFileAnchor = new Famix.IndexedFileAnchor(this.famixRep);
|
|
29
|
+
fmxIndexFileAnchor.setElement(famixElement);
|
|
30
|
+
|
|
31
|
+
if (sourceElement !== null) {
|
|
32
|
+
fmxIndexFileAnchor.setFileName(sourceElement.getSourceFile().getFilePath());
|
|
33
|
+
|
|
34
|
+
if (!(sourceElement instanceof CommentRange)) {
|
|
35
|
+
fmxIndexFileAnchor.setStartPos(sourceElement.getStart());
|
|
36
|
+
fmxIndexFileAnchor.setEndPos(sourceElement.getEnd());
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!(famixElement instanceof Famix.Association) && !(famixElement instanceof Famix.Comment) && !(sourceElement instanceof CommentRange) && !(sourceElement instanceof Identifier) && !(sourceElement instanceof ImportSpecifier) && !(sourceElement instanceof ExpressionWithTypeArguments)) {
|
|
40
|
+
(famixElement as Famix.NamedEntity).setFullyQualifiedName(this.FQNFunctions.getFQN(sourceElement));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|