ts2famix 1.4.1 → 2.0.1
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/LICENSE +1 -0
- package/README.md +30 -61
- package/dist/analyze.js +4 -2
- package/dist/analyze_functions/process_functions.js +285 -131
- package/dist/famix_functions/EntityDictionary.js +864 -231
- package/dist/famix_functions/helpers_creation.js +61 -10
- package/dist/fqn.js +160 -111
- package/dist/lib/famix/famix_JSON_exporter.js +55 -0
- package/dist/lib/famix/famix_base_element.js +18 -0
- package/dist/lib/famix/famix_repository.js +224 -0
- package/dist/lib/famix/{src/index.js → index.js} +1 -0
- package/dist/lib/famix/model/famix/access.js +40 -0
- package/dist/lib/famix/model/famix/accessor.js +17 -0
- package/dist/lib/famix/model/famix/alias.js +33 -0
- package/dist/lib/famix/model/famix/arrow_function.js +17 -0
- package/dist/lib/famix/model/famix/behavioral_entity.js +79 -0
- package/dist/lib/famix/model/famix/class.js +71 -0
- package/dist/lib/famix/model/famix/comment.js +39 -0
- package/dist/lib/famix/model/famix/concretisation.js +31 -0
- package/dist/lib/famix/model/famix/container_entity.js +126 -0
- package/dist/lib/famix/model/famix/decorator.js +32 -0
- package/dist/lib/famix/model/famix/entity.js +17 -0
- package/dist/lib/famix/model/famix/enum.js +31 -0
- package/dist/lib/famix/model/famix/enum_value.js +25 -0
- package/dist/lib/famix/model/famix/function.js +17 -0
- package/dist/lib/famix/model/famix/import_clause.js +41 -0
- package/dist/lib/famix/model/famix/index.js +86 -0
- package/dist/lib/famix/model/famix/indexed_file_anchor.js +38 -0
- package/dist/lib/famix/model/famix/inheritance.js +33 -0
- package/dist/lib/famix/model/famix/interface.js +64 -0
- package/dist/lib/famix/model/famix/invocation.js +54 -0
- package/dist/lib/famix/model/famix/method.js +67 -0
- package/dist/lib/famix/model/famix/module.js +60 -0
- package/dist/lib/famix/model/famix/named_entity.js +78 -0
- package/dist/lib/famix/model/famix/parameter.js +25 -0
- package/dist/lib/famix/model/famix/parameter_concretisation.js +44 -0
- package/dist/lib/famix/model/famix/parameter_type.js +45 -0
- package/dist/lib/famix/model/famix/parametric_arrow_function.js +31 -0
- package/dist/lib/famix/model/famix/parametric_class.js +44 -0
- package/dist/lib/famix/model/famix/parametric_function.js +31 -0
- package/dist/lib/famix/model/famix/parametric_interface.js +44 -0
- package/dist/lib/famix/model/famix/parametric_method.js +31 -0
- package/dist/lib/famix/model/famix/primitive_type.js +17 -0
- package/dist/lib/famix/model/famix/property.js +73 -0
- package/dist/lib/famix/model/famix/reference.js +33 -0
- package/dist/lib/famix/model/famix/scoping_entity.js +36 -0
- package/dist/lib/famix/model/famix/script_entity.js +29 -0
- package/dist/lib/famix/model/famix/source_anchor.js +27 -0
- package/dist/lib/famix/model/famix/source_language.js +35 -0
- package/dist/lib/famix/model/famix/sourced_entity.js +60 -0
- package/dist/lib/famix/model/famix/structural_entity.js +39 -0
- package/dist/lib/famix/model/famix/type.js +73 -0
- package/dist/lib/famix/model/famix/variable.js +24 -0
- package/dist/lib/ts-complex/cyclomatic-service.js +3 -3
- package/dist/refactorer/refactor-getter-setter.js +142 -0
- package/dist/ts2famix-cli-wrapper.js +42 -0
- package/dist/ts2famix-cli.js +8 -1
- package/dist/ts2famix-tsconfig.js +1 -0
- package/doc-uml/famix-typescript-model.puml +608 -0
- package/doc-uml/famix-typescript-model.svg +1 -0
- package/jest.config.json +2 -1
- package/package.json +13 -12
- package/src/analyze.ts +24 -23
- package/src/analyze_functions/process_functions.ts +310 -129
- package/src/famix_functions/EntityDictionary.ts +949 -271
- package/src/famix_functions/helpers_creation.ts +64 -6
- package/src/fqn.ts +169 -96
- package/{dist/lib/famix/src/famix_JSON_exporter.js → src/lib/famix/famix_JSON_exporter.ts} +16 -14
- package/src/lib/famix/famix_base_element.ts +22 -0
- package/{dist/lib/famix/src/famix_repository.js → src/lib/famix/famix_repository.ts} +96 -75
- package/src/lib/famix/model/famix/access.ts +50 -0
- package/src/lib/famix/model/famix/alias.ts +39 -0
- package/src/lib/famix/{src/model/famix/implicit_variable.ts → model/famix/arrow_function.ts} +3 -3
- package/src/lib/famix/model/famix/behavioral_entity.ts +97 -0
- package/src/lib/famix/model/famix/class.ts +85 -0
- package/src/lib/famix/model/famix/comment.ts +47 -0
- package/src/lib/famix/model/famix/concretisation.ts +40 -0
- package/src/lib/famix/model/famix/container_entity.ts +160 -0
- package/src/lib/famix/model/famix/decorator.ts +37 -0
- package/src/lib/famix/model/famix/enum.ts +30 -0
- package/src/lib/famix/model/famix/enum_value.ts +28 -0
- package/src/lib/famix/model/famix/import_clause.ts +51 -0
- package/src/lib/famix/{src/model → model}/famix/index.ts +8 -7
- package/src/lib/famix/model/famix/indexed_file_anchor.ts +46 -0
- package/src/lib/famix/model/famix/inheritance.ts +40 -0
- package/src/lib/famix/model/famix/interface.ts +75 -0
- package/src/lib/famix/model/famix/invocation.ts +65 -0
- package/src/lib/famix/model/famix/method.ts +89 -0
- package/src/lib/famix/model/famix/module.ts +71 -0
- package/src/lib/famix/model/famix/named_entity.ts +95 -0
- package/src/lib/famix/{src/model → model}/famix/parameter.ts +11 -12
- package/src/lib/famix/model/famix/parameter_concretisation.ts +51 -0
- package/src/lib/famix/model/famix/parameter_type.ts +58 -0
- package/src/lib/famix/model/famix/parametric_arrow_function.ts +32 -0
- package/src/lib/famix/model/famix/parametric_class.ts +49 -0
- package/src/lib/famix/model/famix/parametric_function.ts +32 -0
- package/src/lib/famix/model/famix/parametric_interface.ts +49 -0
- package/src/lib/famix/model/famix/parametric_method.ts +32 -0
- package/src/lib/famix/model/famix/primitive_type.ts +15 -0
- package/src/lib/famix/model/famix/property.ts +94 -0
- package/src/lib/famix/model/famix/reference.ts +40 -0
- package/src/lib/famix/model/famix/scoping_entity.ts +35 -0
- package/src/lib/famix/model/famix/script_entity.ts +34 -0
- package/src/lib/famix/model/famix/source_anchor.ts +30 -0
- package/src/lib/famix/model/famix/source_language.ts +35 -0
- package/src/lib/famix/model/famix/sourced_entity.ts +70 -0
- package/src/lib/famix/model/famix/structural_entity.ts +43 -0
- package/src/lib/famix/model/famix/type.ts +87 -0
- package/src/lib/famix/model/famix/variable.ts +27 -0
- package/src/lib/famix/package.json +1 -1
- package/src/lib/ts-complex/cyclomatic-service.ts +10 -10
- package/src/refactorer/refactor-getter-setter.ts +140 -0
- package/src/ts2famix-cli-wrapper.ts +21 -0
- package/src/ts2famix-cli.ts +8 -2
- package/tsconfig.check-tests.json +14 -0
- package/tsconfig.json +71 -69
- package/dist/famix2puml.js +0 -125
- package/dist/lib/famix/src/famix_base_element.js +0 -17
- 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/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/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 -83
- package/dist/lib/famix/src/model/famix/indexed_file_anchor.js +0 -51
- 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 -31
- 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/parameter_type.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 -35
- 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 -35
- package/dist/lib/famix/src/model/famix/sourced_entity.js +0 -59
- 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/variable.js +0 -23
- package/doc-uml/metamodel-full.svg +0 -1
- package/doc-uml/metamodel.svg +0 -1
- package/jest.config-old.ts +0 -199
- package/plantuml.jar +0 -0
- package/src/famix2puml.ts +0 -119
- package/src/lib/famix/package-lock.json +0 -301
- package/src/lib/famix/readme.md +0 -5
- package/src/lib/famix/src/famix_JSON_exporter.ts +0 -56
- package/src/lib/famix/src/famix_base_element.ts +0 -22
- package/src/lib/famix/src/famix_repository.ts +0 -243
- package/src/lib/famix/src/model/famix/access.ts +0 -53
- package/src/lib/famix/src/model/famix/alias.ts +0 -41
- package/src/lib/famix/src/model/famix/association.ts +0 -44
- package/src/lib/famix/src/model/famix/behavioral_entity.ts +0 -107
- package/src/lib/famix/src/model/famix/class.ts +0 -86
- package/src/lib/famix/src/model/famix/comment.ts +0 -50
- package/src/lib/famix/src/model/famix/container_entity.ts +0 -165
- package/src/lib/famix/src/model/famix/decorator.ts +0 -39
- package/src/lib/famix/src/model/famix/enum.ts +0 -31
- package/src/lib/famix/src/model/famix/enum_value.ts +0 -29
- package/src/lib/famix/src/model/famix/import_clause.ts +0 -53
- package/src/lib/famix/src/model/famix/indexed_file_anchor.ts +0 -71
- package/src/lib/famix/src/model/famix/inheritance.ts +0 -42
- package/src/lib/famix/src/model/famix/interface.ts +0 -75
- package/src/lib/famix/src/model/famix/invocation.ts +0 -68
- package/src/lib/famix/src/model/famix/method.ts +0 -96
- package/src/lib/famix/src/model/famix/module.ts +0 -31
- package/src/lib/famix/src/model/famix/named_entity.ts +0 -98
- package/src/lib/famix/src/model/famix/namespace.ts +0 -28
- package/src/lib/famix/src/model/famix/parameter_type.ts +0 -33
- package/src/lib/famix/src/model/famix/parameterizable_class.ts +0 -31
- package/src/lib/famix/src/model/famix/parameterizable_interface.ts +0 -31
- package/src/lib/famix/src/model/famix/parameterized_type.ts +0 -40
- package/src/lib/famix/src/model/famix/primitive_type.ts +0 -15
- package/src/lib/famix/src/model/famix/property.ts +0 -54
- package/src/lib/famix/src/model/famix/reference.ts +0 -42
- package/src/lib/famix/src/model/famix/scoping_entity.ts +0 -35
- package/src/lib/famix/src/model/famix/script_entity.ts +0 -38
- package/src/lib/famix/src/model/famix/source_anchor.ts +0 -31
- package/src/lib/famix/src/model/famix/source_language.ts +0 -37
- package/src/lib/famix/src/model/famix/sourced_entity.ts +0 -73
- package/src/lib/famix/src/model/famix/structural_entity.ts +0 -44
- package/src/lib/famix/src/model/famix/text_anchor.ts +0 -49
- package/src/lib/famix/src/model/famix/type.ts +0 -88
- package/src/lib/famix/src/model/famix/variable.ts +0 -28
- package/src/lib/famix/tsconfig.json +0 -27
- package/src/lib/famix/tslint.json +0 -15
- /package/src/lib/famix/{src/index.ts → index.ts} +0 -0
- /package/src/lib/famix/{src/model → model}/famix/accessor.ts +0 -0
- /package/src/lib/famix/{src/model → model}/famix/entity.ts +0 -0
- /package/src/lib/famix/{src/model → model}/famix/function.ts +0 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { FamixJSONExporter } from "../../famix_JSON_exporter";
|
|
2
|
+
import { Class } from "./class";
|
|
3
|
+
import { Interface } from "./interface";
|
|
4
|
+
import { StructuralEntity } from "./structural_entity";
|
|
5
|
+
|
|
6
|
+
export type VisibilityTypes = "public" | "private" | "protected" | "";
|
|
7
|
+
|
|
8
|
+
export class Property extends StructuralEntity {
|
|
9
|
+
|
|
10
|
+
private _isClassSide: boolean = false;
|
|
11
|
+
|
|
12
|
+
public get readOnly() {
|
|
13
|
+
return this._readOnly;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public set readOnly(value: boolean) {
|
|
17
|
+
this._readOnly = value;
|
|
18
|
+
}
|
|
19
|
+
private _readOnly: boolean = false;
|
|
20
|
+
private _parentEntity!: Class | Interface;
|
|
21
|
+
|
|
22
|
+
public get isDefinitelyAssigned() {
|
|
23
|
+
return this._isDefinitelyAssigned;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public set isDefinitelyAssigned(value: boolean) {
|
|
27
|
+
this._isDefinitelyAssigned = value;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public get isOptional() {
|
|
31
|
+
return this._isOptional;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public set isOptional(value: boolean) {
|
|
35
|
+
this._isOptional = value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public get isJavaScriptPrivate() {
|
|
39
|
+
return this._isJavaScriptPrivate;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public set isJavaScriptPrivate(value: boolean) {
|
|
43
|
+
this._isJavaScriptPrivate = value;
|
|
44
|
+
}
|
|
45
|
+
private _isDefinitelyAssigned!: boolean;
|
|
46
|
+
|
|
47
|
+
private _isOptional!: boolean;
|
|
48
|
+
|
|
49
|
+
private _isJavaScriptPrivate!: boolean;
|
|
50
|
+
|
|
51
|
+
public get visibility() {
|
|
52
|
+
return this._visibility;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public set visibility(value: VisibilityTypes) {
|
|
56
|
+
this._visibility = value;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private _visibility: VisibilityTypes = "";
|
|
60
|
+
|
|
61
|
+
public getJSON(): string {
|
|
62
|
+
const json: FamixJSONExporter = new FamixJSONExporter("Property", this);
|
|
63
|
+
this.addPropertiesToExporter(json);
|
|
64
|
+
return json.getJSON();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public addPropertiesToExporter(exporter: FamixJSONExporter): void {
|
|
68
|
+
super.addPropertiesToExporter(exporter);
|
|
69
|
+
exporter.addProperty("readOnly", this.readOnly);
|
|
70
|
+
exporter.addProperty("isClassSide", this.isClassSide);
|
|
71
|
+
exporter.addProperty("parentType", this.parentEntity);
|
|
72
|
+
exporter.addProperty("visibility", this.visibility);
|
|
73
|
+
exporter.addProperty("isDefinitelyAssigned", this.isDefinitelyAssigned);
|
|
74
|
+
exporter.addProperty("isOptional", this.isOptional);
|
|
75
|
+
exporter.addProperty("isJavaScriptPrivate", this.isJavaScriptPrivate);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
get isClassSide() {
|
|
79
|
+
return this._isClassSide;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
set isClassSide(isClassSide: boolean) {
|
|
83
|
+
this._isClassSide = isClassSide;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
get parentEntity() {
|
|
87
|
+
return this._parentEntity;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
set parentEntity(parentEntity: Class | Interface) {
|
|
91
|
+
this._parentEntity = parentEntity;
|
|
92
|
+
parentEntity.addProperty(this);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { FamixJSONExporter } from "../../famix_JSON_exporter";
|
|
2
|
+
import { Type } from "./type";
|
|
3
|
+
import { ContainerEntity } from "./container_entity";
|
|
4
|
+
import { Entity } from "./entity";
|
|
5
|
+
|
|
6
|
+
export class Reference extends Entity {
|
|
7
|
+
|
|
8
|
+
private _source!: ContainerEntity;
|
|
9
|
+
private _target!: Type;
|
|
10
|
+
|
|
11
|
+
public getJSON(): string {
|
|
12
|
+
const json: FamixJSONExporter = new FamixJSONExporter("Reference", this);
|
|
13
|
+
this.addPropertiesToExporter(json);
|
|
14
|
+
return json.getJSON();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public addPropertiesToExporter(exporter: FamixJSONExporter): void {
|
|
18
|
+
super.addPropertiesToExporter(exporter);
|
|
19
|
+
exporter.addProperty("source", this.source);
|
|
20
|
+
exporter.addProperty("target", this.target);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get source() {
|
|
24
|
+
return this._source;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
set source(source: ContainerEntity) {
|
|
28
|
+
this._source = source;
|
|
29
|
+
source.addOutgoingReference(this);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get target() {
|
|
33
|
+
return this._target;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
set target(target: Type) {
|
|
37
|
+
this._target = target;
|
|
38
|
+
target.addIncomingReference(this);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { FamixJSONExporter } from "../../famix_JSON_exporter";
|
|
2
|
+
import { ContainerEntity } from "./container_entity";
|
|
3
|
+
import { logger } from "../../../../analyze";
|
|
4
|
+
import { Module } from "./module";
|
|
5
|
+
|
|
6
|
+
export class ScopingEntity extends ContainerEntity {
|
|
7
|
+
|
|
8
|
+
private _modules: Set<Module> = new Set();
|
|
9
|
+
|
|
10
|
+
public addModule(childModule: Module): void {
|
|
11
|
+
if (!this._modules.has(childModule)) {
|
|
12
|
+
logger.debug("Adding module " + childModule.name + " to " + this.name);
|
|
13
|
+
this._modules.add(childModule);
|
|
14
|
+
childModule.parentScope = this;
|
|
15
|
+
} else {
|
|
16
|
+
logger.debug("Module " + childModule.name + " already added to " + this.name);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
public getJSON(): string {
|
|
22
|
+
const json: FamixJSONExporter = new FamixJSONExporter("ScopingEntity", this);
|
|
23
|
+
this.addPropertiesToExporter(json);
|
|
24
|
+
return json.getJSON();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public addPropertiesToExporter(exporter: FamixJSONExporter): void {
|
|
28
|
+
super.addPropertiesToExporter(exporter);
|
|
29
|
+
// exporter.addProperty("namespaces", this.getModules());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get modules() {
|
|
33
|
+
return this._modules;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { FamixJSONExporter } from "../../famix_JSON_exporter";
|
|
2
|
+
import { ScopingEntity } from "./scoping_entity";
|
|
3
|
+
|
|
4
|
+
export class ScriptEntity extends ScopingEntity {
|
|
5
|
+
|
|
6
|
+
private _numberOfLinesOfText!: number;
|
|
7
|
+
private _numberOfCharacters!: number;
|
|
8
|
+
|
|
9
|
+
public getJSON(): string {
|
|
10
|
+
const json: FamixJSONExporter = new FamixJSONExporter("ScriptEntity", this);
|
|
11
|
+
this.addPropertiesToExporter(json);
|
|
12
|
+
return json.getJSON();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public addPropertiesToExporter(exporter: FamixJSONExporter): void {
|
|
16
|
+
super.addPropertiesToExporter(exporter);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
get numberOfLinesOfText() {
|
|
20
|
+
return this._numberOfLinesOfText;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
set numberOfLinesOfText(numberOfLinesOfText: number) {
|
|
24
|
+
this._numberOfLinesOfText = numberOfLinesOfText;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get numberOfCharacters() {
|
|
28
|
+
return this._numberOfCharacters;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
set numberOfCharacters(numberOfCharacters: number) {
|
|
32
|
+
this._numberOfCharacters = numberOfCharacters;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { FamixJSONExporter } from "../../famix_JSON_exporter";
|
|
2
|
+
import { Entity } from "./entity";
|
|
3
|
+
import { SourcedEntity } from "./sourced_entity";
|
|
4
|
+
|
|
5
|
+
export class SourceAnchor extends Entity {
|
|
6
|
+
|
|
7
|
+
private _element!: SourcedEntity;
|
|
8
|
+
|
|
9
|
+
public getJSON(): string {
|
|
10
|
+
const json: FamixJSONExporter = new FamixJSONExporter("SourceAnchor", this);
|
|
11
|
+
this.addPropertiesToExporter(json);
|
|
12
|
+
return json.getJSON();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public addPropertiesToExporter(exporter: FamixJSONExporter): void {
|
|
16
|
+
super.addPropertiesToExporter(exporter);
|
|
17
|
+
exporter.addProperty("element", this.element);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get element() {
|
|
21
|
+
return this._element;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
set element(element: SourcedEntity) {
|
|
25
|
+
if (this._element === undefined) {
|
|
26
|
+
this._element = element;
|
|
27
|
+
element.sourceAnchor = this;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { FamixJSONExporter } from "../../famix_JSON_exporter";
|
|
2
|
+
import { Entity } from "./entity";
|
|
3
|
+
import { SourcedEntity } from "./sourced_entity";
|
|
4
|
+
|
|
5
|
+
export class SourceLanguage extends Entity {
|
|
6
|
+
|
|
7
|
+
private _sourcedEntities: Set<SourcedEntity> = new Set();
|
|
8
|
+
|
|
9
|
+
// name of the source language
|
|
10
|
+
get name(): string {
|
|
11
|
+
return "TypeScript";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public addSourcedEntity(sourcedEntity: SourcedEntity): void {
|
|
15
|
+
if (!this._sourcedEntities.has(sourcedEntity)) {
|
|
16
|
+
this._sourcedEntities.add(sourcedEntity);
|
|
17
|
+
sourcedEntity.declaredSourceLanguage = this;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public getJSON(): string {
|
|
22
|
+
const json: FamixJSONExporter = new FamixJSONExporter("SourceLanguage", this);
|
|
23
|
+
this.addPropertiesToExporter(json);
|
|
24
|
+
return json.getJSON();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public addPropertiesToExporter(exporter: FamixJSONExporter): void {
|
|
28
|
+
super.addPropertiesToExporter(exporter);
|
|
29
|
+
exporter.addProperty("sourcedEntities", this.sourcedEntities);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get sourcedEntities() {
|
|
33
|
+
return this._sourcedEntities;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { FamixJSONExporter } from "../../famix_JSON_exporter";
|
|
2
|
+
import { SourceLanguage } from "./source_language";
|
|
3
|
+
import { Entity } from "./entity";
|
|
4
|
+
import { Comment } from "./comment";
|
|
5
|
+
import { SourceAnchor } from "./source_anchor";
|
|
6
|
+
import { logger } from "../../../../analyze";
|
|
7
|
+
|
|
8
|
+
export class SourcedEntity extends Entity {
|
|
9
|
+
|
|
10
|
+
private _isStub!: boolean;
|
|
11
|
+
private _sourceAnchor!: SourceAnchor;
|
|
12
|
+
private _comments: Set<Comment> = new Set();
|
|
13
|
+
|
|
14
|
+
public addComment(comment: Comment): void {
|
|
15
|
+
if (!this._comments.has(comment)) {
|
|
16
|
+
this._comments.add(comment);
|
|
17
|
+
comment.container = this;
|
|
18
|
+
} else {
|
|
19
|
+
logger.debug("Adding comment that is already in comments: " + comment.getJSON() + " to " + this.getJSON());
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
private _declaredSourceLanguage!: SourceLanguage;
|
|
24
|
+
|
|
25
|
+
public getJSON(): string {
|
|
26
|
+
const json: FamixJSONExporter = new FamixJSONExporter("SourcedEntity", this);
|
|
27
|
+
this.addPropertiesToExporter(json);
|
|
28
|
+
return json.getJSON();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public addPropertiesToExporter(exporter: FamixJSONExporter): void {
|
|
32
|
+
super.addPropertiesToExporter(exporter);
|
|
33
|
+
exporter.addProperty("isStub", this.isStub);
|
|
34
|
+
exporter.addProperty("sourceAnchor", this.sourceAnchor);
|
|
35
|
+
exporter.addProperty("comments", this.comments);
|
|
36
|
+
exporter.addProperty("declaredSourceLanguage", this.declaredSourceLanguage);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
get isStub() {
|
|
40
|
+
return this._isStub;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
set isStub(isStub: boolean) {
|
|
44
|
+
this._isStub = isStub;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
get sourceAnchor() {
|
|
48
|
+
return this._sourceAnchor;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
set sourceAnchor(sourceAnchor: SourceAnchor) {
|
|
52
|
+
if (this._sourceAnchor === undefined) {
|
|
53
|
+
this._sourceAnchor = sourceAnchor;
|
|
54
|
+
sourceAnchor.element = this;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get comments() {
|
|
59
|
+
return this._comments;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get declaredSourceLanguage() {
|
|
63
|
+
return this._declaredSourceLanguage;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
set declaredSourceLanguage(declaredSourceLanguage: SourceLanguage) {
|
|
67
|
+
this._declaredSourceLanguage = declaredSourceLanguage;
|
|
68
|
+
declaredSourceLanguage.addSourcedEntity(this);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { FamixJSONExporter } from "../../famix_JSON_exporter";
|
|
2
|
+
import { Type } from "./type";
|
|
3
|
+
import { Access } from "./access";
|
|
4
|
+
import { NamedEntity } from "./named_entity";
|
|
5
|
+
|
|
6
|
+
export class StructuralEntity extends NamedEntity {
|
|
7
|
+
|
|
8
|
+
private _incomingAccesses: Set<Access> = new Set();
|
|
9
|
+
|
|
10
|
+
public addIncomingAccess(incomingAccess: Access): void {
|
|
11
|
+
if (!this._incomingAccesses.has(incomingAccess)) {
|
|
12
|
+
this._incomingAccesses.add(incomingAccess);
|
|
13
|
+
incomingAccess.variable = this;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
private _declaredType!: Type;
|
|
18
|
+
|
|
19
|
+
public getJSON(): string {
|
|
20
|
+
const json: FamixJSONExporter = new FamixJSONExporter("StructuralEntity", this);
|
|
21
|
+
this.addPropertiesToExporter(json);
|
|
22
|
+
return json.getJSON();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public addPropertiesToExporter(exporter: FamixJSONExporter): void {
|
|
26
|
+
super.addPropertiesToExporter(exporter);
|
|
27
|
+
exporter.addProperty("incomingAccesses", this.incomingAccesses);
|
|
28
|
+
exporter.addProperty("declaredType", this.declaredType);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get incomingAccesses() {
|
|
32
|
+
return this._incomingAccesses;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get declaredType() {
|
|
36
|
+
return this._declaredType;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
set declaredType(declaredType: Type) {
|
|
40
|
+
this._declaredType = declaredType;
|
|
41
|
+
declaredType.addStructureWithDeclaredType(this);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { FamixJSONExporter } from "../../famix_JSON_exporter";
|
|
2
|
+
import { StructuralEntity } from "./structural_entity";
|
|
3
|
+
import { ContainerEntity } from "./container_entity";
|
|
4
|
+
import { Reference } from "./reference";
|
|
5
|
+
import { BehavioralEntity } from "./behavioral_entity";
|
|
6
|
+
import { Alias } from "./alias";
|
|
7
|
+
|
|
8
|
+
export class Type extends ContainerEntity {
|
|
9
|
+
|
|
10
|
+
private _container!: ContainerEntity;
|
|
11
|
+
private _typeAliases: Set<Alias> = new Set();
|
|
12
|
+
|
|
13
|
+
public addTypeAlias(typeAlias: Alias): void {
|
|
14
|
+
if (!this._typeAliases.has(typeAlias)) {
|
|
15
|
+
this._typeAliases.add(typeAlias);
|
|
16
|
+
typeAlias.aliasedEntity = this;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
private _structuresWithDeclaredType: Set<StructuralEntity> = new Set();
|
|
21
|
+
|
|
22
|
+
public addStructureWithDeclaredType(structureWithDeclaredType: StructuralEntity): void {
|
|
23
|
+
if (!this._structuresWithDeclaredType.has(structureWithDeclaredType)) {
|
|
24
|
+
this._structuresWithDeclaredType.add(structureWithDeclaredType);
|
|
25
|
+
structureWithDeclaredType.declaredType = this;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private _behavioralEntitiesWithDeclaredType: Set<BehavioralEntity> = new Set();
|
|
30
|
+
|
|
31
|
+
public addBehavioralEntityWithDeclaredType(behavioralEntityWithDeclaredType: BehavioralEntity): void {
|
|
32
|
+
if (!this._behavioralEntitiesWithDeclaredType.has(behavioralEntityWithDeclaredType)) {
|
|
33
|
+
this._behavioralEntitiesWithDeclaredType.add(behavioralEntityWithDeclaredType);
|
|
34
|
+
behavioralEntityWithDeclaredType.declaredType = this;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private _incomingReferences: Set<Reference> = new Set();
|
|
39
|
+
|
|
40
|
+
public addIncomingReference(incomingReference: Reference): void {
|
|
41
|
+
if (!this._incomingReferences.has(incomingReference)) {
|
|
42
|
+
this._incomingReferences.add(incomingReference);
|
|
43
|
+
incomingReference.target = this;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public getJSON(): string {
|
|
48
|
+
const json: FamixJSONExporter = new FamixJSONExporter("Type", this);
|
|
49
|
+
this.addPropertiesToExporter(json);
|
|
50
|
+
return json.getJSON();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public addPropertiesToExporter(exporter: FamixJSONExporter): void {
|
|
54
|
+
super.addPropertiesToExporter(exporter);
|
|
55
|
+
exporter.addProperty("typeContainer", this.container);
|
|
56
|
+
/* unsupported properties in MM so far */
|
|
57
|
+
// exporter.addProperty("typeAliases", this.getTypeAliases());
|
|
58
|
+
// exporter.addProperty("structuresWithDeclaredType", this.getStructuresWithDeclaredType());
|
|
59
|
+
// exporter.addProperty("behavioralEntitiesWithDeclaredType", this.getBehavioralEntitiesWithDeclaredType());
|
|
60
|
+
exporter.addProperty("incomingReferences", this.incomingReferences);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
get container() {
|
|
64
|
+
return this._container;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
set container(container: ContainerEntity) {
|
|
68
|
+
this._container = container;
|
|
69
|
+
container.addType(this);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
get typeAliases() {
|
|
73
|
+
return this._typeAliases;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
get structuresWithDeclaredType() {
|
|
77
|
+
return this._structuresWithDeclaredType;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
get behavioralEntitiesWithDeclaredType() {
|
|
81
|
+
return this._behavioralEntitiesWithDeclaredType;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
get incomingReferences() {
|
|
85
|
+
return this._incomingReferences;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FamixJSONExporter } from "../../famix_JSON_exporter";
|
|
2
|
+
import { ContainerEntity } from "./container_entity";
|
|
3
|
+
import { StructuralEntity } from "./structural_entity";
|
|
4
|
+
|
|
5
|
+
export class Variable extends StructuralEntity {
|
|
6
|
+
|
|
7
|
+
private _parentContainerEntity!: ContainerEntity;
|
|
8
|
+
|
|
9
|
+
public getJSON(): string {
|
|
10
|
+
const json: FamixJSONExporter = new FamixJSONExporter("Variable", this);
|
|
11
|
+
this.addPropertiesToExporter(json);
|
|
12
|
+
return json.getJSON();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public addPropertiesToExporter(exporter: FamixJSONExporter): void {
|
|
16
|
+
super.addPropertiesToExporter(exporter);
|
|
17
|
+
exporter.addProperty("parentBehaviouralEntity", this.parentContainerEntity);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get parentContainerEntity() {
|
|
21
|
+
return this._parentContainerEntity;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
set parentContainerEntity(parentContainerEntity: ContainerEntity) {
|
|
25
|
+
this._parentContainerEntity = parentContainerEntity;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -12,21 +12,21 @@ The above copyright notice and this permission notice shall be included in all c
|
|
|
12
12
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import { forEachChild, isIdentifier, SyntaxKind, createSourceFile, ScriptTarget } from 'typescript';
|
|
15
|
+
import { forEachChild, isIdentifier, SyntaxKind, createSourceFile, ScriptTarget, Node, CaseClause, BinaryExpression, FunctionLikeDeclaration } from 'typescript';
|
|
16
16
|
import { isFunctionWithBody } from 'tsutils';
|
|
17
|
-
import { existsSync, readFileSync } from 'fs';
|
|
17
|
+
import { existsSync, PathLike, readFileSync } from 'fs';
|
|
18
18
|
|
|
19
|
-
const getNodeName = (node) => {
|
|
19
|
+
const getNodeName = (node: FunctionLikeDeclaration) => {
|
|
20
20
|
const { name, pos, end } = node;
|
|
21
21
|
const key = name !== undefined && isIdentifier(name) ? name.text : JSON.stringify({ pos, end });
|
|
22
22
|
return key;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
const increasesComplexity = (node) => {
|
|
25
|
+
const increasesComplexity = (node: Node) => {
|
|
26
26
|
/* eslint-disable indent */
|
|
27
27
|
switch (node.kind) {
|
|
28
28
|
case SyntaxKind.CaseClause:
|
|
29
|
-
return node.statements.length > 0;
|
|
29
|
+
return (node as CaseClause).statements.length > 0;
|
|
30
30
|
case SyntaxKind.CatchClause:
|
|
31
31
|
case SyntaxKind.ConditionalExpression:
|
|
32
32
|
case SyntaxKind.DoStatement:
|
|
@@ -38,7 +38,7 @@ const increasesComplexity = (node) => {
|
|
|
38
38
|
return true;
|
|
39
39
|
|
|
40
40
|
case SyntaxKind.BinaryExpression:
|
|
41
|
-
switch (node.operatorToken.kind) {
|
|
41
|
+
switch ((node as BinaryExpression).operatorToken.kind) {
|
|
42
42
|
case SyntaxKind.BarBarToken:
|
|
43
43
|
case SyntaxKind.AmpersandAmpersandToken:
|
|
44
44
|
return true;
|
|
@@ -52,9 +52,9 @@ const increasesComplexity = (node) => {
|
|
|
52
52
|
/* eslint-enable indent */
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
-
const calculateFromSource = (ctx) => {
|
|
55
|
+
const calculateFromSource = (ctx: Node) => {
|
|
56
56
|
let complexity = 0;
|
|
57
|
-
const output = {};
|
|
57
|
+
const output: { [key: string]: number } = {};
|
|
58
58
|
forEachChild(ctx, function cb(node) {
|
|
59
59
|
if (isFunctionWithBody(node)) {
|
|
60
60
|
const old = complexity;
|
|
@@ -73,11 +73,11 @@ const calculateFromSource = (ctx) => {
|
|
|
73
73
|
return output;
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
-
export const calculate = (filePath) => {
|
|
76
|
+
export const calculate = (filePath: PathLike) => {
|
|
77
77
|
if (!existsSync(filePath)) {
|
|
78
78
|
throw new Error(`File "${filePath}" does not exists`);
|
|
79
79
|
}
|
|
80
80
|
const sourceText = readFileSync(filePath).toString();
|
|
81
|
-
const source = createSourceFile(filePath, sourceText, ScriptTarget.ES2015);
|
|
81
|
+
const source = createSourceFile(filePath.toString(), sourceText, ScriptTarget.ES2015);
|
|
82
82
|
return calculateFromSource(source);
|
|
83
83
|
};
|