ts2famix 1.0.1 → 1.0.4
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 +102 -0
- package/dist/analyze_functions/processAccesses.js +47 -0
- package/dist/analyze_functions/processFiles.js +540 -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 +513 -0
- package/dist/famix_functions/famix_functions_associations.js +205 -0
- package/dist/famix_functions/famix_functions_index.js +62 -0
- package/dist/famix_functions/famix_functions_types.js +110 -0
- package/dist/fqn.js +126 -0
- package/dist/fqp_implementation.js +73 -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 +51 -0
- package/dist/ts2famix-tsconfig.js +53 -0
- package/doc-uml/.gitkeep +0 -0
- package/docs/.gitkeep +0 -0
- package/jest.config.json +10 -0
- package/package.json +1 -1
- package/tsconfig.json +1 -1
- package/.github/workflows/node.js.yml +0 -60
- package/doc-metamodel/skins.include.puml +0 -2
- package/test/abstractClassWithComments.test.ts +0 -58
- package/test/abstracts.test.ts +0 -53
- package/test/access.test.ts +0 -62
- package/test/accesses.test.ts +0 -42
- package/test/accessorsWithDecorators.test.ts +0 -98
- package/test/alias.test.ts +0 -39
- package/test/classExtendsUndefinedClass.test.ts +0 -41
- package/test/classImplementsUndefinedInterface.test.ts +0 -45
- package/test/classWithDecorators.test.ts +0 -65
- package/test/entities.test.ts +0 -232
- package/test/entities_json.test.ts +0 -48
- package/test/enum.test.ts +0 -55
- package/test/functionReturnsFunction.test.ts +0 -53
- package/test/functionWithParameters.test.ts +0 -38
- package/test/functionWithVariables.test.ts +0 -64
- package/test/functions.test.ts +0 -23
- package/test/functionsInFunction.test.ts +0 -40
- package/test/functionsInMethod.test.ts +0 -42
- package/test/genericClass.test.ts +0 -42
- package/test/genericClassInheritsInterface.test.ts +0 -47
- package/test/genericInterface.test.ts +0 -38
- package/test/genericMethod.test.ts +0 -65
- package/test/genericWithInvocation.test.ts +0 -71
- package/test/generics.test.ts +0 -68
- package/test/inheritance.test.ts +0 -50
- package/test/interfaceInheritsInterface.test.ts +0 -40
- package/test/interfaceInheritsUndefinedInterface.test.ts +0 -41
- package/test/invocation.test.ts +0 -94
- package/test/invocationWithFunction.test.ts +0 -42
- package/test/invocationWithVariable.test.ts +0 -46
- package/test/invocation_json.test.ts +0 -63
- package/test/invocations.test.ts +0 -131
- package/test/jsDoc.test.ts +0 -31
- package/test/methodWithDecorator.test.ts +0 -44
- package/test/methods.test.ts +0 -42
- package/test/metrics.test.ts +0 -51
- package/test/module.test.ts +0 -71
- package/test/namespaces.test.ts +0 -54
- package/test/namespacesAndClasses.test.ts +0 -66
- package/test/parameterWithDecorators.test.ts +0 -54
- package/test/propertyWithDecorators.test.ts +0 -80
- package/test/sample.test.ts +0 -13
- package/test/simpleFunction.test.ts +0 -32
- package/test/simpleTest.test.ts +0 -18
- package/test/simpleTest2.test.ts +0 -36
- package/test/types.test.ts +0 -58
- package/test_src/sample.ts +0 -103
- package/test_src/sampleForModule.ts +0 -10
- package/test_src/sampleForModule2.ts +0 -7
- package/test_src/sampleForModule3.ts +0 -2
- /package/{jest.config.ts → jest.config-old.ts} +0 -0
|
@@ -0,0 +1,205 @@
|
|
|
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.FamixFunctionsAssociations = void 0;
|
|
27
|
+
const ts_morph_1 = require("ts-morph");
|
|
28
|
+
const Famix = __importStar(require("../lib/famix/src/model/famix"));
|
|
29
|
+
const fqn_1 = require("../fqn");
|
|
30
|
+
const famix_functions_index_1 = require("./famix_functions_index");
|
|
31
|
+
/**
|
|
32
|
+
* This class is used to build a Famix model for the associations
|
|
33
|
+
*/
|
|
34
|
+
class FamixFunctionsAssociations {
|
|
35
|
+
/**
|
|
36
|
+
* Initializes the FamixFunctionsAssociations object
|
|
37
|
+
* @param famixRep The Famix repository
|
|
38
|
+
* @param fmxClasses The map of the class names and their Famix model
|
|
39
|
+
* @param fmxInterfaces The map of the interface names and their Famix model
|
|
40
|
+
*/
|
|
41
|
+
constructor(famixRep, fmxClasses, fmxInterfaces) {
|
|
42
|
+
this.FQNFunctions = new fqn_1.FQNFunctions(); // The fully qualified name functions
|
|
43
|
+
this.famixRep = famixRep;
|
|
44
|
+
this.famixClasses = fmxClasses;
|
|
45
|
+
this.famixInterfaces = fmxInterfaces;
|
|
46
|
+
this.famixFunctionsIndex = new famix_functions_index_1.FamixFunctionsIndex(famixRep);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Creates a Famix access
|
|
50
|
+
* @param node A node
|
|
51
|
+
* @param id An id of a parameter, a variable, a property or an enum member
|
|
52
|
+
*/
|
|
53
|
+
createFamixAccess(node, id) {
|
|
54
|
+
const fmxVar = this.famixRep.getFamixEntityById(id);
|
|
55
|
+
const nodeReferenceAncestor = this.findAncestor(node);
|
|
56
|
+
const ancestorFullyQualifiedName = this.FQNFunctions.getFQN(nodeReferenceAncestor);
|
|
57
|
+
const accessor = this.getFamixEntityByFullyQualifiedName(ancestorFullyQualifiedName);
|
|
58
|
+
const fmxAccess = new Famix.Access(this.famixRep);
|
|
59
|
+
fmxAccess.setAccessor(accessor);
|
|
60
|
+
fmxAccess.setVariable(fmxVar);
|
|
61
|
+
this.famixFunctionsIndex.makeFamixIndexFileAnchor(node, fmxAccess);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Creates a Famix invocation
|
|
65
|
+
* @param node A node
|
|
66
|
+
* @param m A method or a function
|
|
67
|
+
* @param id The id of the method or the function
|
|
68
|
+
*/
|
|
69
|
+
createFamixInvocation(node, m, id) {
|
|
70
|
+
const fmxMethodOrFunction = this.getFamixEntityById(id);
|
|
71
|
+
const nodeReferenceAncestor = this.findAncestor(node);
|
|
72
|
+
const ancestorFullyQualifiedName = this.FQNFunctions.getFQN(nodeReferenceAncestor);
|
|
73
|
+
const sender = this.getFamixEntityByFullyQualifiedName(ancestorFullyQualifiedName);
|
|
74
|
+
const receiverFullyQualifiedName = this.FQNFunctions.getFQN(m.getParent());
|
|
75
|
+
const receiver = this.getFamixEntityByFullyQualifiedName(receiverFullyQualifiedName);
|
|
76
|
+
const fmxInvocation = new Famix.Invocation(this.famixRep);
|
|
77
|
+
fmxInvocation.setSender(sender);
|
|
78
|
+
fmxInvocation.setReceiver(receiver);
|
|
79
|
+
fmxInvocation.addCandidate(fmxMethodOrFunction);
|
|
80
|
+
fmxInvocation.setSignature(fmxMethodOrFunction.getSignature());
|
|
81
|
+
this.famixFunctionsIndex.makeFamixIndexFileAnchor(node, fmxInvocation);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Creates a Famix inheritance
|
|
85
|
+
* @param cls A class or an interface (subclass)
|
|
86
|
+
* @param inhClass The inherited class or interface (superclass)
|
|
87
|
+
*/
|
|
88
|
+
createFamixInheritance(cls, inhClass) {
|
|
89
|
+
const fmxInheritance = new Famix.Inheritance(this.famixRep);
|
|
90
|
+
const clsName = cls.getName();
|
|
91
|
+
let subClass;
|
|
92
|
+
if (cls instanceof ts_morph_1.ClassDeclaration) {
|
|
93
|
+
subClass = this.famixClasses.get(clsName);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
subClass = this.famixInterfaces.get(clsName);
|
|
97
|
+
}
|
|
98
|
+
let inhClassName;
|
|
99
|
+
let superClass;
|
|
100
|
+
if (inhClass instanceof ts_morph_1.ClassDeclaration || inhClass instanceof ts_morph_1.InterfaceDeclaration) {
|
|
101
|
+
inhClassName = inhClass.getName();
|
|
102
|
+
if (inhClass instanceof ts_morph_1.ClassDeclaration) {
|
|
103
|
+
superClass = this.famixClasses.get(inhClassName);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
superClass = this.famixInterfaces.get(inhClassName);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
inhClassName = inhClass.getExpression().getText();
|
|
111
|
+
}
|
|
112
|
+
if (superClass === undefined) {
|
|
113
|
+
if (inhClass instanceof ts_morph_1.ClassDeclaration) {
|
|
114
|
+
superClass = new Famix.Class(this.famixRep);
|
|
115
|
+
this.famixClasses.set(inhClassName, superClass);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
superClass = new Famix.Interface(this.famixRep);
|
|
119
|
+
this.famixInterfaces.set(inhClassName, superClass);
|
|
120
|
+
}
|
|
121
|
+
superClass.setName(inhClassName);
|
|
122
|
+
superClass.setIsStub(true);
|
|
123
|
+
this.famixFunctionsIndex.makeFamixIndexFileAnchor(inhClass, superClass);
|
|
124
|
+
}
|
|
125
|
+
fmxInheritance.setSubclass(subClass);
|
|
126
|
+
fmxInheritance.setSuperclass(superClass);
|
|
127
|
+
this.famixFunctionsIndex.makeFamixIndexFileAnchor(null, fmxInheritance);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Creates a Famix import clause
|
|
131
|
+
* @param importer A source file which is a module
|
|
132
|
+
* @param moduleSpecifier The name of the module where the export declaration is
|
|
133
|
+
* @param moduleSpecifierFilePath The path of the module where the export declaration is
|
|
134
|
+
* @param importElement The imported entity
|
|
135
|
+
* @param isInExports A boolean indicating if the imported entity is in the exports
|
|
136
|
+
* @param isDefaultExport A boolean indicating if the imported entity is a default export
|
|
137
|
+
*/
|
|
138
|
+
createFamixImportClause(importer, moduleSpecifier, moduleSpecifierFilePath, importElement, isInExports, isDefaultExport) {
|
|
139
|
+
const fmxImportClause = new Famix.ImportClause(this.famixRep);
|
|
140
|
+
let importedEntity;
|
|
141
|
+
let importedEntityName;
|
|
142
|
+
let pathName = "\"" + moduleSpecifierFilePath + "\".";
|
|
143
|
+
if (importElement instanceof ts_morph_1.ImportSpecifier) {
|
|
144
|
+
importedEntityName = importElement.getName();
|
|
145
|
+
pathName = pathName + importedEntityName;
|
|
146
|
+
if (isInExports) {
|
|
147
|
+
importedEntity = this.getFamixEntityByFullyQualifiedName(pathName);
|
|
148
|
+
}
|
|
149
|
+
if (importedEntity === undefined) {
|
|
150
|
+
importedEntity = new Famix.NamedEntity(this.famixRep);
|
|
151
|
+
importedEntity.setName(importedEntityName);
|
|
152
|
+
if (!isInExports) {
|
|
153
|
+
importedEntity.setIsStub(true);
|
|
154
|
+
}
|
|
155
|
+
this.famixFunctionsIndex.makeFamixIndexFileAnchor(importElement, importedEntity);
|
|
156
|
+
importedEntity.setFullyQualifiedName(pathName);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
importedEntityName = importElement.getText();
|
|
161
|
+
if (isDefaultExport) {
|
|
162
|
+
pathName = pathName + "defaultExport";
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
pathName = pathName + "namespaceExport";
|
|
166
|
+
}
|
|
167
|
+
importedEntity = new Famix.NamedEntity(this.famixRep);
|
|
168
|
+
importedEntity.setName(importedEntityName);
|
|
169
|
+
this.famixFunctionsIndex.makeFamixIndexFileAnchor(importElement, importedEntity);
|
|
170
|
+
importedEntity.setFullyQualifiedName(pathName);
|
|
171
|
+
}
|
|
172
|
+
const importerFullyQualifiedName = this.FQNFunctions.getFQN(importer);
|
|
173
|
+
const fmxImporter = this.getFamixEntityByFullyQualifiedName(importerFullyQualifiedName);
|
|
174
|
+
fmxImportClause.setImporter(fmxImporter);
|
|
175
|
+
fmxImportClause.setImportedEntity(importedEntity);
|
|
176
|
+
fmxImportClause.setModuleSpecifier(moduleSpecifier);
|
|
177
|
+
this.famixFunctionsIndex.makeFamixIndexFileAnchor(null, fmxImportClause);
|
|
178
|
+
fmxImporter.addImportClause(fmxImportClause);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Gets a Famix entity by id
|
|
182
|
+
* @param famixId An id of a Famix entity
|
|
183
|
+
* @returns The Famix entity corresponding to the id
|
|
184
|
+
*/
|
|
185
|
+
getFamixEntityById(famixId) {
|
|
186
|
+
return this.famixRep.getFamixEntityById(famixId);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Gets a Famix entity by fully qualified name
|
|
190
|
+
* @param fullyQualifiedName A fully qualified name
|
|
191
|
+
* @returns The Famix entity corresponding to the fully qualified name
|
|
192
|
+
*/
|
|
193
|
+
getFamixEntityByFullyQualifiedName(fullyQualifiedName) {
|
|
194
|
+
return this.famixRep.getFamixEntityByFullyQualifiedName(fullyQualifiedName);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Finds the ancestor of a node
|
|
198
|
+
* @param node A node
|
|
199
|
+
* @returns The ancestor of the node
|
|
200
|
+
*/
|
|
201
|
+
findAncestor(node) {
|
|
202
|
+
return node.getAncestors().find(a => a.getKind() === ts_morph_1.SyntaxKind.MethodDeclaration || a.getKind() === ts_morph_1.SyntaxKind.Constructor || a.getKind() === ts_morph_1.SyntaxKind.FunctionDeclaration || a.getKind() === ts_morph_1.SyntaxKind.FunctionExpression || a.getKind() === ts_morph_1.SyntaxKind.ModuleDeclaration || a.getKind() === ts_morph_1.SyntaxKind.SourceFile || a.getKindName() === "GetAccessor" || a.getKindName() === "SetAccessor" || a.getKind() === ts_morph_1.SyntaxKind.ClassDeclaration);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
exports.FamixFunctionsAssociations = FamixFunctionsAssociations;
|
|
@@ -0,0 +1,62 @@
|
|
|
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.FamixFunctionsIndex = void 0;
|
|
27
|
+
const ts_morph_1 = require("ts-morph");
|
|
28
|
+
const Famix = __importStar(require("../lib/famix/src/model/famix"));
|
|
29
|
+
const fqn_1 = require("../fqn");
|
|
30
|
+
/**
|
|
31
|
+
* This class is used to build a Famix model for the index file anchors
|
|
32
|
+
*/
|
|
33
|
+
class FamixFunctionsIndex {
|
|
34
|
+
/**
|
|
35
|
+
* Initializes the FamixFunctionsIndex object
|
|
36
|
+
* @param famixRep The Famix repository
|
|
37
|
+
*/
|
|
38
|
+
constructor(famixRep) {
|
|
39
|
+
this.FQNFunctions = new fqn_1.FQNFunctions(); // The fully qualified name functions
|
|
40
|
+
this.famixRep = famixRep;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Makes a Famix index file anchor
|
|
44
|
+
* @param sourceElement A source element
|
|
45
|
+
* @param famixElement The Famix model of the source element
|
|
46
|
+
*/
|
|
47
|
+
makeFamixIndexFileAnchor(sourceElement, famixElement) {
|
|
48
|
+
const fmxIndexFileAnchor = new Famix.IndexedFileAnchor(this.famixRep);
|
|
49
|
+
fmxIndexFileAnchor.setElement(famixElement);
|
|
50
|
+
if (sourceElement !== null) {
|
|
51
|
+
fmxIndexFileAnchor.setFileName(sourceElement.getSourceFile().getFilePath());
|
|
52
|
+
if (!(sourceElement instanceof ts_morph_1.CommentRange)) {
|
|
53
|
+
fmxIndexFileAnchor.setStartPos(sourceElement.getStart());
|
|
54
|
+
fmxIndexFileAnchor.setEndPos(sourceElement.getEnd());
|
|
55
|
+
}
|
|
56
|
+
if (!(famixElement instanceof Famix.Association) && !(famixElement instanceof Famix.Comment) && !(sourceElement instanceof ts_morph_1.CommentRange) && !(sourceElement instanceof ts_morph_1.Identifier) && !(sourceElement instanceof ts_morph_1.ImportSpecifier) && !(sourceElement instanceof ts_morph_1.ExpressionWithTypeArguments)) {
|
|
57
|
+
famixElement.setFullyQualifiedName(this.FQNFunctions.getFQN(sourceElement));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.FamixFunctionsIndex = FamixFunctionsIndex;
|
|
@@ -0,0 +1,110 @@
|
|
|
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.FamixFunctionsTypes = void 0;
|
|
27
|
+
const ts_morph_1 = require("ts-morph");
|
|
28
|
+
const Famix = __importStar(require("../lib/famix/src/model/famix"));
|
|
29
|
+
const fqn_1 = require("../fqn");
|
|
30
|
+
const famix_functions_index_1 = require("./famix_functions_index");
|
|
31
|
+
/**
|
|
32
|
+
* This class is used to build a Famix model for the types
|
|
33
|
+
*/
|
|
34
|
+
class FamixFunctionsTypes {
|
|
35
|
+
/**
|
|
36
|
+
* Initializes the FamixFunctionsIndex object
|
|
37
|
+
* @param famixRep The Famix repository
|
|
38
|
+
*/
|
|
39
|
+
constructor(famixRep) {
|
|
40
|
+
this.FQNFunctions = new fqn_1.FQNFunctions(); // The fully qualified name functions
|
|
41
|
+
this.fmxTypes = new Map(); // Maps the type names to their Famix model
|
|
42
|
+
this.famixRep = famixRep;
|
|
43
|
+
this.famixFunctionsIndex = new famix_functions_index_1.FamixFunctionsIndex(famixRep);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates or gets a Famix type
|
|
47
|
+
* @param typeName A type name
|
|
48
|
+
* @param element A ts-morph element
|
|
49
|
+
* @returns The Famix model of the type
|
|
50
|
+
*/
|
|
51
|
+
createOrGetFamixType(typeName, element) {
|
|
52
|
+
let fmxType;
|
|
53
|
+
let isPrimitiveType = false;
|
|
54
|
+
let isParameterizedType = false;
|
|
55
|
+
const typeAncestor = this.findTypeAncestor(element);
|
|
56
|
+
const ancestorFullyQualifiedName = this.FQNFunctions.getFQN(typeAncestor);
|
|
57
|
+
const ancestor = this.getFamixEntityByFullyQualifiedName(ancestorFullyQualifiedName);
|
|
58
|
+
if (typeName === "number" || typeName === "string" || typeName === "boolean" || typeName === "bigint" || typeName === "symbol" || typeName === "undefined" || typeName === "null") {
|
|
59
|
+
isPrimitiveType = true;
|
|
60
|
+
}
|
|
61
|
+
if (!isPrimitiveType && typeName.includes("<") && typeName.includes(">") && !(typeName.includes("=>"))) {
|
|
62
|
+
isParameterizedType = true;
|
|
63
|
+
}
|
|
64
|
+
if (!this.fmxTypes.has(typeName)) {
|
|
65
|
+
if (isPrimitiveType) {
|
|
66
|
+
fmxType = new Famix.PrimitiveType(this.famixRep);
|
|
67
|
+
fmxType.setIsStub(true);
|
|
68
|
+
}
|
|
69
|
+
else if (isParameterizedType) {
|
|
70
|
+
fmxType = new Famix.ParameterizedType(this.famixRep);
|
|
71
|
+
const parameterTypeNames = typeName.substring(typeName.indexOf("<") + 1, typeName.indexOf(">")).split(",").map(s => s.trim());
|
|
72
|
+
const baseTypeName = typeName.substring(0, typeName.indexOf("<")).trim();
|
|
73
|
+
parameterTypeNames.forEach(parameterTypeName => {
|
|
74
|
+
const fmxParameterType = this.createOrGetFamixType(parameterTypeName, element);
|
|
75
|
+
fmxType.addArgument(fmxParameterType);
|
|
76
|
+
});
|
|
77
|
+
const fmxBaseType = this.createOrGetFamixType(baseTypeName, element);
|
|
78
|
+
fmxType.setBaseType(fmxBaseType);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
fmxType = new Famix.Type(this.famixRep);
|
|
82
|
+
}
|
|
83
|
+
fmxType.setName(typeName);
|
|
84
|
+
fmxType.setContainer(ancestor);
|
|
85
|
+
this.famixFunctionsIndex.makeFamixIndexFileAnchor(null, fmxType);
|
|
86
|
+
this.fmxTypes.set(typeName, fmxType);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
fmxType = this.fmxTypes.get(typeName);
|
|
90
|
+
}
|
|
91
|
+
return fmxType;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Gets a Famix entity by fully qualified name
|
|
95
|
+
* @param fullyQualifiedName A fully qualified name
|
|
96
|
+
* @returns The Famix entity corresponding to the fully qualified name
|
|
97
|
+
*/
|
|
98
|
+
getFamixEntityByFullyQualifiedName(fullyQualifiedName) {
|
|
99
|
+
return this.famixRep.getFamixEntityByFullyQualifiedName(fullyQualifiedName);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Finds the ancestor of a ts-morph element
|
|
103
|
+
* @param element A ts-morph element
|
|
104
|
+
* @returns The ancestor of the ts-morph element
|
|
105
|
+
*/
|
|
106
|
+
findTypeAncestor(element) {
|
|
107
|
+
return element.getAncestors().find(a => a.getKind() === ts_morph_1.SyntaxKind.MethodDeclaration || a.getKind() === ts_morph_1.SyntaxKind.Constructor || a.getKind() === ts_morph_1.SyntaxKind.MethodSignature || a.getKind() === ts_morph_1.SyntaxKind.FunctionDeclaration || a.getKind() === ts_morph_1.SyntaxKind.FunctionExpression || a.getKind() === ts_morph_1.SyntaxKind.ModuleDeclaration || a.getKind() === ts_morph_1.SyntaxKind.SourceFile || a.getKindName() === "GetAccessor" || a.getKindName() === "SetAccessor" || a.getKind() === ts_morph_1.SyntaxKind.ClassDeclaration || a.getKind() === ts_morph_1.SyntaxKind.InterfaceDeclaration);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.FamixFunctionsTypes = FamixFunctionsTypes;
|
package/dist/fqn.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
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.FQNFunctions = void 0;
|
|
27
|
+
const ts = __importStar(require("ts-morph"));
|
|
28
|
+
/**
|
|
29
|
+
* This class is used to get the fully qualified name of a node
|
|
30
|
+
*/
|
|
31
|
+
class FQNFunctions {
|
|
32
|
+
/**
|
|
33
|
+
* Gets the fully qualified name of a node, if it has one
|
|
34
|
+
* @param node A node
|
|
35
|
+
* @returns The fully qualified name of the node, or undefined if it doesn't have one
|
|
36
|
+
*/
|
|
37
|
+
getFQN(node) {
|
|
38
|
+
if (node instanceof ts.SourceFile) {
|
|
39
|
+
return `"${node.getFilePath()}"`;
|
|
40
|
+
}
|
|
41
|
+
const symbol = node.getSymbol();
|
|
42
|
+
if (!symbol) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
const declarations = symbol.getDeclarations();
|
|
46
|
+
if (!declarations) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
const sourceFile = declarations[0].getSourceFile();
|
|
50
|
+
if (!sourceFile) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
const sourceFilePath = sourceFile.getFilePath();
|
|
54
|
+
const sourceFileDirectory = sourceFilePath.substring(0, sourceFilePath.lastIndexOf("/"));
|
|
55
|
+
const qualifiedNameParts = [];
|
|
56
|
+
const nodeName = this.getNameOfNode(node);
|
|
57
|
+
if (nodeName)
|
|
58
|
+
qualifiedNameParts.push(nodeName);
|
|
59
|
+
const ancestors = node.getAncestors();
|
|
60
|
+
ancestors.forEach(a => {
|
|
61
|
+
const partName = this.getNameOfNode(a);
|
|
62
|
+
if (partName)
|
|
63
|
+
qualifiedNameParts.push(partName);
|
|
64
|
+
});
|
|
65
|
+
if (qualifiedNameParts.length > 0) {
|
|
66
|
+
return `"${sourceFileDirectory}/${qualifiedNameParts.pop()}".${qualifiedNameParts.reverse().join(".")}`;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Gets the name of a node, if it has one
|
|
74
|
+
* @param a A node
|
|
75
|
+
* @returns The name of the node, or an empty string if it doesn't have one
|
|
76
|
+
*/
|
|
77
|
+
getNameOfNode(a) {
|
|
78
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
79
|
+
switch (a.getKind()) {
|
|
80
|
+
case ts.SyntaxKind.SourceFile:
|
|
81
|
+
return (_a = a.asKind(ts.SyntaxKind.SourceFile)) === null || _a === void 0 ? void 0 : _a.getBaseName();
|
|
82
|
+
case ts.SyntaxKind.ModuleDeclaration:
|
|
83
|
+
return (_b = a.asKind(ts.SyntaxKind.ModuleDeclaration)) === null || _b === void 0 ? void 0 : _b.getName();
|
|
84
|
+
case ts.SyntaxKind.ClassDeclaration:
|
|
85
|
+
return (_c = a.asKind(ts.SyntaxKind.ClassDeclaration)) === null || _c === void 0 ? void 0 : _c.getName();
|
|
86
|
+
case ts.SyntaxKind.InterfaceDeclaration:
|
|
87
|
+
return (_d = a.asKind(ts.SyntaxKind.InterfaceDeclaration)) === null || _d === void 0 ? void 0 : _d.getName();
|
|
88
|
+
case ts.SyntaxKind.PropertyDeclaration:
|
|
89
|
+
return (_e = a.asKind(ts.SyntaxKind.PropertyDeclaration)) === null || _e === void 0 ? void 0 : _e.getName();
|
|
90
|
+
case ts.SyntaxKind.PropertySignature:
|
|
91
|
+
return (_f = a.asKind(ts.SyntaxKind.PropertySignature)) === null || _f === void 0 ? void 0 : _f.getName();
|
|
92
|
+
case ts.SyntaxKind.MethodDeclaration:
|
|
93
|
+
return (_g = a.asKind(ts.SyntaxKind.MethodDeclaration)) === null || _g === void 0 ? void 0 : _g.getName();
|
|
94
|
+
case ts.SyntaxKind.MethodSignature:
|
|
95
|
+
return (_h = a.asKind(ts.SyntaxKind.MethodSignature)) === null || _h === void 0 ? void 0 : _h.getName();
|
|
96
|
+
case ts.SyntaxKind.GetAccessor:
|
|
97
|
+
return (_j = a.asKind(ts.SyntaxKind.GetAccessor)) === null || _j === void 0 ? void 0 : _j.getName();
|
|
98
|
+
case ts.SyntaxKind.SetAccessor:
|
|
99
|
+
return (_k = a.asKind(ts.SyntaxKind.SetAccessor)) === null || _k === void 0 ? void 0 : _k.getName();
|
|
100
|
+
case ts.SyntaxKind.FunctionDeclaration:
|
|
101
|
+
return (_l = a.asKind(ts.SyntaxKind.FunctionDeclaration)) === null || _l === void 0 ? void 0 : _l.getName();
|
|
102
|
+
case ts.SyntaxKind.FunctionExpression:
|
|
103
|
+
return ((_m = a.asKind(ts.SyntaxKind.FunctionExpression)) === null || _m === void 0 ? void 0 : _m.getName()) ? (_o = a.asKind(ts.SyntaxKind.FunctionExpression)) === null || _o === void 0 ? void 0 : _o.getName() : "anonymous";
|
|
104
|
+
case ts.SyntaxKind.Parameter:
|
|
105
|
+
return (_p = a.asKind(ts.SyntaxKind.Parameter)) === null || _p === void 0 ? void 0 : _p.getName();
|
|
106
|
+
case ts.SyntaxKind.VariableDeclaration:
|
|
107
|
+
return (_q = a.asKind(ts.SyntaxKind.VariableDeclaration)) === null || _q === void 0 ? void 0 : _q.getName();
|
|
108
|
+
case ts.SyntaxKind.Decorator:
|
|
109
|
+
return "@" + ((_r = a.asKind(ts.SyntaxKind.Decorator)) === null || _r === void 0 ? void 0 : _r.getName());
|
|
110
|
+
case ts.SyntaxKind.TypeParameter:
|
|
111
|
+
return (_s = a.asKind(ts.SyntaxKind.TypeParameter)) === null || _s === void 0 ? void 0 : _s.getName();
|
|
112
|
+
case ts.SyntaxKind.EnumDeclaration:
|
|
113
|
+
return (_t = a.asKind(ts.SyntaxKind.EnumDeclaration)) === null || _t === void 0 ? void 0 : _t.getName();
|
|
114
|
+
case ts.SyntaxKind.EnumMember:
|
|
115
|
+
return (_u = a.asKind(ts.SyntaxKind.EnumMember)) === null || _u === void 0 ? void 0 : _u.getName();
|
|
116
|
+
case ts.SyntaxKind.TypeAliasDeclaration:
|
|
117
|
+
return (_v = a.asKind(ts.SyntaxKind.TypeAliasDeclaration)) === null || _v === void 0 ? void 0 : _v.getName();
|
|
118
|
+
case ts.SyntaxKind.Constructor:
|
|
119
|
+
return "constructor";
|
|
120
|
+
default:
|
|
121
|
+
// ancestor hasn't got a useful name
|
|
122
|
+
return "";
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.FQNFunctions = FQNFunctions;
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
const ts = __importStar(require("typescript"));
|
|
27
|
+
function getFullyQualifiedName(node, checker) {
|
|
28
|
+
// Traverse the lexical hierarchy to construct the fully qualified name.
|
|
29
|
+
function getQualifiedName(node) {
|
|
30
|
+
console.log(`getFullyQualifiedName: ${node}`);
|
|
31
|
+
if (node === undefined) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
console.log(`getFullyQualifiedName kind: ${node.kind}, ${ts.SyntaxKind[node.kind]}`);
|
|
35
|
+
if (ts.isSourceFile(node)) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
else if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name)) {
|
|
39
|
+
const symbol = checker.getSymbolAtLocation(node.name);
|
|
40
|
+
if (symbol) {
|
|
41
|
+
const name = symbol.getName();
|
|
42
|
+
const parentName = getQualifiedName(node.parent);
|
|
43
|
+
return parentName ? `${parentName}.${name}` : name;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return getQualifiedName(node.parent);
|
|
47
|
+
}
|
|
48
|
+
return getQualifiedName(node);
|
|
49
|
+
}
|
|
50
|
+
const sourceFile = ts.createSourceFile("test.ts", "function foo() { const x = 1; }", ts.ScriptTarget.ES2015);
|
|
51
|
+
// create a program instance, which is needed to create a type checker
|
|
52
|
+
const program = ts.createProgram(["test.ts"], {});
|
|
53
|
+
const typeChecker = program.getTypeChecker();
|
|
54
|
+
const statements = sourceFile.statements;
|
|
55
|
+
statements.forEach((statement) => {
|
|
56
|
+
var _a;
|
|
57
|
+
console.log(`statement: ${statement.kind}`);
|
|
58
|
+
if (ts.isFunctionDeclaration(statement)) {
|
|
59
|
+
console.log(`function name: ${(_a = statement.name) === null || _a === void 0 ? void 0 : _a.text}`);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
// find all the identifiers in the source file (don't use ts.createTypeChecker here, make it work for TS 5.1.x)
|
|
63
|
+
const identifiers = [];
|
|
64
|
+
ts.forEachChild(sourceFile, function walk(node) {
|
|
65
|
+
if (ts.isIdentifier(node)) {
|
|
66
|
+
identifiers.push(node);
|
|
67
|
+
}
|
|
68
|
+
ts.forEachChild(node, walk);
|
|
69
|
+
});
|
|
70
|
+
console.log(identifiers.map((identifier) => identifier.text).join(", "));
|
|
71
|
+
// find the fully qualified name of each identifier (don't use ts.createTypeChecker here)
|
|
72
|
+
const fullyQualifiedNames = identifiers.map((identifier) => getFullyQualifiedName(identifier, typeChecker));
|
|
73
|
+
console.log(fullyQualifiedNames.join(", "));
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FamixJSONExporter = void 0;
|
|
4
|
+
const famix_base_element_1 = require("./famix_base_element");
|
|
5
|
+
/**
|
|
6
|
+
* This class is used to export Famix elements to JSON
|
|
7
|
+
*/
|
|
8
|
+
class FamixJSONExporter {
|
|
9
|
+
/**
|
|
10
|
+
* Constructor of the FamixJSONExporter class
|
|
11
|
+
* @param packageClass Name of a Famix class
|
|
12
|
+
* @param element A Famix element to export, this element is an instance of the class named "packageClass"
|
|
13
|
+
*/
|
|
14
|
+
constructor(packageClass, element) {
|
|
15
|
+
this.bufferArray = {}; // A buffer to store the properties of the Famix element
|
|
16
|
+
this.FamixPrefix = "FamixTypeScript"; // Prefix of the Famix element
|
|
17
|
+
this.element = element;
|
|
18
|
+
this.bufferArray["FM3"] = this.FamixPrefix + "." + packageClass;
|
|
19
|
+
this.bufferArray["id"] = this.element.id;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Adds a property to the Famix element
|
|
23
|
+
* @param name Name of the property
|
|
24
|
+
* @param prop A property
|
|
25
|
+
*/
|
|
26
|
+
addProperty(name, prop) {
|
|
27
|
+
if (prop instanceof Set) {
|
|
28
|
+
const valueArray = [];
|
|
29
|
+
for (const value of Array.from(prop.values())) {
|
|
30
|
+
if (value instanceof famix_base_element_1.FamixBaseElement) {
|
|
31
|
+
valueArray.push({ "ref": value.id });
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
valueArray.push(value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
this.bufferArray[name] = valueArray;
|
|
38
|
+
}
|
|
39
|
+
else if (prop instanceof famix_base_element_1.FamixBaseElement) {
|
|
40
|
+
this.bufferArray[name] = { "ref": prop.id };
|
|
41
|
+
}
|
|
42
|
+
else if (prop !== undefined && !(prop instanceof Set)) {
|
|
43
|
+
this.bufferArray[name] = prop;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Gets a JSON representation of the Famix element
|
|
48
|
+
* @returns A JSON representation of the Famix element
|
|
49
|
+
*/
|
|
50
|
+
getJSON() {
|
|
51
|
+
return JSON.stringify(this.bufferArray);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.FamixJSONExporter = FamixJSONExporter;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FamixBaseElement = void 0;
|
|
4
|
+
class FamixBaseElement {
|
|
5
|
+
constructor(repo) {
|
|
6
|
+
repo.addElement(this);
|
|
7
|
+
}
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
// tslint:disable-next-line:no-empty
|
|
10
|
+
addPropertiesToExporter(exporter) {
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.FamixBaseElement = FamixBaseElement;
|