ts2famix 1.3.1 → 1.4.0

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.
Files changed (40) hide show
  1. package/dist/analyze.js +37 -27
  2. package/dist/analyze_functions/process_functions.js +723 -0
  3. package/dist/famix_functions/EntityDictionary.js +798 -0
  4. package/dist/famix_functions/helpers_creation.js +97 -0
  5. package/dist/fqn.js +106 -95
  6. package/dist/lib/famix/src/famix_base_element.js +8 -4
  7. package/dist/lib/famix/src/famix_repository.js +32 -15
  8. package/dist/lib/ts-complex/cyclomatic-service.js +2 -3
  9. package/doc-uml/metamodel-full.svg +1 -0
  10. package/doc-uml/metamodel.svg +1 -0
  11. package/package.json +1 -1
  12. package/plantuml.jar +0 -0
  13. package/src/analyze.ts +46 -29
  14. package/src/analyze_functions/process_functions.ts +838 -0
  15. package/src/famix_functions/EntityDictionary.ts +915 -0
  16. package/src/famix_functions/helpers_creation.ts +77 -0
  17. package/src/fqn.ts +101 -92
  18. package/src/lib/famix/src/famix_base_element.ts +9 -5
  19. package/src/lib/famix/src/famix_repository.ts +45 -23
  20. package/src/lib/ts-complex/cyclomatic-service.ts +2 -4
  21. package/src/ts2famix-cli.ts +1 -0
  22. package/dist/analyze_functions/processAccesses.js +0 -56
  23. package/dist/analyze_functions/processFiles.js +0 -554
  24. package/dist/analyze_functions/processImportClauses.js +0 -88
  25. package/dist/analyze_functions/processInheritances.js +0 -74
  26. package/dist/analyze_functions/processInvocations.js +0 -50
  27. package/dist/famix_functions/famix_functions.js +0 -523
  28. package/dist/famix_functions/famix_functions_associations.js +0 -238
  29. package/dist/famix_functions/famix_functions_index.js +0 -135
  30. package/dist/famix_functions/famix_functions_types.js +0 -115
  31. package/docs/.gitkeep +0 -0
  32. package/src/analyze_functions/processAccesses.ts +0 -58
  33. package/src/analyze_functions/processFiles.ts +0 -667
  34. package/src/analyze_functions/processImportClauses.ts +0 -95
  35. package/src/analyze_functions/processInheritances.ts +0 -85
  36. package/src/analyze_functions/processInvocations.ts +0 -52
  37. package/src/famix_functions/famix_functions.ts +0 -562
  38. package/src/famix_functions/famix_functions_associations.ts +0 -242
  39. package/src/famix_functions/famix_functions_index.ts +0 -120
  40. package/src/famix_functions/famix_functions_types.ts +0 -106
@@ -1,95 +0,0 @@
1
- import { ImportDeclaration, SourceFile, ExportedDeclarations } from "ts-morph";
2
- import { FamixFunctions } from "../famix_functions/famix_functions";
3
- import { logger } from "../analyze";
4
-
5
- /**
6
- * This class is used to build a Famix model for the import clauses
7
- */
8
- export class ProcessImportClauses {
9
-
10
- private famixFunctions: FamixFunctions; // FamixFunctions object, it contains all the functions needed to create Famix entities
11
-
12
- /**
13
- * Initializes the ProcessImportClauses object
14
- * @param famixFunctions FamixFunctions object, it contains all the functions needed to create Famix entities
15
- */
16
- constructor(famixFunctions: FamixFunctions) {
17
- this.famixFunctions = famixFunctions;
18
- }
19
-
20
- /**
21
- * Builds a Famix model for the import clauses of the source files which are modules
22
- * @param modules An array of modules
23
- * @param exports An array of maps of exported declarations
24
- */
25
- public processImportClauses(modules: Array<SourceFile>, exports: Array<ReadonlyMap<string, ExportedDeclarations[]>>): void {
26
- logger.info(`processImportClauses: Creating import clauses:`);
27
- modules.forEach(module => {
28
- module.getImportDeclarations().forEach(impDecl => {
29
- const path = this.getModulePath(impDecl);
30
-
31
- impDecl.getNamedImports().forEach(namedImport => {
32
- logger.debug(`processImportClauses: Importing (named) ${namedImport.getName()} from ${impDecl.getModuleSpecifierValue()}`);
33
- const importedEntityName = namedImport.getName();
34
- let importFoundInExports = false;
35
- exports.forEach(e => {
36
- if (e.has(importedEntityName)) {
37
- importFoundInExports = true;
38
- }
39
- });
40
- this.famixFunctions.createFamixImportClause({importDeclaration: impDecl,
41
- importer: module,
42
- moduleSpecifierFilePath: path,
43
- importElement: namedImport,
44
- isInExports: importFoundInExports,
45
- isDefaultExport: false});
46
- });
47
-
48
- const defaultImport = impDecl.getDefaultImport();
49
- if (defaultImport !== undefined) {
50
- logger.debug(`processImportClauses: Importing (default) ${defaultImport.getText()} from ${impDecl.getModuleSpecifierValue()}`);
51
- // call with module, impDecl.getModuleSpecifierValue(), path, defaultImport, false, true
52
- this.famixFunctions.createFamixImportClause({importDeclaration: impDecl,
53
- importer: module,
54
- moduleSpecifierFilePath: path,
55
- importElement: defaultImport,
56
- isInExports: false,
57
- isDefaultExport: true});
58
- }
59
-
60
- const namespaceImport = impDecl.getNamespaceImport();
61
- if (namespaceImport !== undefined) {
62
- logger.debug(`processImportClauses: Importing (namespace) ${namespaceImport.getText()} from ${impDecl.getModuleSpecifierValue()}`);
63
- this.famixFunctions.createFamixImportClause({importDeclaration: impDecl,
64
- importer: module,
65
- moduleSpecifierFilePath: path,
66
- importElement: namespaceImport,
67
- isInExports: false,
68
- isDefaultExport: false});
69
- // this.famixFunctions.createFamixImportClause(module, impDecl.getModuleSpecifierValue(), path, namespaceImport, false, false);
70
- }
71
- });
72
- });
73
- }
74
-
75
- /**
76
- * Gets the path of a module to be imported
77
- * @param i An import declaration
78
- * @returns The path of the module to be imported
79
- */
80
- private getModulePath(i: ImportDeclaration): string {
81
- let path: string;
82
- if (i.getModuleSpecifierSourceFile() === undefined) {
83
- if (i.getModuleSpecifierValue().substring(i.getModuleSpecifierValue().length - 3) === ".ts") {
84
- path = i.getModuleSpecifierValue();
85
- }
86
- else {
87
- path = i.getModuleSpecifierValue() + ".ts";
88
- }
89
- }
90
- else {
91
- path = i.getModuleSpecifierSourceFile().getFilePath();
92
- }
93
- return path;
94
- }
95
- }
@@ -1,85 +0,0 @@
1
- import { ClassDeclaration, InterfaceDeclaration, ExpressionWithTypeArguments } from "ts-morph";
2
- import { FamixFunctions } from "../famix_functions/famix_functions";
3
- import { logger } from "../analyze";
4
-
5
- /**
6
- * This class is used to build a Famix model for the inheritances
7
- */
8
- export class ProcessInheritances {
9
-
10
- private famixFunctions: FamixFunctions; // FamixFunctions object, it contains all the functions needed to create Famix entities
11
-
12
- /**
13
- * Initializes the ProcessInheritances object
14
- * @param famixFunctions FamixFunctions object, it contains all the functions needed to create Famix entities
15
- */
16
- constructor(famixFunctions: FamixFunctions) {
17
- this.famixFunctions = famixFunctions;
18
- }
19
-
20
- /**
21
- * Builds a Famix model for the inheritances of the classes and interfaces of the source files
22
- * @param classes An array of classes
23
- * @param interfaces An array of interfaces
24
- */
25
- public processInheritances(classes: ClassDeclaration[], interfaces: InterfaceDeclaration[]): void {
26
- logger.info(`processInheritances: Creating inheritances:`);
27
- classes.forEach(cls => {
28
- logger.debug(`processInheritances: Checking class inheritance for ${cls.getName()}`);
29
- const extClass = cls.getBaseClass();
30
- if (extClass !== undefined) {
31
- this.famixFunctions.createFamixInheritance(cls, extClass);
32
-
33
- logger.debug(`processInheritances: class: ${cls.getName()}, (${cls.getType().getText()}), extClass: ${extClass.getName()}, (${extClass.getType().getText()})`);
34
- }
35
-
36
- logger.debug(`processInheritances: Checking interface inheritance for ${cls.getName()}`);
37
- const implementedInterfaces = this.getImplementedOrExtendedInterfaces(interfaces, cls);
38
- implementedInterfaces.forEach(impInter => {
39
- this.famixFunctions.createFamixInheritance(cls, impInter);
40
-
41
- logger.debug(`processInheritances: class: ${cls.getName()}, (${cls.getType().getText()}), impInter: ${(impInter instanceof InterfaceDeclaration) ? impInter.getName() : impInter.getExpression().getText()}, (${(impInter instanceof InterfaceDeclaration) ? impInter.getType().getText() : impInter.getExpression().getText()})`);
42
- });
43
- });
44
-
45
- interfaces.forEach(inter => {
46
- logger.debug(`processInheritances: Checking interface inheritance for ${inter.getName()}`);
47
- const extendedInterfaces = this.getImplementedOrExtendedInterfaces(interfaces, inter);
48
- extendedInterfaces.forEach(extInter => {
49
- this.famixFunctions.createFamixInheritance(inter, extInter);
50
-
51
- logger.debug(`processInheritances: inter: ${inter.getName()}, (${inter.getType().getText()}), extInter: ${(extInter instanceof InterfaceDeclaration) ? extInter.getName() : extInter.getExpression().getText()}, (${(extInter instanceof InterfaceDeclaration) ? extInter.getType().getText() : extInter.getExpression().getText()})`);
52
- });
53
- });
54
- }
55
-
56
- /**
57
- * Gets the interfaces implemented or extended by a class or an interface
58
- * @param interfaces An array of interfaces
59
- * @param subClass A class or an interface
60
- * @returns An array of InterfaceDeclaration and ExpressionWithTypeArguments containing the interfaces implemented or extended by the subClass
61
- */
62
- private getImplementedOrExtendedInterfaces(interfaces: Array<InterfaceDeclaration>, subClass: ClassDeclaration | InterfaceDeclaration): Array<InterfaceDeclaration | ExpressionWithTypeArguments> {
63
- let impOrExtInterfaces: Array<ExpressionWithTypeArguments>;
64
- if (subClass instanceof ClassDeclaration) {
65
- impOrExtInterfaces = subClass.getImplements();
66
- }
67
- else {
68
- impOrExtInterfaces = subClass.getExtends();
69
- }
70
-
71
- const interfacesNames = interfaces.map(i => i.getName());
72
- const implementedOrExtendedInterfaces = new Array<InterfaceDeclaration | ExpressionWithTypeArguments>();
73
-
74
- impOrExtInterfaces.forEach(i => {
75
- if (interfacesNames.includes(i.getExpression().getText())) {
76
- implementedOrExtendedInterfaces.push(interfaces[interfacesNames.indexOf(i.getExpression().getText())]);
77
- }
78
- else {
79
- implementedOrExtendedInterfaces.push(i);
80
- }
81
- });
82
-
83
- return implementedOrExtendedInterfaces;
84
- }
85
- }
@@ -1,52 +0,0 @@
1
- import { MethodDeclaration, FunctionDeclaration, Identifier, ConstructorDeclaration, GetAccessorDeclaration, SetAccessorDeclaration, FunctionExpression } from "ts-morph";
2
- import { FamixFunctions } from "../famix_functions/famix_functions";
3
- import { logger } from "../analyze";
4
-
5
- /**
6
- * This class is used to build a Famix model for the invocations
7
- */
8
- export class ProcessInvocations {
9
-
10
- private famixFunctions: FamixFunctions; // FamixFunctions object, it contains all the functions needed to create Famix entities
11
-
12
- /**
13
- * Initializes the ProcessInvocations object
14
- * @param famixFunctions FamixFunctions object, it contains all the functions needed to create Famix entities
15
- */
16
- constructor(famixFunctions: FamixFunctions) {
17
- this.famixFunctions = famixFunctions;
18
- }
19
-
20
- /**
21
- * Builds a Famix model for the invocations of the methods and functions of the source files
22
- * @param methodsAndFunctionsWithId A map of methods and functions with their id
23
- */
24
- public processInvocations(methodsAndFunctionsWithId: Map<number, MethodDeclaration | ConstructorDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | FunctionDeclaration | FunctionExpression>): void {
25
- logger.info(`Creating invocations:`);
26
- methodsAndFunctionsWithId.forEach((m, id) => {
27
- logger.debug(`Invocations to ${(m instanceof MethodDeclaration || m instanceof GetAccessorDeclaration || m instanceof SetAccessorDeclaration || m instanceof FunctionDeclaration) ? m.getName() : ((m instanceof ConstructorDeclaration) ? 'constructor' : (m.getName() ? m.getName() : 'anonymous'))}`);
28
- try {
29
- const temp_nodes = m.findReferencesAsNodes() as Array<Identifier>;
30
- temp_nodes.forEach(node => this.processNodeForInvocations(node, m, id));
31
- } catch (error) {
32
- logger.error(`> WARNING: got exception ${error}. Continuing...`);
33
- }
34
- });
35
- }
36
-
37
- /**
38
- * Builds a Famix model for an invocation of a method or a function
39
- * @param n A node
40
- * @param m A method or a function
41
- * @param id The id of the method or the function
42
- */
43
- private processNodeForInvocations(n: Identifier, m: MethodDeclaration | ConstructorDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | FunctionDeclaration | FunctionExpression, id: number): void {
44
- try {
45
- this.famixFunctions.createFamixInvocation(n, m, id);
46
-
47
- logger.debug(`node: node, (${n.getType().getText()})`);
48
- } catch (error) {
49
- logger.error(`> WARNING: got exception ${error}. ScopeDeclaration invalid for ${n.getSymbol().getFullyQualifiedName()}. Continuing...`);
50
- }
51
- }
52
- }