ts2famix 1.0.13 → 1.0.15
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 +525 -0
- package/dist/famix_functions/famix_functions_associations.js +223 -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 +199 -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 +31 -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 +34 -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 +565 -559
- package/src/famix_functions/famix_functions_associations.ts +225 -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 +212 -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 +34 -31
- package/src/lib/famix/src/model/famix/script_entity.ts +38 -38
- package/src/lib/famix/src/model/famix/source_anchor.ts +31 -31
- package/src/lib/famix/src/model/famix/source_language.ts +31 -31
- package/src/lib/famix/src/model/famix/sourced_entity.ts +70 -70
- package/src/lib/famix/src/model/famix/structural_entity.ts +44 -44
- package/src/lib/famix/src/model/famix/text_anchor.ts +49 -49
- package/src/lib/famix/src/model/famix/type.ts +88 -88
- package/src/lib/famix/src/model/famix/type_parameter.ts +33 -33
- package/src/lib/famix/src/model/famix/variable.ts +28 -28
- package/src/lib/famix/tsconfig.json +26 -26
- package/src/lib/famix/tslint.json +14 -14
- package/src/lib/ts-complex/cyclomatic-service.ts +85 -85
- package/src/ts2famix-cli.ts +39 -39
- package/tsconfig.json +69 -69
package/package.json
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "ts2famix",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "A TypeScript to JSON importer for Moose 10.",
|
|
5
|
-
"main": "dist/ts2famix-cli.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"dev": "ts-node src/ts2famix-cli.ts",
|
|
8
|
-
"debug": "node --inspect-brk node_modules/.bin/ts-node",
|
|
9
|
-
"build": "tsc",
|
|
10
|
-
"test": "jest --colors --silent",
|
|
11
|
-
"local": "sudo npm i -g && ts2famix",
|
|
12
|
-
"refresh": "rm -rf ./node_modules ./package-lock.json && npm install",
|
|
13
|
-
"doc": "typedoc && touch docs/.gitkeep",
|
|
14
|
-
"coverage": "jest --colors --silent --coverage --coverageDirectory=coverage",
|
|
15
|
-
"uml": "./src/generate_uml.sh"
|
|
16
|
-
},
|
|
17
|
-
"bin": {
|
|
18
|
-
"ts2famix": "dist/ts2famix-cli.js"
|
|
19
|
-
},
|
|
20
|
-
"keywords": [],
|
|
21
|
-
"author": "",
|
|
22
|
-
"nodemonConfig": {
|
|
23
|
-
"ignore": [
|
|
24
|
-
"dist/*"
|
|
25
|
-
]
|
|
26
|
-
},
|
|
27
|
-
"license": "MIT",
|
|
28
|
-
"devDependencies": {
|
|
29
|
-
"@types/jest": "^29.5.4",
|
|
30
|
-
"@types/node": "^20.6.0",
|
|
31
|
-
"@types/yargs": "^17.0.24",
|
|
32
|
-
"@typescript-eslint/eslint-plugin": "^6.6.0",
|
|
33
|
-
"@typescript-eslint/parser": "^6.6.0",
|
|
34
|
-
"eslint": "^8.49.0",
|
|
35
|
-
"jest": "^29.6.4",
|
|
36
|
-
"tplant": "^3.1.2",
|
|
37
|
-
"ts-jest": "^29.1.1",
|
|
38
|
-
"ts-node": "^10.9.1",
|
|
39
|
-
"typedoc": "^0.25.1",
|
|
40
|
-
"typescript": "^5.2.2"
|
|
41
|
-
},
|
|
42
|
-
"dependencies": {
|
|
43
|
-
"ts-morph": "^19.0.0",
|
|
44
|
-
"tsutils": "^3.21.0",
|
|
45
|
-
"yargs": "^17.7.2"
|
|
46
|
-
}
|
|
47
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "ts2famix",
|
|
3
|
+
"version": "1.0.15",
|
|
4
|
+
"description": "A TypeScript to JSON importer for Moose 10.",
|
|
5
|
+
"main": "dist/ts2famix-cli.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "ts-node src/ts2famix-cli.ts",
|
|
8
|
+
"debug": "node --inspect-brk node_modules/.bin/ts-node",
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"test": "jest --colors --silent",
|
|
11
|
+
"local": "sudo npm i -g && ts2famix",
|
|
12
|
+
"refresh": "rm -rf ./node_modules ./package-lock.json && npm install",
|
|
13
|
+
"doc": "typedoc && touch docs/.gitkeep",
|
|
14
|
+
"coverage": "jest --colors --silent --coverage --coverageDirectory=coverage",
|
|
15
|
+
"uml": "./src/generate_uml.sh"
|
|
16
|
+
},
|
|
17
|
+
"bin": {
|
|
18
|
+
"ts2famix": "dist/ts2famix-cli.js"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [],
|
|
21
|
+
"author": "",
|
|
22
|
+
"nodemonConfig": {
|
|
23
|
+
"ignore": [
|
|
24
|
+
"dist/*"
|
|
25
|
+
]
|
|
26
|
+
},
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/jest": "^29.5.4",
|
|
30
|
+
"@types/node": "^20.6.0",
|
|
31
|
+
"@types/yargs": "^17.0.24",
|
|
32
|
+
"@typescript-eslint/eslint-plugin": "^6.6.0",
|
|
33
|
+
"@typescript-eslint/parser": "^6.6.0",
|
|
34
|
+
"eslint": "^8.49.0",
|
|
35
|
+
"jest": "^29.6.4",
|
|
36
|
+
"tplant": "^3.1.2",
|
|
37
|
+
"ts-jest": "^29.1.1",
|
|
38
|
+
"ts-node": "^10.9.1",
|
|
39
|
+
"typedoc": "^0.25.1",
|
|
40
|
+
"typescript": "^5.2.2"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"ts-morph": "^19.0.0",
|
|
44
|
+
"tsutils": "^3.21.0",
|
|
45
|
+
"yargs": "^17.7.2"
|
|
46
|
+
}
|
|
47
|
+
}
|
package/src/analyze.ts
CHANGED
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
import { Project } from "ts-morph";
|
|
2
|
-
import * as fs from 'fs';
|
|
3
|
-
import { FamixRepository } from "./lib/famix/src/famix_repository";
|
|
4
|
-
import { FamixFunctions } from "./famix_functions/famix_functions";
|
|
5
|
-
import { ProcessFiles } from "./analyze_functions/processFiles";
|
|
6
|
-
import { ProcessAccesses } from "./analyze_functions/processAccesses";
|
|
7
|
-
import { ProcessInvocations } from "./analyze_functions/processInvocations";
|
|
8
|
-
import { ProcessInheritances } from "./analyze_functions/processInheritances";
|
|
9
|
-
import { ProcessImportClauses } from "./analyze_functions/processImportClauses";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* This class is used to build a Famix model from a TypeScript source code
|
|
13
|
-
*/
|
|
14
|
-
export class Importer {
|
|
15
|
-
|
|
16
|
-
private project = new Project(); // The project containing the source files to analyze
|
|
17
|
-
private famixFunctions = new FamixFunctions(); // FamixFunctions object, it contains all the functions needed to create Famix entities
|
|
18
|
-
private processFiles = new ProcessFiles(this.famixFunctions); // ProcessFiles object, it contains all the functions needed to process the source files
|
|
19
|
-
private processAccesses = new ProcessAccesses(this.famixFunctions); // ProcessAccesses object, it contains all the functions needed to process the accesses
|
|
20
|
-
private processInvocations = new ProcessInvocations(this.famixFunctions); // ProcessInvocations object, it contains all the functions needed to process the invocations
|
|
21
|
-
private processInheritances = new ProcessInheritances(this.famixFunctions); // ProcessInheritances object, it contains all the functions needed to process the inheritances
|
|
22
|
-
private processImportClauses = new ProcessImportClauses(this.famixFunctions); // ProcessImportClauses object, it contains all the functions needed to process the import clauses
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Main method
|
|
26
|
-
* @param paths An array of paths to the source files to analyze
|
|
27
|
-
* @returns The Famix repository containing the Famix model
|
|
28
|
-
*/
|
|
29
|
-
public famixRepFromPaths(paths: Array<string>): FamixRepository {
|
|
30
|
-
|
|
31
|
-
// try {
|
|
32
|
-
console.info(`famixRepFromPaths: paths: ${paths}`);
|
|
33
|
-
this.project.addSourceFilesAtPaths(paths);
|
|
34
|
-
this.processEntities(this.project);
|
|
35
|
-
|
|
36
|
-
const famixRep = this.famixFunctions.getFamixRepository();
|
|
37
|
-
// }
|
|
38
|
-
// catch (error) {
|
|
39
|
-
// console.error(`> ERROR: got exception ${error}. Exiting...`);
|
|
40
|
-
// console.error(error.message);
|
|
41
|
-
// console.error(error.stack);
|
|
42
|
-
// process.exit(1);
|
|
43
|
-
// }
|
|
44
|
-
|
|
45
|
-
return famixRep;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
private processEntities(project) {
|
|
49
|
-
this.processFiles.processFiles(project.getSourceFiles());
|
|
50
|
-
const accesses = this.processFiles.getAccesses();
|
|
51
|
-
const methodsAndFunctionsWithId = this.processFiles.getMethodsAndFunctionsWithId();
|
|
52
|
-
const classes = this.processFiles.getClasses();
|
|
53
|
-
const interfaces = this.processFiles.getInterfaces();
|
|
54
|
-
const modules = this.processFiles.getModules();
|
|
55
|
-
const exports = this.processFiles.getExports();
|
|
56
|
-
|
|
57
|
-
this.processImportClauses.processImportClauses(modules, exports);
|
|
58
|
-
this.processAccesses.processAccesses(accesses);
|
|
59
|
-
this.processInvocations.processInvocations(methodsAndFunctionsWithId);
|
|
60
|
-
this.processInheritances.processInheritances(classes, interfaces);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Main method for tests
|
|
65
|
-
*
|
|
66
|
-
* @param filename The name of the file to analyze
|
|
67
|
-
* @param source A TypeScript source code
|
|
68
|
-
* @returns The Famix repository containing the Famix model
|
|
69
|
-
*/
|
|
70
|
-
// TODO: this is slow because it writes the source code to a file and then reads it again - it's possible to just pass the source code to the ts-morph project
|
|
71
|
-
public famixRepFromSource(filename: string, source: string): FamixRepository {
|
|
72
|
-
const filePath = `./test_src/${filename}.ts`;
|
|
73
|
-
|
|
74
|
-
fs.writeFileSync(filePath, source, 'utf-8');
|
|
75
|
-
|
|
76
|
-
const famixRep = this.famixRepFromPaths([filePath]);
|
|
77
|
-
|
|
78
|
-
return famixRep;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Main method for a ts-morph project
|
|
83
|
-
* @param project A ts-morph project
|
|
84
|
-
* @returns The Famix repository containing the Famix model
|
|
85
|
-
*/
|
|
86
|
-
public famixRepFromProject(project: Project): FamixRepository {
|
|
87
|
-
//const sourceFileNames = project.getSourceFiles().map(f => f.getFilePath()) as Array<string>;
|
|
88
|
-
|
|
89
|
-
//const famixRep = this.famixRepFromPaths(sourceFileNames);
|
|
90
|
-
this.processEntities(project);
|
|
91
|
-
|
|
92
|
-
return this.famixFunctions.getFamixRepository();
|
|
93
|
-
}
|
|
94
|
-
}
|
|
1
|
+
import { Project } from "ts-morph";
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import { FamixRepository } from "./lib/famix/src/famix_repository";
|
|
4
|
+
import { FamixFunctions } from "./famix_functions/famix_functions";
|
|
5
|
+
import { ProcessFiles } from "./analyze_functions/processFiles";
|
|
6
|
+
import { ProcessAccesses } from "./analyze_functions/processAccesses";
|
|
7
|
+
import { ProcessInvocations } from "./analyze_functions/processInvocations";
|
|
8
|
+
import { ProcessInheritances } from "./analyze_functions/processInheritances";
|
|
9
|
+
import { ProcessImportClauses } from "./analyze_functions/processImportClauses";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* This class is used to build a Famix model from a TypeScript source code
|
|
13
|
+
*/
|
|
14
|
+
export class Importer {
|
|
15
|
+
|
|
16
|
+
private project = new Project(); // The project containing the source files to analyze
|
|
17
|
+
private famixFunctions = new FamixFunctions(); // FamixFunctions object, it contains all the functions needed to create Famix entities
|
|
18
|
+
private processFiles = new ProcessFiles(this.famixFunctions); // ProcessFiles object, it contains all the functions needed to process the source files
|
|
19
|
+
private processAccesses = new ProcessAccesses(this.famixFunctions); // ProcessAccesses object, it contains all the functions needed to process the accesses
|
|
20
|
+
private processInvocations = new ProcessInvocations(this.famixFunctions); // ProcessInvocations object, it contains all the functions needed to process the invocations
|
|
21
|
+
private processInheritances = new ProcessInheritances(this.famixFunctions); // ProcessInheritances object, it contains all the functions needed to process the inheritances
|
|
22
|
+
private processImportClauses = new ProcessImportClauses(this.famixFunctions); // ProcessImportClauses object, it contains all the functions needed to process the import clauses
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Main method
|
|
26
|
+
* @param paths An array of paths to the source files to analyze
|
|
27
|
+
* @returns The Famix repository containing the Famix model
|
|
28
|
+
*/
|
|
29
|
+
public famixRepFromPaths(paths: Array<string>): FamixRepository {
|
|
30
|
+
|
|
31
|
+
// try {
|
|
32
|
+
console.info(`famixRepFromPaths: paths: ${paths}`);
|
|
33
|
+
this.project.addSourceFilesAtPaths(paths);
|
|
34
|
+
this.processEntities(this.project);
|
|
35
|
+
|
|
36
|
+
const famixRep = this.famixFunctions.getFamixRepository();
|
|
37
|
+
// }
|
|
38
|
+
// catch (error) {
|
|
39
|
+
// console.error(`> ERROR: got exception ${error}. Exiting...`);
|
|
40
|
+
// console.error(error.message);
|
|
41
|
+
// console.error(error.stack);
|
|
42
|
+
// process.exit(1);
|
|
43
|
+
// }
|
|
44
|
+
|
|
45
|
+
return famixRep;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private processEntities(project) {
|
|
49
|
+
this.processFiles.processFiles(project.getSourceFiles());
|
|
50
|
+
const accesses = this.processFiles.getAccesses();
|
|
51
|
+
const methodsAndFunctionsWithId = this.processFiles.getMethodsAndFunctionsWithId();
|
|
52
|
+
const classes = this.processFiles.getClasses();
|
|
53
|
+
const interfaces = this.processFiles.getInterfaces();
|
|
54
|
+
const modules = this.processFiles.getModules();
|
|
55
|
+
const exports = this.processFiles.getExports();
|
|
56
|
+
|
|
57
|
+
this.processImportClauses.processImportClauses(modules, exports);
|
|
58
|
+
this.processAccesses.processAccesses(accesses);
|
|
59
|
+
this.processInvocations.processInvocations(methodsAndFunctionsWithId);
|
|
60
|
+
this.processInheritances.processInheritances(classes, interfaces);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Main method for tests
|
|
65
|
+
*
|
|
66
|
+
* @param filename The name of the file to analyze
|
|
67
|
+
* @param source A TypeScript source code
|
|
68
|
+
* @returns The Famix repository containing the Famix model
|
|
69
|
+
*/
|
|
70
|
+
// TODO: this is slow because it writes the source code to a file and then reads it again - it's possible to just pass the source code to the ts-morph project
|
|
71
|
+
public famixRepFromSource(filename: string, source: string): FamixRepository {
|
|
72
|
+
const filePath = `./test_src/${filename}.ts`;
|
|
73
|
+
|
|
74
|
+
fs.writeFileSync(filePath, source, 'utf-8');
|
|
75
|
+
|
|
76
|
+
const famixRep = this.famixRepFromPaths([filePath]);
|
|
77
|
+
|
|
78
|
+
return famixRep;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Main method for a ts-morph project
|
|
83
|
+
* @param project A ts-morph project
|
|
84
|
+
* @returns The Famix repository containing the Famix model
|
|
85
|
+
*/
|
|
86
|
+
public famixRepFromProject(project: Project): FamixRepository {
|
|
87
|
+
//const sourceFileNames = project.getSourceFiles().map(f => f.getFilePath()) as Array<string>;
|
|
88
|
+
|
|
89
|
+
//const famixRep = this.famixRepFromPaths(sourceFileNames);
|
|
90
|
+
this.processEntities(project);
|
|
91
|
+
|
|
92
|
+
return this.famixFunctions.getFamixRepository();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import { Identifier, ParameterDeclaration, VariableDeclaration, PropertyDeclaration, EnumMember } from "ts-morph";
|
|
2
|
-
import { FamixFunctions } from "../famix_functions/famix_functions";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* This class is used to build a Famix model for the accesses
|
|
6
|
-
*/
|
|
7
|
-
export class ProcessAccesses {
|
|
8
|
-
|
|
9
|
-
private famixFunctions: FamixFunctions; // FamixFunctions object, it contains all the functions needed to create Famix entities
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Initializes the ProcessAccesses object
|
|
13
|
-
* @param famixFunctions FamixFunctions object, it contains all the functions needed to create Famix entities
|
|
14
|
-
*/
|
|
15
|
-
constructor(famixFunctions: FamixFunctions) {
|
|
16
|
-
this.famixFunctions = famixFunctions;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Builds a Famix model for the accesses on the parameters, variables, properties and enum members of the source files
|
|
21
|
-
* @param accessMap A map of parameters, variables, properties and enum members with their id
|
|
22
|
-
*/
|
|
23
|
-
public processAccesses(accessMap: Map<number, ParameterDeclaration | VariableDeclaration | PropertyDeclaration | EnumMember>): void {
|
|
24
|
-
console.info(`processAccesses: Creating accesses:`);
|
|
25
|
-
accessMap.forEach((v, id) => {
|
|
26
|
-
console.info(`processAccesses: Accesses to ${v.getName()}`);
|
|
27
|
-
try {
|
|
28
|
-
const temp_nodes = v.findReferencesAsNodes() as Array<Identifier>;
|
|
29
|
-
temp_nodes.forEach(node => this.processNodeForAccesses(node, id));
|
|
30
|
-
} catch (error) {
|
|
31
|
-
console.error(`> WARNING: got exception ${error}. Continuing...`);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Builds a Famix model for an access on a parameter, variable, property or enum member
|
|
38
|
-
* @param n A node
|
|
39
|
-
* @param id An id of a parameter, a variable, a property or an enum member
|
|
40
|
-
*/
|
|
41
|
-
private processNodeForAccesses(n: Identifier, id: number): void {
|
|
42
|
-
try {
|
|
43
|
-
// sometimes node's first ancestor is a PropertyDeclaration, which is not an access
|
|
44
|
-
// see https://github.com/fuhrmanator/FamixTypeScriptImporter/issues/9
|
|
45
|
-
// check for a node whose first ancestor is a property declaration and bail?
|
|
46
|
-
// This may be a bug in ts-morph?
|
|
47
|
-
if (n.getFirstAncestorOrThrow().getKindName() === "PropertyDeclaration") {
|
|
48
|
-
console.info(`processNodeForAccesses: node kind: ${n.getKindName()}, ${n.getText()}, (${n.getType().getText()})'s first ancestor is a PropertyDeclaration. Skipping...`);
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
this.famixFunctions.createFamixAccess(n, id);
|
|
52
|
-
console.info(`processNodeForAccesses: node kind: ${n.getKindName()}, ${n.getText()}, (${n.getType().getText()})`);
|
|
53
|
-
} catch (error) {
|
|
54
|
-
console.error(`> WARNING: got exception ${error}. ScopeDeclaration invalid for ${n.getSymbol().getFullyQualifiedName()}. Continuing...`);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
1
|
+
import { Identifier, ParameterDeclaration, VariableDeclaration, PropertyDeclaration, EnumMember } from "ts-morph";
|
|
2
|
+
import { FamixFunctions } from "../famix_functions/famix_functions";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This class is used to build a Famix model for the accesses
|
|
6
|
+
*/
|
|
7
|
+
export class ProcessAccesses {
|
|
8
|
+
|
|
9
|
+
private famixFunctions: FamixFunctions; // FamixFunctions object, it contains all the functions needed to create Famix entities
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Initializes the ProcessAccesses object
|
|
13
|
+
* @param famixFunctions FamixFunctions object, it contains all the functions needed to create Famix entities
|
|
14
|
+
*/
|
|
15
|
+
constructor(famixFunctions: FamixFunctions) {
|
|
16
|
+
this.famixFunctions = famixFunctions;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Builds a Famix model for the accesses on the parameters, variables, properties and enum members of the source files
|
|
21
|
+
* @param accessMap A map of parameters, variables, properties and enum members with their id
|
|
22
|
+
*/
|
|
23
|
+
public processAccesses(accessMap: Map<number, ParameterDeclaration | VariableDeclaration | PropertyDeclaration | EnumMember>): void {
|
|
24
|
+
console.info(`processAccesses: Creating accesses:`);
|
|
25
|
+
accessMap.forEach((v, id) => {
|
|
26
|
+
console.info(`processAccesses: Accesses to ${v.getName()}`);
|
|
27
|
+
try {
|
|
28
|
+
const temp_nodes = v.findReferencesAsNodes() as Array<Identifier>;
|
|
29
|
+
temp_nodes.forEach(node => this.processNodeForAccesses(node, id));
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.error(`> WARNING: got exception ${error}. Continuing...`);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Builds a Famix model for an access on a parameter, variable, property or enum member
|
|
38
|
+
* @param n A node
|
|
39
|
+
* @param id An id of a parameter, a variable, a property or an enum member
|
|
40
|
+
*/
|
|
41
|
+
private processNodeForAccesses(n: Identifier, id: number): void {
|
|
42
|
+
try {
|
|
43
|
+
// sometimes node's first ancestor is a PropertyDeclaration, which is not an access
|
|
44
|
+
// see https://github.com/fuhrmanator/FamixTypeScriptImporter/issues/9
|
|
45
|
+
// check for a node whose first ancestor is a property declaration and bail?
|
|
46
|
+
// This may be a bug in ts-morph?
|
|
47
|
+
if (n.getFirstAncestorOrThrow().getKindName() === "PropertyDeclaration") {
|
|
48
|
+
console.info(`processNodeForAccesses: node kind: ${n.getKindName()}, ${n.getText()}, (${n.getType().getText()})'s first ancestor is a PropertyDeclaration. Skipping...`);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
this.famixFunctions.createFamixAccess(n, id);
|
|
52
|
+
console.info(`processNodeForAccesses: node kind: ${n.getKindName()}, ${n.getText()}, (${n.getType().getText()})`);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error(`> WARNING: got exception ${error}. ScopeDeclaration invalid for ${n.getSymbol().getFullyQualifiedName()}. Continuing...`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|