ts2famix 1.0.12 → 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
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "famix",
|
|
3
|
-
"version": "1.0.5",
|
|
4
|
-
"description": "a FAMIX model written typescript",
|
|
5
|
-
"main": "build/index.js",
|
|
6
|
-
"types": "build/index.d.ts",
|
|
7
|
-
"files": ["dist/**/*"],
|
|
8
|
-
"repository": {
|
|
9
|
-
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/pascalerni/famix.git"
|
|
11
|
-
},
|
|
12
|
-
"scripts": {
|
|
13
|
-
"test": "echo \"Error: no test specified\" && exit 0",
|
|
14
|
-
"build" : "tsc",
|
|
15
|
-
"lint": "tslint -p tsconfig.json",
|
|
16
|
-
"prepare": "npm run build",
|
|
17
|
-
"prepublishOnly": "npm test && npm run lint",
|
|
18
|
-
"preversion": "npm run lint",
|
|
19
|
-
"version": "git add -A src",
|
|
20
|
-
"postversion": "git push && git push --tags"
|
|
21
|
-
},
|
|
22
|
-
"author": "Pascal Erni",
|
|
23
|
-
"license": "MIT",
|
|
24
|
-
"devDependencies": {
|
|
25
|
-
"tslint": "^5.20.0",
|
|
26
|
-
"typescript": "^3.6.3"
|
|
27
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "famix",
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"description": "a FAMIX model written typescript",
|
|
5
|
+
"main": "build/index.js",
|
|
6
|
+
"types": "build/index.d.ts",
|
|
7
|
+
"files": ["dist/**/*"],
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/pascalerni/famix.git"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"test": "echo \"Error: no test specified\" && exit 0",
|
|
14
|
+
"build" : "tsc",
|
|
15
|
+
"lint": "tslint -p tsconfig.json",
|
|
16
|
+
"prepare": "npm run build",
|
|
17
|
+
"prepublishOnly": "npm test && npm run lint",
|
|
18
|
+
"preversion": "npm run lint",
|
|
19
|
+
"version": "git add -A src",
|
|
20
|
+
"postversion": "git push && git push --tags"
|
|
21
|
+
},
|
|
22
|
+
"author": "Pascal Erni",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"tslint": "^5.20.0",
|
|
26
|
+
"typescript": "^3.6.3"
|
|
27
|
+
}
|
|
28
28
|
}
|
package/src/lib/famix/readme.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
# FAMIX model in typescript
|
|
2
|
-
|
|
3
|
-
FAMIX is a family of metamodels to represent source code.
|
|
4
|
-
|
|
1
|
+
# FAMIX model in typescript
|
|
2
|
+
|
|
3
|
+
FAMIX is a family of metamodels to represent source code.
|
|
4
|
+
|
|
5
5
|
Learn more about the MSE file format and the FAMIX model https://www.researchgate.net/publication/265428652
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { FamixBaseElement } from "./famix_base_element";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This class is used to export Famix elements to JSON
|
|
5
|
-
*/
|
|
6
|
-
export class FamixJSONExporter {
|
|
7
|
-
|
|
8
|
-
private element: FamixBaseElement; // A Famix element to export
|
|
9
|
-
private bufferArray: any = {}; // A buffer to store the properties of the Famix element
|
|
10
|
-
private FamixPrefix = "FamixTypeScript"; // Prefix of the Famix element
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Constructor of the FamixJSONExporter class
|
|
14
|
-
* @param packageClass Name of a Famix class
|
|
15
|
-
* @param element A Famix element to export, this element is an instance of the class named "packageClass"
|
|
16
|
-
*/
|
|
17
|
-
constructor(packageClass: string, element: FamixBaseElement) {
|
|
18
|
-
this.element = element;
|
|
19
|
-
this.bufferArray["FM3"] = this.FamixPrefix + "." + packageClass;
|
|
20
|
-
this.bufferArray["id"] = this.element.id;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Adds a property to the Famix element
|
|
25
|
-
* @param name Name of the property
|
|
26
|
-
* @param prop A property
|
|
27
|
-
*/
|
|
28
|
-
public addProperty(name: string, prop: unknown): void {
|
|
29
|
-
if (prop instanceof Set) {
|
|
30
|
-
const valueArray: Array<unknown> = [];
|
|
31
|
-
for (const value of Array.from(prop.values())) {
|
|
32
|
-
if (value instanceof FamixBaseElement) {
|
|
33
|
-
valueArray.push({ "ref": value.id });
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
valueArray.push(value);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
this.bufferArray[name] = valueArray;
|
|
40
|
-
}
|
|
41
|
-
else if (prop instanceof FamixBaseElement) {
|
|
42
|
-
this.bufferArray[name] = { "ref": prop.id };
|
|
43
|
-
}
|
|
44
|
-
else if (prop !== undefined && !(prop instanceof Set)) {
|
|
45
|
-
this.bufferArray[name] = prop;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Gets a JSON representation of the Famix element
|
|
51
|
-
* @returns A JSON representation of the Famix element
|
|
52
|
-
*/
|
|
53
|
-
public getJSON(): string {
|
|
54
|
-
return JSON.stringify(this.bufferArray);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
1
|
+
import { FamixBaseElement } from "./famix_base_element";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This class is used to export Famix elements to JSON
|
|
5
|
+
*/
|
|
6
|
+
export class FamixJSONExporter {
|
|
7
|
+
|
|
8
|
+
private element: FamixBaseElement; // A Famix element to export
|
|
9
|
+
private bufferArray: any = {}; // A buffer to store the properties of the Famix element
|
|
10
|
+
private FamixPrefix = "FamixTypeScript"; // Prefix of the Famix element
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Constructor of the FamixJSONExporter class
|
|
14
|
+
* @param packageClass Name of a Famix class
|
|
15
|
+
* @param element A Famix element to export, this element is an instance of the class named "packageClass"
|
|
16
|
+
*/
|
|
17
|
+
constructor(packageClass: string, element: FamixBaseElement) {
|
|
18
|
+
this.element = element;
|
|
19
|
+
this.bufferArray["FM3"] = this.FamixPrefix + "." + packageClass;
|
|
20
|
+
this.bufferArray["id"] = this.element.id;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Adds a property to the Famix element
|
|
25
|
+
* @param name Name of the property
|
|
26
|
+
* @param prop A property
|
|
27
|
+
*/
|
|
28
|
+
public addProperty(name: string, prop: unknown): void {
|
|
29
|
+
if (prop instanceof Set) {
|
|
30
|
+
const valueArray: Array<unknown> = [];
|
|
31
|
+
for (const value of Array.from(prop.values())) {
|
|
32
|
+
if (value instanceof FamixBaseElement) {
|
|
33
|
+
valueArray.push({ "ref": value.id });
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
valueArray.push(value);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
this.bufferArray[name] = valueArray;
|
|
40
|
+
}
|
|
41
|
+
else if (prop instanceof FamixBaseElement) {
|
|
42
|
+
this.bufferArray[name] = { "ref": prop.id };
|
|
43
|
+
}
|
|
44
|
+
else if (prop !== undefined && !(prop instanceof Set)) {
|
|
45
|
+
this.bufferArray[name] = prop;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Gets a JSON representation of the Famix element
|
|
51
|
+
* @returns A JSON representation of the Famix element
|
|
52
|
+
*/
|
|
53
|
+
public getJSON(): string {
|
|
54
|
+
return JSON.stringify(this.bufferArray);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { FamixJSONExporter } from "./famix_JSON_exporter";
|
|
2
|
-
import { FamixRepository } from "./famix_repository";
|
|
3
|
-
|
|
4
|
-
export abstract class FamixBaseElement {
|
|
5
|
-
|
|
6
|
-
public id: number;
|
|
7
|
-
|
|
8
|
-
constructor(repo: FamixRepository) {
|
|
9
|
-
repo.addElement(this);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
public abstract getJSON(): string;
|
|
13
|
-
|
|
14
|
-
// @ts-ignore
|
|
15
|
-
// tslint:disable-next-line:no-empty
|
|
16
|
-
public addPropertiesToExporter(exporter: FamixJSONExporter): void {
|
|
17
|
-
}
|
|
18
|
-
}
|
|
1
|
+
import { FamixJSONExporter } from "./famix_JSON_exporter";
|
|
2
|
+
import { FamixRepository } from "./famix_repository";
|
|
3
|
+
|
|
4
|
+
export abstract class FamixBaseElement {
|
|
5
|
+
|
|
6
|
+
public id: number;
|
|
7
|
+
|
|
8
|
+
constructor(repo: FamixRepository) {
|
|
9
|
+
repo.addElement(this);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public abstract getJSON(): string;
|
|
13
|
+
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
// tslint:disable-next-line:no-empty
|
|
16
|
+
public addPropertiesToExporter(exporter: FamixJSONExporter): void {
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -1,199 +1,199 @@
|
|
|
1
|
-
import { FamixBaseElement } from "./famix_base_element";
|
|
2
|
-
import { Class, Interface, Namespace, Method, Function, Type, NamedEntity, ScriptEntity, Module } from "./model/famix";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* This class is used to store all Famix elements
|
|
6
|
-
*/
|
|
7
|
-
export class FamixRepository {
|
|
8
|
-
|
|
9
|
-
private elements = new Set<FamixBaseElement>(); // All Famix elements
|
|
10
|
-
private famixClasses = new Set<Class>(); // All Famix classes
|
|
11
|
-
private famixInterfaces = new Set<Interface>(); // All Famix interfaces
|
|
12
|
-
private famixNamespaces = new Set<Namespace>(); // All Famix namespaces
|
|
13
|
-
private famixMethods = new Set<Method>(); // All Famix methods
|
|
14
|
-
private famixFunctions = new Set<Function>(); // All Famix functions
|
|
15
|
-
private famixFiles = new Set<ScriptEntity | Module>(); // All Famix files
|
|
16
|
-
private idCounter = 1; // Id counter
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Gets a Famix entity by id
|
|
20
|
-
* @param id An id of a Famix entity
|
|
21
|
-
* @returns The Famix entity corresponding to the id or undefined if it doesn't exist
|
|
22
|
-
*/
|
|
23
|
-
public getFamixEntityById(id: number): FamixBaseElement | undefined {
|
|
24
|
-
const entity = Array.from(this.elements.values()).find(e => e.id === id);
|
|
25
|
-
return entity;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Gets a Famix entity by fully qualified name
|
|
30
|
-
* @param fullyQualifiedName A fully qualified name
|
|
31
|
-
* @returns The Famix entity corresponding to the fully qualified name or undefined if it doesn't exist
|
|
32
|
-
*/
|
|
33
|
-
public getFamixEntityByFullyQualifiedName(fullyQualifiedName: string): FamixBaseElement | undefined {
|
|
34
|
-
const allEntities = Array.from(this.elements.values()).filter(e => e instanceof NamedEntity) as Array<NamedEntity>;
|
|
35
|
-
const entity = allEntities.find(e => e.getFullyQualifiedName() === fullyQualifiedName);
|
|
36
|
-
return entity;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
// Only for tests
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Gets all Famix entities
|
|
44
|
-
* @returns All Famix entities
|
|
45
|
-
*/
|
|
46
|
-
public _getAllEntities(): Set<FamixBaseElement> {
|
|
47
|
-
return new Set(Array.from(this.elements.values()));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Gets all Famix entities of a given type
|
|
52
|
-
* @param theType A type of Famix entity
|
|
53
|
-
* @returns All Famix entities of the given type
|
|
54
|
-
*/
|
|
55
|
-
public _getAllEntitiesWithType(theType: string): Set<FamixBaseElement> {
|
|
56
|
-
return new Set(Array.from(this.elements.values()).filter(e => (e as any).constructor.name === theType));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Gets a Famix class by name
|
|
61
|
-
* @param name A class name
|
|
62
|
-
* @returns The Famix class corresponding to the name or undefined if it doesn't exist
|
|
63
|
-
*/
|
|
64
|
-
public _getFamixClass(name: string): Class | undefined {
|
|
65
|
-
return Array.from(this.famixClasses.values()).find(ns => ns.getName() === name);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Gets a Famix interface by name
|
|
70
|
-
* @param name An interface name
|
|
71
|
-
* @returns The Famix interface corresponding to the name or undefined if it doesn't exist
|
|
72
|
-
*/
|
|
73
|
-
public _getFamixInterface(name: string): Interface | undefined {
|
|
74
|
-
return Array.from(this.famixInterfaces.values()).find(ns => ns.getName() === name);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Gets a Famix method by name
|
|
79
|
-
* @param name A method name
|
|
80
|
-
* @returns The Famix method corresponding to the name or undefined if it doesn't exist
|
|
81
|
-
*/
|
|
82
|
-
public _getFamixMethod(name: string): Method | undefined {
|
|
83
|
-
return Array.from(this.famixMethods.values()).find(ns => ns.getName() === name);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Gets a Famix function by name
|
|
88
|
-
* @param name A function name
|
|
89
|
-
* @returns The Famix function corresponding to the name or undefined if it doesn't exist
|
|
90
|
-
*/
|
|
91
|
-
public _getFamixFunction(name: string): Function | undefined {
|
|
92
|
-
return Array.from(this.famixFunctions.values()).find(ns => ns.getName() === name);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Gets a Famix namespace by name
|
|
97
|
-
* @param name A namespace name
|
|
98
|
-
* @returns The Famix namespace corresponding to the name or undefined if it doesn't exist
|
|
99
|
-
*/
|
|
100
|
-
public _getFamixNamespace(name: string): Namespace | undefined {
|
|
101
|
-
return Array.from(this.famixNamespaces.values()).find(ns => ns.getName() === name);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Gets all Famix namespaces
|
|
106
|
-
* @returns All Famix namespaces
|
|
107
|
-
*/
|
|
108
|
-
public _getFamixNamespaces(): Set<Namespace> {
|
|
109
|
-
return new Set(Array.from(this.famixNamespaces.values()));
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Gets a Famix file by name
|
|
114
|
-
* @param name A file name
|
|
115
|
-
* @returns The Famix file corresponding to the name or undefined if it doesn't exist
|
|
116
|
-
*/
|
|
117
|
-
public _getFamixFile(name: string): ScriptEntity | Module | undefined {
|
|
118
|
-
return Array.from(this.famixFiles.values()).find(ns => ns.getName() === name);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Gets all Famix files
|
|
123
|
-
* @returns All Famix files
|
|
124
|
-
*/
|
|
125
|
-
public _getFamixFiles(): Set<ScriptEntity | Module> {
|
|
126
|
-
return new Set(Array.from(this.famixFiles.values()));
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Gets all method names as a set from a class
|
|
131
|
-
* @param className A class name
|
|
132
|
-
* @returns The set of class "className" method names
|
|
133
|
-
*/
|
|
134
|
-
public _methodNamesAsSetFromClass(className: string): Set<string> {
|
|
135
|
-
const theClass = this._getFamixClass(className) as Class;
|
|
136
|
-
return new Set(Array.from(theClass.getMethods()).map(m => m.getName()));
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Gets all method parents as a set from a class
|
|
141
|
-
* @param className A class name
|
|
142
|
-
* @returns The set of class "className" method parents
|
|
143
|
-
*/
|
|
144
|
-
public _methodParentsAsSetFromClass(className: string): Set<Type> {
|
|
145
|
-
const theClass = this._getFamixClass(className) as Class;
|
|
146
|
-
return new Set(Array.from(theClass.getMethods()).map(m => m.getParentEntity()));
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Gets the map of Famix element ids and their Famix element from a JSON model
|
|
151
|
-
* @param model A JSON model
|
|
152
|
-
* @returns The map of Famix element ids and their Famix element from the JSON model
|
|
153
|
-
*/
|
|
154
|
-
public _initMapFromModel(model: string): Map<number, unknown> {
|
|
155
|
-
const parsedModel: Array<any> = JSON.parse(model);
|
|
156
|
-
const idToElementMap: Map<number, unknown> = new Map();
|
|
157
|
-
parsedModel.forEach(element => {
|
|
158
|
-
idToElementMap.set(element.id, element);
|
|
159
|
-
});
|
|
160
|
-
return idToElementMap;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Adds a Famix element to the repository
|
|
166
|
-
* @param element A Famix element
|
|
167
|
-
*/
|
|
168
|
-
public addElement(element: FamixBaseElement): void {
|
|
169
|
-
if (element instanceof Class) {
|
|
170
|
-
this.famixClasses.add(element);
|
|
171
|
-
} else if (element instanceof Interface) {
|
|
172
|
-
this.famixInterfaces.add(element);
|
|
173
|
-
} else if (element instanceof Namespace) {
|
|
174
|
-
this.famixNamespaces.add(element);
|
|
175
|
-
} else if (element instanceof Method) {
|
|
176
|
-
this.famixMethods.add(element);
|
|
177
|
-
} else if (element instanceof Function) {
|
|
178
|
-
this.famixFunctions.add(element);
|
|
179
|
-
} else if (element instanceof ScriptEntity || element instanceof Module) {
|
|
180
|
-
this.famixFiles.add(element);
|
|
181
|
-
}
|
|
182
|
-
this.elements.add(element);
|
|
183
|
-
element.id = this.idCounter;
|
|
184
|
-
this.idCounter++;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Gets a JSON representation of the repository
|
|
189
|
-
* @returns A JSON representation of the repository
|
|
190
|
-
*/
|
|
191
|
-
public getJSON(): string {
|
|
192
|
-
let ret = "[";
|
|
193
|
-
for (const element of Array.from(this.elements.values())) {
|
|
194
|
-
ret = ret + element.getJSON() + ",";
|
|
195
|
-
}
|
|
196
|
-
ret = ret.substring(0, ret.length - 1);
|
|
197
|
-
return ret + "]";
|
|
198
|
-
}
|
|
199
|
-
}
|
|
1
|
+
import { FamixBaseElement } from "./famix_base_element";
|
|
2
|
+
import { Class, Interface, Namespace, Method, Function, Type, NamedEntity, ScriptEntity, Module } from "./model/famix";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This class is used to store all Famix elements
|
|
6
|
+
*/
|
|
7
|
+
export class FamixRepository {
|
|
8
|
+
|
|
9
|
+
private elements = new Set<FamixBaseElement>(); // All Famix elements
|
|
10
|
+
private famixClasses = new Set<Class>(); // All Famix classes
|
|
11
|
+
private famixInterfaces = new Set<Interface>(); // All Famix interfaces
|
|
12
|
+
private famixNamespaces = new Set<Namespace>(); // All Famix namespaces
|
|
13
|
+
private famixMethods = new Set<Method>(); // All Famix methods
|
|
14
|
+
private famixFunctions = new Set<Function>(); // All Famix functions
|
|
15
|
+
private famixFiles = new Set<ScriptEntity | Module>(); // All Famix files
|
|
16
|
+
private idCounter = 1; // Id counter
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Gets a Famix entity by id
|
|
20
|
+
* @param id An id of a Famix entity
|
|
21
|
+
* @returns The Famix entity corresponding to the id or undefined if it doesn't exist
|
|
22
|
+
*/
|
|
23
|
+
public getFamixEntityById(id: number): FamixBaseElement | undefined {
|
|
24
|
+
const entity = Array.from(this.elements.values()).find(e => e.id === id);
|
|
25
|
+
return entity;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Gets a Famix entity by fully qualified name
|
|
30
|
+
* @param fullyQualifiedName A fully qualified name
|
|
31
|
+
* @returns The Famix entity corresponding to the fully qualified name or undefined if it doesn't exist
|
|
32
|
+
*/
|
|
33
|
+
public getFamixEntityByFullyQualifiedName(fullyQualifiedName: string): FamixBaseElement | undefined {
|
|
34
|
+
const allEntities = Array.from(this.elements.values()).filter(e => e instanceof NamedEntity) as Array<NamedEntity>;
|
|
35
|
+
const entity = allEntities.find(e => e.getFullyQualifiedName() === fullyQualifiedName);
|
|
36
|
+
return entity;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
// Only for tests
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Gets all Famix entities
|
|
44
|
+
* @returns All Famix entities
|
|
45
|
+
*/
|
|
46
|
+
public _getAllEntities(): Set<FamixBaseElement> {
|
|
47
|
+
return new Set(Array.from(this.elements.values()));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Gets all Famix entities of a given type
|
|
52
|
+
* @param theType A type of Famix entity
|
|
53
|
+
* @returns All Famix entities of the given type
|
|
54
|
+
*/
|
|
55
|
+
public _getAllEntitiesWithType(theType: string): Set<FamixBaseElement> {
|
|
56
|
+
return new Set(Array.from(this.elements.values()).filter(e => (e as any).constructor.name === theType));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Gets a Famix class by name
|
|
61
|
+
* @param name A class name
|
|
62
|
+
* @returns The Famix class corresponding to the name or undefined if it doesn't exist
|
|
63
|
+
*/
|
|
64
|
+
public _getFamixClass(name: string): Class | undefined {
|
|
65
|
+
return Array.from(this.famixClasses.values()).find(ns => ns.getName() === name);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Gets a Famix interface by name
|
|
70
|
+
* @param name An interface name
|
|
71
|
+
* @returns The Famix interface corresponding to the name or undefined if it doesn't exist
|
|
72
|
+
*/
|
|
73
|
+
public _getFamixInterface(name: string): Interface | undefined {
|
|
74
|
+
return Array.from(this.famixInterfaces.values()).find(ns => ns.getName() === name);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Gets a Famix method by name
|
|
79
|
+
* @param name A method name
|
|
80
|
+
* @returns The Famix method corresponding to the name or undefined if it doesn't exist
|
|
81
|
+
*/
|
|
82
|
+
public _getFamixMethod(name: string): Method | undefined {
|
|
83
|
+
return Array.from(this.famixMethods.values()).find(ns => ns.getName() === name);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Gets a Famix function by name
|
|
88
|
+
* @param name A function name
|
|
89
|
+
* @returns The Famix function corresponding to the name or undefined if it doesn't exist
|
|
90
|
+
*/
|
|
91
|
+
public _getFamixFunction(name: string): Function | undefined {
|
|
92
|
+
return Array.from(this.famixFunctions.values()).find(ns => ns.getName() === name);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Gets a Famix namespace by name
|
|
97
|
+
* @param name A namespace name
|
|
98
|
+
* @returns The Famix namespace corresponding to the name or undefined if it doesn't exist
|
|
99
|
+
*/
|
|
100
|
+
public _getFamixNamespace(name: string): Namespace | undefined {
|
|
101
|
+
return Array.from(this.famixNamespaces.values()).find(ns => ns.getName() === name);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Gets all Famix namespaces
|
|
106
|
+
* @returns All Famix namespaces
|
|
107
|
+
*/
|
|
108
|
+
public _getFamixNamespaces(): Set<Namespace> {
|
|
109
|
+
return new Set(Array.from(this.famixNamespaces.values()));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Gets a Famix file by name
|
|
114
|
+
* @param name A file name
|
|
115
|
+
* @returns The Famix file corresponding to the name or undefined if it doesn't exist
|
|
116
|
+
*/
|
|
117
|
+
public _getFamixFile(name: string): ScriptEntity | Module | undefined {
|
|
118
|
+
return Array.from(this.famixFiles.values()).find(ns => ns.getName() === name);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Gets all Famix files
|
|
123
|
+
* @returns All Famix files
|
|
124
|
+
*/
|
|
125
|
+
public _getFamixFiles(): Set<ScriptEntity | Module> {
|
|
126
|
+
return new Set(Array.from(this.famixFiles.values()));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Gets all method names as a set from a class
|
|
131
|
+
* @param className A class name
|
|
132
|
+
* @returns The set of class "className" method names
|
|
133
|
+
*/
|
|
134
|
+
public _methodNamesAsSetFromClass(className: string): Set<string> {
|
|
135
|
+
const theClass = this._getFamixClass(className) as Class;
|
|
136
|
+
return new Set(Array.from(theClass.getMethods()).map(m => m.getName()));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Gets all method parents as a set from a class
|
|
141
|
+
* @param className A class name
|
|
142
|
+
* @returns The set of class "className" method parents
|
|
143
|
+
*/
|
|
144
|
+
public _methodParentsAsSetFromClass(className: string): Set<Type> {
|
|
145
|
+
const theClass = this._getFamixClass(className) as Class;
|
|
146
|
+
return new Set(Array.from(theClass.getMethods()).map(m => m.getParentEntity()));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Gets the map of Famix element ids and their Famix element from a JSON model
|
|
151
|
+
* @param model A JSON model
|
|
152
|
+
* @returns The map of Famix element ids and their Famix element from the JSON model
|
|
153
|
+
*/
|
|
154
|
+
public _initMapFromModel(model: string): Map<number, unknown> {
|
|
155
|
+
const parsedModel: Array<any> = JSON.parse(model);
|
|
156
|
+
const idToElementMap: Map<number, unknown> = new Map();
|
|
157
|
+
parsedModel.forEach(element => {
|
|
158
|
+
idToElementMap.set(element.id, element);
|
|
159
|
+
});
|
|
160
|
+
return idToElementMap;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Adds a Famix element to the repository
|
|
166
|
+
* @param element A Famix element
|
|
167
|
+
*/
|
|
168
|
+
public addElement(element: FamixBaseElement): void {
|
|
169
|
+
if (element instanceof Class) {
|
|
170
|
+
this.famixClasses.add(element);
|
|
171
|
+
} else if (element instanceof Interface) {
|
|
172
|
+
this.famixInterfaces.add(element);
|
|
173
|
+
} else if (element instanceof Namespace) {
|
|
174
|
+
this.famixNamespaces.add(element);
|
|
175
|
+
} else if (element instanceof Method) {
|
|
176
|
+
this.famixMethods.add(element);
|
|
177
|
+
} else if (element instanceof Function) {
|
|
178
|
+
this.famixFunctions.add(element);
|
|
179
|
+
} else if (element instanceof ScriptEntity || element instanceof Module) {
|
|
180
|
+
this.famixFiles.add(element);
|
|
181
|
+
}
|
|
182
|
+
this.elements.add(element);
|
|
183
|
+
element.id = this.idCounter;
|
|
184
|
+
this.idCounter++;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Gets a JSON representation of the repository
|
|
189
|
+
* @returns A JSON representation of the repository
|
|
190
|
+
*/
|
|
191
|
+
public getJSON(): string {
|
|
192
|
+
let ret = "[";
|
|
193
|
+
for (const element of Array.from(this.elements.values())) {
|
|
194
|
+
ret = ret + element.getJSON() + ",";
|
|
195
|
+
}
|
|
196
|
+
ret = ret.substring(0, ret.length - 1);
|
|
197
|
+
return ret + "]";
|
|
198
|
+
}
|
|
199
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as Famix from "./model/famix";
|
|
2
|
-
import { FamixBaseElement } from "./famix_base_element";
|
|
3
|
-
import { FamixJSONExporter } from "./famix_JSON_exporter";
|
|
4
|
-
import { FamixRepository } from "./famix_repository";
|
|
5
|
-
|
|
6
|
-
const model = { Famix };
|
|
7
|
-
|
|
8
|
-
export = { FamixBaseElement, FamixJSONExporter, FamixRepository, model };
|
|
1
|
+
import * as Famix from "./model/famix";
|
|
2
|
+
import { FamixBaseElement } from "./famix_base_element";
|
|
3
|
+
import { FamixJSONExporter } from "./famix_JSON_exporter";
|
|
4
|
+
import { FamixRepository } from "./famix_repository";
|
|
5
|
+
|
|
6
|
+
const model = { Famix };
|
|
7
|
+
|
|
8
|
+
export = { FamixBaseElement, FamixJSONExporter, FamixRepository, model };
|