ts2famix 1.0.11 → 1.0.12

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 (139) hide show
  1. package/.eslintrc.json +24 -24
  2. package/LICENSE +23 -23
  3. package/README.md +109 -109
  4. package/jest.config-old.ts +199 -199
  5. package/package.json +47 -47
  6. package/src/analyze.ts +94 -94
  7. package/src/analyze_functions/processAccesses.ts +57 -57
  8. package/src/analyze_functions/processFiles.ts +669 -661
  9. package/src/analyze_functions/processImportClauses.ts +77 -77
  10. package/src/analyze_functions/processInheritances.ts +84 -84
  11. package/src/analyze_functions/processInvocations.ts +51 -51
  12. package/src/famix2puml.ts +119 -119
  13. package/src/famix_functions/famix_functions.ts +559 -555
  14. package/src/famix_functions/famix_functions_associations.ts +215 -215
  15. package/src/famix_functions/famix_functions_index.ts +44 -44
  16. package/src/famix_functions/famix_functions_types.ts +105 -100
  17. package/src/generate_uml.sh +16 -16
  18. package/src/lib/famix/License.md +22 -22
  19. package/src/lib/famix/package-lock.json +301 -301
  20. package/src/lib/famix/package.json +27 -27
  21. package/src/lib/famix/readme.md +4 -4
  22. package/src/lib/famix/src/famix_JSON_exporter.ts +56 -56
  23. package/src/lib/famix/src/famix_base_element.ts +18 -18
  24. package/src/lib/famix/src/famix_repository.ts +199 -199
  25. package/src/lib/famix/src/index.ts +8 -8
  26. package/src/lib/famix/src/model/famix/access.ts +53 -53
  27. package/src/lib/famix/src/model/famix/accessor.ts +15 -15
  28. package/src/lib/famix/src/model/famix/alias.ts +41 -41
  29. package/src/lib/famix/src/model/famix/association.ts +44 -44
  30. package/src/lib/famix/src/model/famix/behavioral_entity.ts +107 -107
  31. package/src/lib/famix/src/model/famix/c_source_language.ts +15 -15
  32. package/src/lib/famix/src/model/famix/class.ts +86 -86
  33. package/src/lib/famix/src/model/famix/comment.ts +50 -50
  34. package/src/lib/famix/src/model/famix/container_entity.ts +165 -165
  35. package/src/lib/famix/src/model/famix/custom_source_language.ts +27 -27
  36. package/src/lib/famix/src/model/famix/decorator.ts +39 -39
  37. package/src/lib/famix/src/model/famix/entity.ts +15 -15
  38. package/src/lib/famix/src/model/famix/enum.ts +31 -31
  39. package/src/lib/famix/src/model/famix/enum_value.ts +29 -29
  40. package/src/lib/famix/src/model/famix/function.ts +15 -15
  41. package/src/lib/famix/src/model/famix/implicit_variable.ts +15 -15
  42. package/src/lib/famix/src/model/famix/import_clause.ts +53 -53
  43. package/src/lib/famix/src/model/famix/index.ts +42 -42
  44. package/src/lib/famix/src/model/famix/indexed_file_anchor.ts +49 -49
  45. package/src/lib/famix/src/model/famix/inheritance.ts +42 -42
  46. package/src/lib/famix/src/model/famix/interface.ts +75 -75
  47. package/src/lib/famix/src/model/famix/invocation.ts +68 -68
  48. package/src/lib/famix/src/model/famix/method.ts +96 -96
  49. package/src/lib/famix/src/model/famix/module.ts +31 -31
  50. package/src/lib/famix/src/model/famix/named_entity.ts +98 -98
  51. package/src/lib/famix/src/model/famix/namespace.ts +28 -28
  52. package/src/lib/famix/src/model/famix/parameter.ts +29 -29
  53. package/src/lib/famix/src/model/famix/parameterizable_class.ts +31 -31
  54. package/src/lib/famix/src/model/famix/parameterizable_interface.ts +31 -31
  55. package/src/lib/famix/src/model/famix/parameterized_type.ts +40 -40
  56. package/src/lib/famix/src/model/famix/primitive_type.ts +15 -15
  57. package/src/lib/famix/src/model/famix/property.ts +54 -54
  58. package/src/lib/famix/src/model/famix/reference.ts +42 -42
  59. package/src/lib/famix/src/model/famix/scoping_entity.ts +31 -31
  60. package/src/lib/famix/src/model/famix/script_entity.ts +38 -38
  61. package/src/lib/famix/src/model/famix/source_anchor.ts +31 -31
  62. package/src/lib/famix/src/model/famix/source_language.ts +31 -31
  63. package/src/lib/famix/src/model/famix/sourced_entity.ts +70 -70
  64. package/src/lib/famix/src/model/famix/structural_entity.ts +44 -44
  65. package/src/lib/famix/src/model/famix/text_anchor.ts +49 -49
  66. package/src/lib/famix/src/model/famix/type.ts +88 -88
  67. package/src/lib/famix/src/model/famix/type_parameter.ts +33 -33
  68. package/src/lib/famix/src/model/famix/variable.ts +28 -28
  69. package/src/lib/famix/tsconfig.json +26 -26
  70. package/src/lib/famix/tslint.json +14 -14
  71. package/src/lib/ts-complex/cyclomatic-service.ts +85 -85
  72. package/src/ts2famix-cli.ts +39 -39
  73. package/tsconfig.json +69 -69
  74. package/dist/analyze.js +0 -102
  75. package/dist/analyze_functions/processAccesses.js +0 -47
  76. package/dist/analyze_functions/processFiles.js +0 -540
  77. package/dist/analyze_functions/processImportClauses.js +0 -70
  78. package/dist/analyze_functions/processInheritances.js +0 -73
  79. package/dist/analyze_functions/processInvocations.js +0 -49
  80. package/dist/famix2puml.js +0 -125
  81. package/dist/famix_functions/famix_functions.js +0 -513
  82. package/dist/famix_functions/famix_functions_associations.js +0 -205
  83. package/dist/famix_functions/famix_functions_index.js +0 -62
  84. package/dist/famix_functions/famix_functions_types.js +0 -110
  85. package/dist/fqn.js +0 -126
  86. package/dist/fqp_implementation.js +0 -73
  87. package/dist/lib/famix/src/famix_JSON_exporter.js +0 -54
  88. package/dist/lib/famix/src/famix_base_element.js +0 -13
  89. package/dist/lib/famix/src/famix_repository.js +0 -187
  90. package/dist/lib/famix/src/index.js +0 -30
  91. package/dist/lib/famix/src/model/famix/access.js +0 -39
  92. package/dist/lib/famix/src/model/famix/accessor.js +0 -16
  93. package/dist/lib/famix/src/model/famix/alias.js +0 -32
  94. package/dist/lib/famix/src/model/famix/association.js +0 -36
  95. package/dist/lib/famix/src/model/famix/behavioral_entity.js +0 -81
  96. package/dist/lib/famix/src/model/famix/c_source_language.js +0 -16
  97. package/dist/lib/famix/src/model/famix/class.js +0 -70
  98. package/dist/lib/famix/src/model/famix/comment.js +0 -38
  99. package/dist/lib/famix/src/model/famix/container_entity.js +0 -125
  100. package/dist/lib/famix/src/model/famix/custom_source_language.js +0 -23
  101. package/dist/lib/famix/src/model/famix/decorator.js +0 -31
  102. package/dist/lib/famix/src/model/famix/entity.js +0 -16
  103. package/dist/lib/famix/src/model/famix/enum.js +0 -30
  104. package/dist/lib/famix/src/model/famix/enum_value.js +0 -24
  105. package/dist/lib/famix/src/model/famix/function.js +0 -16
  106. package/dist/lib/famix/src/model/famix/implicit_variable.js +0 -16
  107. package/dist/lib/famix/src/model/famix/import_clause.js +0 -39
  108. package/dist/lib/famix/src/model/famix/index.js +0 -87
  109. package/dist/lib/famix/src/model/famix/indexed_file_anchor.js +0 -37
  110. package/dist/lib/famix/src/model/famix/inheritance.js +0 -32
  111. package/dist/lib/famix/src/model/famix/interface.js +0 -63
  112. package/dist/lib/famix/src/model/famix/invocation.js +0 -53
  113. package/dist/lib/famix/src/model/famix/method.js +0 -66
  114. package/dist/lib/famix/src/model/famix/module.js +0 -30
  115. package/dist/lib/famix/src/model/famix/named_entity.js +0 -77
  116. package/dist/lib/famix/src/model/famix/namespace.js +0 -24
  117. package/dist/lib/famix/src/model/famix/parameter.js +0 -24
  118. package/dist/lib/famix/src/model/famix/parameterizable_class.js +0 -30
  119. package/dist/lib/famix/src/model/famix/parameterizable_interface.js +0 -30
  120. package/dist/lib/famix/src/model/famix/parameterized_type.js +0 -36
  121. package/dist/lib/famix/src/model/famix/primitive_type.js +0 -16
  122. package/dist/lib/famix/src/model/famix/property.js +0 -44
  123. package/dist/lib/famix/src/model/famix/reference.js +0 -32
  124. package/dist/lib/famix/src/model/famix/scoping_entity.js +0 -30
  125. package/dist/lib/famix/src/model/famix/script_entity.js +0 -30
  126. package/dist/lib/famix/src/model/famix/source_anchor.js +0 -26
  127. package/dist/lib/famix/src/model/famix/source_language.js +0 -30
  128. package/dist/lib/famix/src/model/famix/sourced_entity.js +0 -55
  129. package/dist/lib/famix/src/model/famix/structural_entity.js +0 -38
  130. package/dist/lib/famix/src/model/famix/text_anchor.js +0 -37
  131. package/dist/lib/famix/src/model/famix/type.js +0 -71
  132. package/dist/lib/famix/src/model/famix/type_parameter.js +0 -24
  133. package/dist/lib/famix/src/model/famix/variable.js +0 -23
  134. package/dist/lib/ts-complex/cyclomatic-service.js +0 -83
  135. package/dist/ts2famix-cli.js +0 -63
  136. package/dist/ts2famix-tsconfig.js +0 -53
  137. package/metrics.ts +0 -23
  138. package/output.debug.txt +0 -1351
  139. package/src/fqp_implementation.ts +0 -66
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ProcessInvocations = void 0;
4
- const ts_morph_1 = require("ts-morph");
5
- /**
6
- * This class is used to build a Famix model for the invocations
7
- */
8
- class ProcessInvocations {
9
- /**
10
- * Initializes the ProcessInvocations object
11
- * @param famixFunctions FamixFunctions object, it contains all the functions needed to create Famix entities
12
- */
13
- constructor(famixFunctions) {
14
- this.famixFunctions = famixFunctions;
15
- }
16
- /**
17
- * Builds a Famix model for the invocations of the methods and functions of the source files
18
- * @param methodsAndFunctionsWithId A map of methods and functions with their id
19
- */
20
- processInvocations(methodsAndFunctionsWithId) {
21
- console.info(`Creating invocations:`);
22
- methodsAndFunctionsWithId.forEach((m, id) => {
23
- console.info(`Invocations to ${(m instanceof ts_morph_1.MethodDeclaration || m instanceof ts_morph_1.GetAccessorDeclaration || m instanceof ts_morph_1.SetAccessorDeclaration || m instanceof ts_morph_1.FunctionDeclaration) ? m.getName() : ((m instanceof ts_morph_1.ConstructorDeclaration) ? 'constructor' : (m.getName() ? m.getName() : 'anonymous'))}`);
24
- try {
25
- const temp_nodes = m.findReferencesAsNodes();
26
- temp_nodes.forEach(node => this.processNodeForInvocations(node, m, id));
27
- }
28
- catch (error) {
29
- console.error(`> WARNING: got exception ${error}. Continuing...`);
30
- }
31
- });
32
- }
33
- /**
34
- * Builds a Famix model for an invocation of a method or a function
35
- * @param n A node
36
- * @param m A method or a function
37
- * @param id The id of the method or the function
38
- */
39
- processNodeForInvocations(n, m, id) {
40
- try {
41
- this.famixFunctions.createFamixInvocation(n, m, id);
42
- console.info(`node: node, (${n.getType().getText()})`);
43
- }
44
- catch (error) {
45
- console.error(`> WARNING: got exception ${error}. ScopeDeclaration invalid for ${n.getSymbol().getFullyQualifiedName()}. Continuing...`);
46
- }
47
- }
48
- }
49
- exports.ProcessInvocations = ProcessInvocations;
@@ -1,125 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const fs = __importStar(require("fs"));
30
- const yargs_1 = __importDefault(require("yargs"));
31
- const argv = yargs_1.default
32
- .example('ts-node src/famix2puml.ts -i JSONModels/projectName.json -o PUMLModels/projectName.puml', 'creates a PlantUML class diagram from a JSON-format model of a typescript project')
33
- .alias('i', 'input')
34
- .nargs('i', 1)
35
- .alias('o', 'output')
36
- .nargs('o', 1)
37
- .demandOption('input').demandOption('output').parseSync();
38
- const INHERITANCE_LINK_COLOR = 'blue';
39
- const jsonFileName = argv.input;
40
- const pumlFileName = argv.output.substring(argv.output.indexOf("/") + 1, argv.output.lastIndexOf('.'));
41
- const parsedModel = JSON.parse(fs.readFileSync(jsonFileName, 'utf-8'));
42
- const classNameMap = new Map();
43
- const associations = new Array();
44
- // maps all class names to their id
45
- parsedModel.forEach(element => {
46
- // map has id as key and unique (plantuml) class name
47
- classNameMap.set(element.id, uniqueElementName(element));
48
- const nameWithoutPrefix = element.FM3.split('.')[1];
49
- // special case association
50
- if (nameWithoutPrefix.endsWith('Inheritance')) {
51
- const subclass = element['subclass'].ref;
52
- const superclass = element['superclass'].ref;
53
- associations.push({ from: subclass, to: superclass, name: nameWithoutPrefix });
54
- }
55
- });
56
- // generates plantuml
57
- let plantUMLOutString = `@startuml ${pumlFileName}
58
- skinparam style strictuml
59
- title Object diagram for ${jsonFileName}
60
- `;
61
- parsedModel.forEach(element => {
62
- plantUMLOutString += `${toPlantUML(element)}\n`;
63
- });
64
- // creates associations
65
- associations.forEach(association => {
66
- // inheritance is a special case, show it in UML even though it doesn't make 100% sense in object diagrams
67
- const isInheritance = association.name.startsWith('Inheritance');
68
- if (isInheritance) {
69
- plantUMLOutString += `${classNameMap.get(association.from)} --|> ${classNameMap.get(association.to)} #line:${INHERITANCE_LINK_COLOR}\n`;
70
- }
71
- else {
72
- plantUMLOutString += `${classNameMap.get(association.from)} ..> "${association.name}" ${classNameMap.get(association.to)}\n`;
73
- }
74
- });
75
- plantUMLOutString += '@enduml';
76
- // writes to output file
77
- fs.writeFile(argv.output, plantUMLOutString, (err) => {
78
- if (err) {
79
- throw err;
80
- }
81
- });
82
- function uniqueElementName(element) {
83
- return `${element.FM3}${element.id}`;
84
- }
85
- function toPlantUML(element) {
86
- let plantUMLString = '';
87
- const optionalName = element.name || '';
88
- const nameWithoutPrefix = element.FM3.split('.')[1];
89
- plantUMLString += `object "${optionalName}:${nameWithoutPrefix}" as ${uniqueElementName(element)} {\n`;
90
- plantUMLString += `id = ${element.id}\n`;
91
- plantUMLString += propertiesToPlantUML(element);
92
- plantUMLString += '}\n';
93
- return plantUMLString;
94
- }
95
- function propertiesToPlantUML(element) {
96
- let plantUMLString = '';
97
- for (const property in element) {
98
- const attribute = element[property];
99
- const isOneToManyReference = typeof attribute !== 'string' && attribute.length; // array but not a string
100
- switch (property) {
101
- // ignores these properties
102
- case 'subclass':
103
- case 'superclass':
104
- case 'FM3':
105
- case 'id':
106
- case 'name':
107
- break;
108
- default:
109
- if (isOneToManyReference) {
110
- attribute.forEach((composite, index) => {
111
- associations.push({ from: element.id, to: composite.ref, name: `${property}[${index}]` });
112
- });
113
- }
114
- else if (typeof attribute === 'object') {
115
- associations.push({ from: element.id, to: attribute.ref, name: property });
116
- }
117
- else { // typeof string, boolean, number, etc
118
- // treats it as a simple attribute
119
- plantUMLString += `${property} = ${element[property]}\n`;
120
- }
121
- break;
122
- }
123
- }
124
- return plantUMLString;
125
- }
@@ -1,513 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.FamixFunctions = void 0;
27
- const ts_morph_1 = require("ts-morph");
28
- const Famix = __importStar(require("../lib/famix/src/model/famix"));
29
- const famix_repository_1 = require("../lib/famix/src/famix_repository");
30
- const fqn_1 = require("../fqn");
31
- const famix_functions_index_1 = require("./famix_functions_index");
32
- const famix_functions_associations_1 = require("./famix_functions_associations");
33
- const famix_functions_types_1 = require("./famix_functions_types");
34
- /**
35
- * This class contains all the functions needed to create Famix entities
36
- */
37
- class FamixFunctions {
38
- constructor() {
39
- this.famixRep = new famix_repository_1.FamixRepository(); // The Famix repository
40
- this.FQNFunctions = new fqn_1.FQNFunctions(); // The fully qualified name functions
41
- this.fmxAliases = new Map(); // Maps the alias names to their Famix model
42
- this.fmxClasses = new Map(); // Maps the class names to their Famix model
43
- this.fmxInterfaces = new Map(); // Maps the interface names to their Famix model
44
- this.fmxNamespaces = new Map(); // Maps the namespace names to their Famix model
45
- this.fmxFiles = new Map(); // Maps the source file names to their Famix model
46
- this.famixFunctionsIndex = new famix_functions_index_1.FamixFunctionsIndex(this.famixRep); // FamixFunctionsIndex object, it contains all the functions needed to create Famix index file anchors
47
- this.famixFunctionsAssociations = new famix_functions_associations_1.FamixFunctionsAssociations(this.famixRep, this.fmxClasses, this.fmxInterfaces); // FamixFunctionsAssociations object, it contains all the functions needed to create Famix associations
48
- this.famixFunctionsTypes = new famix_functions_types_1.FamixFunctionsTypes(this.famixRep); // FamixFunctionsTypes object, it contains all the functions needed to create Famix types
49
- this.UNKNOWN_VALUE = '(unknown due to parsing error)'; // The value to use when a name is not usable
50
- }
51
- /**
52
- * Gets the Famix repository
53
- * @returns The Famix repository
54
- */
55
- getFamixRepository() {
56
- return this.famixRep;
57
- }
58
- /**
59
- * Creates or gets a Famix script entity or module
60
- * @param f A source file
61
- * @param isModule A boolean indicating if the source file is a module
62
- * @returns The Famix model of the source file
63
- */
64
- createOrGetFamixFile(f, isModule) {
65
- let fmxFile;
66
- const fileName = f.getBaseName();
67
- if (!this.fmxFiles.has(fileName)) {
68
- if (isModule) {
69
- fmxFile = new Famix.Module(this.famixRep);
70
- }
71
- else {
72
- fmxFile = new Famix.ScriptEntity(this.famixRep);
73
- }
74
- fmxFile.setName(fileName);
75
- fmxFile.setNumberOfLinesOfText(f.getEndLineNumber() - f.getStartLineNumber());
76
- fmxFile.setNumberOfCharacters(f.getFullText().length);
77
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(f, fmxFile);
78
- this.fmxFiles.set(fileName, fmxFile);
79
- }
80
- else {
81
- fmxFile = this.fmxFiles.get(fileName);
82
- }
83
- return fmxFile;
84
- }
85
- /**
86
- * Creates or gets a Famix namespace
87
- * @param m A namespace
88
- * @returns The Famix model of the namespace
89
- */
90
- createOrGetFamixNamespace(m) {
91
- let fmxNamespace;
92
- const namespaceName = m.getName();
93
- if (!this.fmxNamespaces.has(namespaceName)) {
94
- fmxNamespace = new Famix.Namespace(this.famixRep);
95
- fmxNamespace.setName(namespaceName);
96
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(m, fmxNamespace);
97
- this.fmxNamespaces.set(namespaceName, fmxNamespace);
98
- }
99
- else {
100
- fmxNamespace = this.fmxNamespaces.get(namespaceName);
101
- }
102
- return fmxNamespace;
103
- }
104
- /**
105
- * Creates a Famix alias
106
- * @param a An alias
107
- * @returns The Famix model of the alias
108
- */
109
- createFamixAlias(a) {
110
- let fmxAlias;
111
- const aliasName = a.getName();
112
- if (!this.fmxAliases.has(aliasName)) {
113
- fmxAlias = new Famix.Alias(this.famixRep);
114
- fmxAlias.setName(a.getName());
115
- const fmxType = this.createOrGetFamixType(aliasName, a);
116
- fmxAlias.setAliasedEntity(fmxType);
117
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(a, fmxAlias);
118
- this.fmxAliases.set(aliasName, fmxAlias);
119
- }
120
- else {
121
- fmxAlias = this.fmxAliases.get(aliasName);
122
- }
123
- return fmxAlias;
124
- }
125
- /**
126
- * Creates or gets a Famix class or parameterizable class
127
- * @param cls A class
128
- * @returns The Famix model of the class
129
- */
130
- createOrGetFamixClass(cls) {
131
- let fmxClass;
132
- const isAbstract = cls.isAbstract();
133
- const clsName = cls.getName();
134
- if (!this.fmxClasses.has(clsName)) {
135
- const isGeneric = cls.getTypeParameters().length;
136
- if (isGeneric) {
137
- fmxClass = new Famix.ParameterizableClass(this.famixRep);
138
- }
139
- else {
140
- fmxClass = new Famix.Class(this.famixRep);
141
- }
142
- fmxClass.setName(clsName);
143
- fmxClass.setIsAbstract(isAbstract);
144
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(cls, fmxClass);
145
- this.fmxClasses.set(clsName, fmxClass);
146
- }
147
- else {
148
- fmxClass = this.fmxClasses.get(clsName);
149
- }
150
- return fmxClass;
151
- }
152
- /**
153
- * Creates or gets a Famix interface or parameterizable interface
154
- * @param inter An interface
155
- * @returns The Famix model of the interface
156
- */
157
- createOrGetFamixInterface(inter) {
158
- let fmxInterface;
159
- const interName = inter.getName();
160
- if (!this.fmxInterfaces.has(interName)) {
161
- const isGeneric = inter.getTypeParameters().length;
162
- if (isGeneric) {
163
- fmxInterface = new Famix.ParameterizableInterface(this.famixRep);
164
- }
165
- else {
166
- fmxInterface = new Famix.Interface(this.famixRep);
167
- }
168
- fmxInterface.setName(interName);
169
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(inter, fmxInterface);
170
- this.fmxInterfaces.set(interName, fmxInterface);
171
- }
172
- else {
173
- fmxInterface = this.fmxInterfaces.get(interName);
174
- }
175
- return fmxInterface;
176
- }
177
- /**
178
- * Creates a Famix property
179
- * @param property A property
180
- * @returns The Famix model of the property
181
- */
182
- createFamixProperty(property) {
183
- const fmxProperty = new Famix.Property(this.famixRep);
184
- const isSignature = property instanceof ts_morph_1.PropertySignature;
185
- fmxProperty.setName(property.getName());
186
- let propTypeName = this.UNKNOWN_VALUE;
187
- try {
188
- propTypeName = property.getType().getText().trim();
189
- }
190
- catch (error) {
191
- console.error(`> WARNING: got exception ${error}. Failed to get usable name for property: ${property.getName()}. Continuing...`);
192
- }
193
- const fmxType = this.createOrGetFamixType(propTypeName, property);
194
- fmxProperty.setDeclaredType(fmxType);
195
- property.getModifiers().forEach(m => fmxProperty.addModifier(m.getText()));
196
- if (!isSignature && property.getExclamationTokenNode()) {
197
- fmxProperty.addModifier("!");
198
- }
199
- if (property.getQuestionTokenNode()) {
200
- fmxProperty.addModifier("?");
201
- }
202
- if (property.getName().substring(0, 1) === "#") {
203
- fmxProperty.addModifier("#");
204
- }
205
- if (fmxProperty.getModifiers().has("static")) {
206
- fmxProperty.setIsClassSide(true);
207
- }
208
- else {
209
- fmxProperty.setIsClassSide(false);
210
- }
211
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(property, fmxProperty);
212
- return fmxProperty;
213
- }
214
- /**
215
- * Creates a Famix method or accessor
216
- * @param method A method or an accessor
217
- * @param currentCC The cyclomatic complexity metrics of the current source file
218
- * @returns The Famix model of the method or the accessor
219
- */
220
- createFamixMethod(method, currentCC) {
221
- let fmxMethod;
222
- if (method instanceof ts_morph_1.GetAccessorDeclaration || method instanceof ts_morph_1.SetAccessorDeclaration) {
223
- fmxMethod = new Famix.Accessor(this.famixRep);
224
- const isGetter = method instanceof ts_morph_1.GetAccessorDeclaration;
225
- const isSetter = method instanceof ts_morph_1.SetAccessorDeclaration;
226
- if (isGetter) {
227
- fmxMethod.setKind("getter");
228
- }
229
- if (isSetter) {
230
- fmxMethod.setKind("setter");
231
- }
232
- }
233
- else {
234
- fmxMethod = new Famix.Method(this.famixRep);
235
- }
236
- const isConstructor = method instanceof ts_morph_1.ConstructorDeclaration;
237
- const isSignature = method instanceof ts_morph_1.MethodSignature;
238
- const isGeneric = method.getTypeParameters().length > 0;
239
- fmxMethod.setIsGeneric(isGeneric);
240
- let isAbstract = false;
241
- let isStatic = false;
242
- if (method instanceof ts_morph_1.MethodDeclaration || method instanceof ts_morph_1.GetAccessorDeclaration || method instanceof ts_morph_1.SetAccessorDeclaration) {
243
- isAbstract = method.isAbstract();
244
- isStatic = method.isStatic();
245
- }
246
- if (isConstructor) {
247
- fmxMethod.setKind("constructor");
248
- }
249
- fmxMethod.setIsAbstract(isAbstract);
250
- fmxMethod.setIsClassSide(isStatic);
251
- fmxMethod.setIsPrivate((method instanceof ts_morph_1.MethodDeclaration || method instanceof ts_morph_1.GetAccessorDeclaration || method instanceof ts_morph_1.SetAccessorDeclaration) ? (method.getModifiers().find(x => x.getText() === 'private')) !== undefined : false);
252
- fmxMethod.setIsProtected((method instanceof ts_morph_1.MethodDeclaration || method instanceof ts_morph_1.GetAccessorDeclaration || method instanceof ts_morph_1.SetAccessorDeclaration) ? (method.getModifiers().find(x => x.getText() === 'protected')) !== undefined : false);
253
- fmxMethod.setSignature(this.computeSignature(method.getText()));
254
- let methodName;
255
- if (isConstructor) {
256
- methodName = "constructor";
257
- }
258
- else {
259
- methodName = method.getName();
260
- }
261
- fmxMethod.setName(methodName);
262
- if (!isConstructor) {
263
- if (method.getName().substring(0, 1) === "#") {
264
- fmxMethod.setIsPrivate(true);
265
- }
266
- }
267
- if (!fmxMethod.getIsPrivate() && !fmxMethod.getIsProtected()) {
268
- fmxMethod.setIsPublic(true);
269
- }
270
- else {
271
- fmxMethod.setIsPublic(false);
272
- }
273
- if (!isSignature) {
274
- fmxMethod.setCyclomaticComplexity(currentCC[fmxMethod.getName()]);
275
- }
276
- else {
277
- fmxMethod.setCyclomaticComplexity(0);
278
- }
279
- let methodTypeName = this.UNKNOWN_VALUE;
280
- try {
281
- methodTypeName = method.getReturnType().getText().trim();
282
- }
283
- catch (error) {
284
- console.error(`> WARNING: got exception ${error}. Failed to get usable name for return type of method: ${fmxMethod.getName()}. Continuing...`);
285
- }
286
- const fmxType = this.createOrGetFamixType(methodTypeName, method);
287
- fmxMethod.setDeclaredType(fmxType);
288
- fmxMethod.setNumberOfLinesOfCode(method.getEndLineNumber() - method.getStartLineNumber());
289
- const parameters = method.getParameters();
290
- fmxMethod.setNumberOfParameters(parameters.length);
291
- if (!isSignature) {
292
- fmxMethod.setNumberOfStatements(method.getStatements().length);
293
- }
294
- else {
295
- fmxMethod.setNumberOfStatements(0);
296
- }
297
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(method, fmxMethod);
298
- return fmxMethod;
299
- }
300
- /**
301
- * Creates a Famix function
302
- * @param func A function
303
- * @param currentCC The cyclomatic complexity metrics of the current source file
304
- * @returns The Famix model of the function
305
- */
306
- createFamixFunction(func, currentCC) {
307
- const fmxFunction = new Famix.Function(this.famixRep);
308
- if (func.getName()) {
309
- fmxFunction.setName(func.getName());
310
- }
311
- else {
312
- fmxFunction.setName("anonymous");
313
- }
314
- fmxFunction.setSignature(this.computeSignature(func.getText()));
315
- fmxFunction.setCyclomaticComplexity(currentCC[fmxFunction.getName()]);
316
- const isGeneric = func.getTypeParameters().length > 0;
317
- fmxFunction.setIsGeneric(isGeneric);
318
- let functionTypeName = this.UNKNOWN_VALUE;
319
- try {
320
- functionTypeName = func.getReturnType().getText().trim();
321
- }
322
- catch (error) {
323
- console.error(`> WARNING: got exception ${error}. Failed to get usable name for return type of function: ${func.getName()}. Continuing...`);
324
- }
325
- const fmxType = this.createOrGetFamixType(functionTypeName, func);
326
- fmxFunction.setDeclaredType(fmxType);
327
- fmxFunction.setNumberOfLinesOfCode(func.getEndLineNumber() - func.getStartLineNumber());
328
- const parameters = func.getParameters();
329
- fmxFunction.setNumberOfParameters(parameters.length);
330
- fmxFunction.setNumberOfStatements(func.getStatements().length);
331
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(func, fmxFunction);
332
- return fmxFunction;
333
- }
334
- /**
335
- * Creates a Famix parameter
336
- * @param param A parameter
337
- * @returns The Famix model of the parameter
338
- */
339
- createFamixParameter(param) {
340
- const fmxParam = new Famix.Parameter(this.famixRep);
341
- let paramTypeName = this.UNKNOWN_VALUE;
342
- try {
343
- paramTypeName = param.getType().getText().trim();
344
- }
345
- catch (error) {
346
- console.error(`> WARNING: got exception ${error}. Failed to get usable name for parameter: ${param.getName()}. Continuing...`);
347
- }
348
- const fmxType = this.createOrGetFamixType(paramTypeName, param);
349
- fmxParam.setDeclaredType(fmxType);
350
- fmxParam.setName(param.getName());
351
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(param, fmxParam);
352
- return fmxParam;
353
- }
354
- /**
355
- * Creates a Famix type parameter
356
- * @param tp A type parameter
357
- * @returns The Famix model of the type parameter
358
- */
359
- createFamixTypeParameter(tp) {
360
- const fmxTypeParameter = new Famix.TypeParameter(this.famixRep);
361
- fmxTypeParameter.setName(tp.getName());
362
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(tp, fmxTypeParameter);
363
- return fmxTypeParameter;
364
- }
365
- /**
366
- * Creates a Famix variable
367
- * @param variable A variable
368
- * @returns The Famix model of the variable
369
- */
370
- createFamixVariable(variable) {
371
- const fmxVariable = new Famix.Variable(this.famixRep);
372
- let variableTypeName = this.UNKNOWN_VALUE;
373
- try {
374
- variableTypeName = variable.getType().getText().trim();
375
- }
376
- catch (error) {
377
- console.error(`> WARNING: got exception ${error}. Failed to get usable name for variable: ${variable.getName()}. Continuing...`);
378
- }
379
- const fmxType = this.createOrGetFamixType(variableTypeName, variable);
380
- fmxVariable.setDeclaredType(fmxType);
381
- fmxVariable.setName(variable.getName());
382
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(variable, fmxVariable);
383
- return fmxVariable;
384
- }
385
- /**
386
- * Creates a Famix enum
387
- * @param enumEntity An enum
388
- * @returns The Famix model of the enum
389
- */
390
- createFamixEnum(enumEntity) {
391
- const fmxEnum = new Famix.Enum(this.famixRep);
392
- fmxEnum.setName(enumEntity.getName());
393
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(enumEntity, fmxEnum);
394
- return fmxEnum;
395
- }
396
- /**
397
- * Creates a Famix enum value
398
- * @param enumMember An enum member
399
- * @returns The Famix model of the enum member
400
- */
401
- createFamixEnumValue(enumMember) {
402
- const fmxEnumValue = new Famix.EnumValue(this.famixRep);
403
- let enumValueTypeName = this.UNKNOWN_VALUE;
404
- try {
405
- enumValueTypeName = enumMember.getType().getText().trim();
406
- }
407
- catch (error) {
408
- console.error(`> WARNING: got exception ${error}. Failed to get usable name for enum value: ${enumMember.getName()}. Continuing...`);
409
- }
410
- const fmxType = this.createOrGetFamixType(enumValueTypeName, enumMember);
411
- fmxEnumValue.setDeclaredType(fmxType);
412
- fmxEnumValue.setName(enumMember.getName());
413
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(enumMember, fmxEnumValue);
414
- return fmxEnumValue;
415
- }
416
- /**
417
- * Creates or gets a Famix decorator
418
- * @param decorator A decorator
419
- * @param decoratedEntity A class, a method, a parameter or a property
420
- * @returns The Famix model of the decorator
421
- */
422
- createOrGetFamixDecorator(decorator, decoratedEntity) {
423
- const fmxDecorator = new Famix.Decorator(this.famixRep);
424
- const decoratorName = "@" + decorator.getName();
425
- const decoratorExpression = decorator.getText().substring(1);
426
- fmxDecorator.setName(decoratorName);
427
- fmxDecorator.setDecoratorExpression(decoratorExpression);
428
- const decoratedEntityFullyQualifiedName = this.FQNFunctions.getFQN(decoratedEntity);
429
- const fmxDecoratedEntity = this.getFamixEntityByFullyQualifiedName(decoratedEntityFullyQualifiedName);
430
- fmxDecorator.setDecoratedEntity(fmxDecoratedEntity);
431
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(decorator, fmxDecorator);
432
- return fmxDecorator;
433
- }
434
- /**
435
- * Creates a Famix comment
436
- * @param comment A comment
437
- * @param fmxScope The Famix model of the comment's container
438
- * @param isJSDoc A boolean indicating if the comment is a JSDoc
439
- * @returns The Famix model of the comment
440
- */
441
- createFamixComment(comment, fmxScope, isJSDoc) {
442
- const fmxComment = new Famix.Comment(this.famixRep);
443
- fmxComment.setContent(comment.getText());
444
- fmxComment.setContainer(fmxScope);
445
- fmxComment.setIsJSDoc(isJSDoc);
446
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(comment, fmxComment);
447
- return fmxComment;
448
- }
449
- /**
450
- * Creates or gets a Famix type
451
- * @param typeName A type name
452
- * @param element A ts-morph element
453
- * @returns The Famix model of the type
454
- */
455
- createOrGetFamixType(typeName, element) {
456
- return this.famixFunctionsTypes.createOrGetFamixType(typeName, element);
457
- }
458
- /**
459
- * Creates a Famix access
460
- * @param node A node
461
- * @param id An id of a parameter, a variable, a property or an enum member
462
- */
463
- createFamixAccess(node, id) {
464
- this.famixFunctionsAssociations.createFamixAccess(node, id);
465
- }
466
- /**
467
- * Creates a Famix invocation
468
- * @param node A node
469
- * @param m A method or a function
470
- * @param id The id of the method or the function
471
- */
472
- createFamixInvocation(node, m, id) {
473
- this.famixFunctionsAssociations.createFamixInvocation(node, m, id);
474
- }
475
- /**
476
- * Creates a Famix inheritance
477
- * @param cls A class or an interface (subclass)
478
- * @param inhClass The inherited class or interface (superclass)
479
- */
480
- createFamixInheritance(cls, inhClass) {
481
- this.famixFunctionsAssociations.createFamixInheritance(cls, inhClass);
482
- }
483
- /**
484
- * Creates a Famix import clause
485
- * @param importer A source file which is a module
486
- * @param moduleSpecifier The name of the module where the export declaration is
487
- * @param moduleSpecifierFilePath The path of the module where the export declaration is
488
- * @param importElement The imported entity
489
- * @param isInExports A boolean indicating if the imported entity is in the exports
490
- * @param isDefaultExport A boolean indicating if the imported entity is a default export
491
- */
492
- createFamixImportClause(importer, moduleSpecifier, moduleSpecifierFilePath, importElement, isInExports, isDefaultExport) {
493
- this.famixFunctionsAssociations.createFamixImportClause(importer, moduleSpecifier, moduleSpecifierFilePath, importElement, isInExports, isDefaultExport);
494
- }
495
- /**
496
- * Gets a Famix entity by fully qualified name
497
- * @param fullyQualifiedName A fully qualified name
498
- * @returns The Famix entity corresponding to the fully qualified name
499
- */
500
- getFamixEntityByFullyQualifiedName(fullyQualifiedName) {
501
- return this.famixRep.getFamixEntityByFullyQualifiedName(fullyQualifiedName);
502
- }
503
- /**
504
- * Gets the signature of a method or a function
505
- * @param text A method or a function source code
506
- * @returns The signature of the method or the function
507
- */
508
- computeSignature(text) {
509
- const endSignatureText = text.indexOf("{");
510
- return text.substring(0, endSignatureText).trim();
511
- }
512
- }
513
- exports.FamixFunctions = FamixFunctions;