ts2famix 2.0.1 → 2.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 +19 -9
- package/dist/analyze_functions/process_functions.js +127 -67
- package/dist/famix_functions/EntityDictionary.js +803 -356
- package/dist/famix_functions/helpers_creation.js +35 -19
- package/dist/fqn.js +384 -18
- package/dist/lib/famix/famix_repository.js +76 -2
- package/dist/lib/famix/index.js +18 -8
- package/dist/refactorer/refactor-getter-setter.js +18 -8
- package/dist/ts2famix-cli-wrapper.js +18 -8
- package/dist/ts2famix-cli.js +18 -8
- package/dist/ts2famix-tsconfig.js +18 -8
- package/doc-uml/famix-typescript-model.puml +29 -17
- package/doc-uml/famix-typescript-model.svg +1 -1
- package/eslint.config.mjs +28 -0
- package/jest.config.json +1 -1
- package/package.json +32 -12
- package/src/analyze.ts +1 -1
- package/src/analyze_functions/process_functions.ts +168 -118
- package/src/famix_functions/EntityDictionary.ts +909 -441
- package/src/famix_functions/helpers_creation.ts +23 -15
- package/src/fqn.ts +450 -50
- package/src/lib/famix/famix_repository.ts +46 -1
- package/tsconfig.json +1 -0
|
@@ -2,6 +2,8 @@ import { FamixBaseElement } from "./famix_base_element";
|
|
|
2
2
|
import { Class, Interface, Variable, Method, ArrowFunction, Function as FamixFunctionEntity, Type, NamedEntity, ScriptEntity, Module, SourceLanguage } from "./model/famix";
|
|
3
3
|
import * as Famix from "./model/famix";
|
|
4
4
|
import { TSMorphObjectType } from "../../famix_functions/EntityDictionary";
|
|
5
|
+
import { logger } from "../../analyze";
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* This class is used to store all Famix elements
|
|
7
9
|
*/
|
|
@@ -56,10 +58,28 @@ export class FamixRepository {
|
|
|
56
58
|
*/
|
|
57
59
|
public getFamixEntityByFullyQualifiedName(fullyQualifiedName: string): FamixBaseElement | undefined {
|
|
58
60
|
const allEntities = Array.from(this.elements.values()).filter(e => e instanceof NamedEntity) as Array<NamedEntity>;
|
|
59
|
-
const entity = allEntities.find(e =>
|
|
61
|
+
const entity = allEntities.find(e =>
|
|
62
|
+
// {console.log(`namedEntity: ${e.fullyQualifiedName}`);
|
|
63
|
+
// return
|
|
64
|
+
e.fullyQualifiedName === fullyQualifiedName
|
|
65
|
+
// }
|
|
66
|
+
);
|
|
60
67
|
return entity;
|
|
61
68
|
}
|
|
62
69
|
|
|
70
|
+
// Method to get Famix access by accessor and variable
|
|
71
|
+
public getFamixAccessByAccessorAndVariable(accessor: Famix.ContainerEntity, variable: Famix.StructuralEntity): Famix.Access | undefined {
|
|
72
|
+
// Iterate through the list of Famix accesses to find the matching one
|
|
73
|
+
for (const access of Array.from(this.elements.values()).filter(e => e instanceof Famix.Access) as Array<Famix.Access>) {
|
|
74
|
+
if (access.accessor === accessor && access.variable === variable) {
|
|
75
|
+
return access;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Return undefined if no matching access is found
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
63
83
|
export(arg0: { format: string; }) {
|
|
64
84
|
if (arg0.format === "json") {
|
|
65
85
|
return this.getJSON();
|
|
@@ -208,6 +228,7 @@ export class FamixRepository {
|
|
|
208
228
|
* @param element A Famix element
|
|
209
229
|
*/
|
|
210
230
|
public addElement(element: FamixBaseElement): void {
|
|
231
|
+
logger.debug(`Adding Famix element ${element.constructor.name} with id ${element.id}`);
|
|
211
232
|
if (element instanceof Class) {
|
|
212
233
|
this.famixClasses.add(element);
|
|
213
234
|
} else if (element instanceof Interface) {
|
|
@@ -226,8 +247,32 @@ export class FamixRepository {
|
|
|
226
247
|
this.elements.add(element);
|
|
227
248
|
element.id = this.idCounter;
|
|
228
249
|
this.idCounter++;
|
|
250
|
+
this.validateFQNs();
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Validates the fully qualified names of all Famix elements
|
|
255
|
+
*/
|
|
256
|
+
private validateFQNs(): void {
|
|
257
|
+
// make sure all elements have unique fully qualified names
|
|
258
|
+
const fqns = new Set<string>();
|
|
259
|
+
for (const element of Array.from(this.elements.values())) {
|
|
260
|
+
// ignore everything that is not a NamedEntity
|
|
261
|
+
if (element instanceof NamedEntity) {
|
|
262
|
+
if (element.fullyQualifiedName && fqns.has(element.fullyQualifiedName)) {
|
|
263
|
+
const theExistingElement = Array.from(this.elements.values()).find(e => (e as NamedEntity).fullyQualifiedName === element.fullyQualifiedName);
|
|
264
|
+
throw new Error(`The fully qualified name ${element.fullyQualifiedName} is not unique.\nIt exists for ${theExistingElement?.getJSON()}`);
|
|
265
|
+
}
|
|
266
|
+
const theName = (element as NamedEntity).fullyQualifiedName;
|
|
267
|
+
if (theName === undefined || theName === "") {
|
|
268
|
+
throw new Error(`The element ${element.constructor.name} with id ${element.id} has no valid fully qualified name`);
|
|
269
|
+
}
|
|
270
|
+
fqns.add(theName);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
229
273
|
}
|
|
230
274
|
|
|
275
|
+
|
|
231
276
|
/**
|
|
232
277
|
* Gets a JSON representation of the repository
|
|
233
278
|
* @returns A JSON representation of the repository
|
package/tsconfig.json
CHANGED
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
/* Experimental Options */
|
|
54
54
|
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
55
55
|
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
56
|
+
"isolatedModules": true
|
|
56
57
|
},
|
|
57
58
|
"include": [
|
|
58
59
|
"src/**/*.ts",
|