ts2famix 1.0.1 → 1.0.4

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 (121) hide show
  1. package/dist/analyze.js +102 -0
  2. package/dist/analyze_functions/processAccesses.js +47 -0
  3. package/dist/analyze_functions/processFiles.js +540 -0
  4. package/dist/analyze_functions/processImportClauses.js +70 -0
  5. package/dist/analyze_functions/processInheritances.js +73 -0
  6. package/dist/analyze_functions/processInvocations.js +49 -0
  7. package/dist/famix2puml.js +125 -0
  8. package/dist/famix_functions/famix_functions.js +513 -0
  9. package/dist/famix_functions/famix_functions_associations.js +205 -0
  10. package/dist/famix_functions/famix_functions_index.js +62 -0
  11. package/dist/famix_functions/famix_functions_types.js +110 -0
  12. package/dist/fqn.js +126 -0
  13. package/dist/fqp_implementation.js +73 -0
  14. package/dist/lib/famix/src/famix_JSON_exporter.js +54 -0
  15. package/dist/lib/famix/src/famix_base_element.js +13 -0
  16. package/dist/lib/famix/src/famix_repository.js +187 -0
  17. package/dist/lib/famix/src/index.js +30 -0
  18. package/dist/lib/famix/src/model/famix/access.js +39 -0
  19. package/dist/lib/famix/src/model/famix/accessor.js +16 -0
  20. package/dist/lib/famix/src/model/famix/alias.js +32 -0
  21. package/dist/lib/famix/src/model/famix/association.js +36 -0
  22. package/dist/lib/famix/src/model/famix/behavioral_entity.js +81 -0
  23. package/dist/lib/famix/src/model/famix/c_source_language.js +16 -0
  24. package/dist/lib/famix/src/model/famix/class.js +70 -0
  25. package/dist/lib/famix/src/model/famix/comment.js +38 -0
  26. package/dist/lib/famix/src/model/famix/container_entity.js +125 -0
  27. package/dist/lib/famix/src/model/famix/custom_source_language.js +23 -0
  28. package/dist/lib/famix/src/model/famix/decorator.js +31 -0
  29. package/dist/lib/famix/src/model/famix/entity.js +16 -0
  30. package/dist/lib/famix/src/model/famix/enum.js +30 -0
  31. package/dist/lib/famix/src/model/famix/enum_value.js +24 -0
  32. package/dist/lib/famix/src/model/famix/function.js +16 -0
  33. package/dist/lib/famix/src/model/famix/implicit_variable.js +16 -0
  34. package/dist/lib/famix/src/model/famix/import_clause.js +39 -0
  35. package/dist/lib/famix/src/model/famix/index.js +87 -0
  36. package/dist/lib/famix/src/model/famix/indexed_file_anchor.js +37 -0
  37. package/dist/lib/famix/src/model/famix/inheritance.js +32 -0
  38. package/dist/lib/famix/src/model/famix/interface.js +63 -0
  39. package/dist/lib/famix/src/model/famix/invocation.js +53 -0
  40. package/dist/lib/famix/src/model/famix/method.js +66 -0
  41. package/dist/lib/famix/src/model/famix/module.js +30 -0
  42. package/dist/lib/famix/src/model/famix/named_entity.js +77 -0
  43. package/dist/lib/famix/src/model/famix/namespace.js +24 -0
  44. package/dist/lib/famix/src/model/famix/parameter.js +24 -0
  45. package/dist/lib/famix/src/model/famix/parameterizable_class.js +30 -0
  46. package/dist/lib/famix/src/model/famix/parameterizable_interface.js +30 -0
  47. package/dist/lib/famix/src/model/famix/parameterized_type.js +36 -0
  48. package/dist/lib/famix/src/model/famix/primitive_type.js +16 -0
  49. package/dist/lib/famix/src/model/famix/property.js +44 -0
  50. package/dist/lib/famix/src/model/famix/reference.js +32 -0
  51. package/dist/lib/famix/src/model/famix/scoping_entity.js +30 -0
  52. package/dist/lib/famix/src/model/famix/script_entity.js +30 -0
  53. package/dist/lib/famix/src/model/famix/source_anchor.js +26 -0
  54. package/dist/lib/famix/src/model/famix/source_language.js +30 -0
  55. package/dist/lib/famix/src/model/famix/sourced_entity.js +55 -0
  56. package/dist/lib/famix/src/model/famix/structural_entity.js +38 -0
  57. package/dist/lib/famix/src/model/famix/text_anchor.js +37 -0
  58. package/dist/lib/famix/src/model/famix/type.js +71 -0
  59. package/dist/lib/famix/src/model/famix/type_parameter.js +24 -0
  60. package/dist/lib/famix/src/model/famix/variable.js +23 -0
  61. package/dist/lib/ts-complex/cyclomatic-service.js +83 -0
  62. package/dist/ts2famix-cli.js +51 -0
  63. package/dist/ts2famix-tsconfig.js +53 -0
  64. package/doc-uml/.gitkeep +0 -0
  65. package/docs/.gitkeep +0 -0
  66. package/jest.config.json +10 -0
  67. package/package.json +1 -1
  68. package/tsconfig.json +1 -1
  69. package/.github/workflows/node.js.yml +0 -60
  70. package/doc-metamodel/skins.include.puml +0 -2
  71. package/test/abstractClassWithComments.test.ts +0 -58
  72. package/test/abstracts.test.ts +0 -53
  73. package/test/access.test.ts +0 -62
  74. package/test/accesses.test.ts +0 -42
  75. package/test/accessorsWithDecorators.test.ts +0 -98
  76. package/test/alias.test.ts +0 -39
  77. package/test/classExtendsUndefinedClass.test.ts +0 -41
  78. package/test/classImplementsUndefinedInterface.test.ts +0 -45
  79. package/test/classWithDecorators.test.ts +0 -65
  80. package/test/entities.test.ts +0 -232
  81. package/test/entities_json.test.ts +0 -48
  82. package/test/enum.test.ts +0 -55
  83. package/test/functionReturnsFunction.test.ts +0 -53
  84. package/test/functionWithParameters.test.ts +0 -38
  85. package/test/functionWithVariables.test.ts +0 -64
  86. package/test/functions.test.ts +0 -23
  87. package/test/functionsInFunction.test.ts +0 -40
  88. package/test/functionsInMethod.test.ts +0 -42
  89. package/test/genericClass.test.ts +0 -42
  90. package/test/genericClassInheritsInterface.test.ts +0 -47
  91. package/test/genericInterface.test.ts +0 -38
  92. package/test/genericMethod.test.ts +0 -65
  93. package/test/genericWithInvocation.test.ts +0 -71
  94. package/test/generics.test.ts +0 -68
  95. package/test/inheritance.test.ts +0 -50
  96. package/test/interfaceInheritsInterface.test.ts +0 -40
  97. package/test/interfaceInheritsUndefinedInterface.test.ts +0 -41
  98. package/test/invocation.test.ts +0 -94
  99. package/test/invocationWithFunction.test.ts +0 -42
  100. package/test/invocationWithVariable.test.ts +0 -46
  101. package/test/invocation_json.test.ts +0 -63
  102. package/test/invocations.test.ts +0 -131
  103. package/test/jsDoc.test.ts +0 -31
  104. package/test/methodWithDecorator.test.ts +0 -44
  105. package/test/methods.test.ts +0 -42
  106. package/test/metrics.test.ts +0 -51
  107. package/test/module.test.ts +0 -71
  108. package/test/namespaces.test.ts +0 -54
  109. package/test/namespacesAndClasses.test.ts +0 -66
  110. package/test/parameterWithDecorators.test.ts +0 -54
  111. package/test/propertyWithDecorators.test.ts +0 -80
  112. package/test/sample.test.ts +0 -13
  113. package/test/simpleFunction.test.ts +0 -32
  114. package/test/simpleTest.test.ts +0 -18
  115. package/test/simpleTest2.test.ts +0 -36
  116. package/test/types.test.ts +0 -58
  117. package/test_src/sample.ts +0 -103
  118. package/test_src/sampleForModule.ts +0 -10
  119. package/test_src/sampleForModule2.ts +0 -7
  120. package/test_src/sampleForModule3.ts +0 -2
  121. /package/{jest.config.ts → jest.config-old.ts} +0 -0
@@ -0,0 +1,102 @@
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.Importer = void 0;
27
+ const ts_morph_1 = require("ts-morph");
28
+ const fs = __importStar(require("fs"));
29
+ const famix_functions_1 = require("./famix_functions/famix_functions");
30
+ const processFiles_1 = require("./analyze_functions/processFiles");
31
+ const processAccesses_1 = require("./analyze_functions/processAccesses");
32
+ const processInvocations_1 = require("./analyze_functions/processInvocations");
33
+ const processInheritances_1 = require("./analyze_functions/processInheritances");
34
+ const processImportClauses_1 = require("./analyze_functions/processImportClauses");
35
+ /**
36
+ * This class is used to build a Famix model from a TypeScript source code
37
+ */
38
+ class Importer {
39
+ constructor() {
40
+ this.project = new ts_morph_1.Project(); // The project containing the source files to analyze
41
+ this.famixFunctions = new famix_functions_1.FamixFunctions(); // FamixFunctions object, it contains all the functions needed to create Famix entities
42
+ this.processFiles = new processFiles_1.ProcessFiles(this.famixFunctions); // ProcessFiles object, it contains all the functions needed to process the source files
43
+ this.processAccesses = new processAccesses_1.ProcessAccesses(this.famixFunctions); // ProcessAccesses object, it contains all the functions needed to process the accesses
44
+ this.processInvocations = new processInvocations_1.ProcessInvocations(this.famixFunctions); // ProcessInvocations object, it contains all the functions needed to process the invocations
45
+ this.processInheritances = new processInheritances_1.ProcessInheritances(this.famixFunctions); // ProcessInheritances object, it contains all the functions needed to process the inheritances
46
+ this.processImportClauses = new processImportClauses_1.ProcessImportClauses(this.famixFunctions); // ProcessImportClauses object, it contains all the functions needed to process the import clauses
47
+ }
48
+ /**
49
+ * Main method
50
+ * @param paths An array of paths to the source files to analyze
51
+ * @returns The Famix repository containing the Famix model
52
+ */
53
+ famixRepFromPaths(paths) {
54
+ let famixRep;
55
+ try {
56
+ console.info(`famixRepFromPaths: paths: ${paths}`);
57
+ const sourceFiles = this.project.addSourceFilesAtPaths(paths);
58
+ this.processFiles.processFiles(sourceFiles);
59
+ const accesses = this.processFiles.getAccesses();
60
+ const methodsAndFunctionsWithId = this.processFiles.getMethodsAndFunctionsWithId();
61
+ const classes = this.processFiles.getClasses();
62
+ const interfaces = this.processFiles.getInterfaces();
63
+ const modules = this.processFiles.getModules();
64
+ const exports = this.processFiles.getExports();
65
+ this.processImportClauses.processImportClauses(modules, exports);
66
+ this.processAccesses.processAccesses(accesses);
67
+ this.processInvocations.processInvocations(methodsAndFunctionsWithId);
68
+ this.processInheritances.processInheritances(classes, interfaces);
69
+ famixRep = this.famixFunctions.getFamixRepository();
70
+ }
71
+ catch (error) {
72
+ console.error(`> ERROR: got exception ${error}. Exiting...`);
73
+ console.error(error.message);
74
+ console.error(error.stack);
75
+ process.exit(1);
76
+ }
77
+ return famixRep;
78
+ }
79
+ /**
80
+ * Main method for tests
81
+ * @param filename The name of the file to analyze
82
+ * @param source A TypeScript source code
83
+ * @returns The Famix repository containing the Famix model
84
+ */
85
+ famixRepFromSource(filename, source) {
86
+ const filePath = `./test_src/${filename}.ts`;
87
+ fs.writeFileSync(filePath, source, 'utf-8');
88
+ const famixRep = this.famixRepFromPaths([filePath]);
89
+ return famixRep;
90
+ }
91
+ /**
92
+ * Main method for a ts-morph project
93
+ * @param project A ts-morph project
94
+ * @returns The Famix repository containing the Famix model
95
+ */
96
+ famixRepFromProject(project) {
97
+ const sourceFileNames = project.getSourceFiles().map(f => f.getFilePath());
98
+ const famixRep = this.famixRepFromPaths(sourceFileNames);
99
+ return famixRep;
100
+ }
101
+ }
102
+ exports.Importer = Importer;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProcessAccesses = void 0;
4
+ /**
5
+ * This class is used to build a Famix model for the accesses
6
+ */
7
+ class ProcessAccesses {
8
+ /**
9
+ * Initializes the ProcessAccesses object
10
+ * @param famixFunctions FamixFunctions object, it contains all the functions needed to create Famix entities
11
+ */
12
+ constructor(famixFunctions) {
13
+ this.famixFunctions = famixFunctions;
14
+ }
15
+ /**
16
+ * Builds a Famix model for the accesses on the parameters, variables, properties and enum members of the source files
17
+ * @param accesses A map of parameters, variables, properties and enum members with their id
18
+ */
19
+ processAccesses(accesses) {
20
+ console.info(`processAccesses: Creating accesses:`);
21
+ accesses.forEach((v, id) => {
22
+ console.info(`processAccesses: Accesses to ${v.getName()}`);
23
+ try {
24
+ const temp_nodes = v.findReferencesAsNodes();
25
+ temp_nodes.forEach(node => this.processNodeForAccesses(node, id));
26
+ }
27
+ catch (error) {
28
+ console.error(`> WARNING: got exception ${error}. Continuing...`);
29
+ }
30
+ });
31
+ }
32
+ /**
33
+ * Builds a Famix model for an access on a parameter, variable, property or enum member
34
+ * @param n A node
35
+ * @param id An id of a parameter, a variable, a property or an enum member
36
+ */
37
+ processNodeForAccesses(n, id) {
38
+ try {
39
+ this.famixFunctions.createFamixAccess(n, id);
40
+ console.info(`processNodeForAccesses: node: node, (${n.getType().getText()})`);
41
+ }
42
+ catch (error) {
43
+ console.error(`> WARNING: got exception ${error}. ScopeDeclaration invalid for ${n.getSymbol().getFullyQualifiedName()}. Continuing...`);
44
+ }
45
+ }
46
+ }
47
+ exports.ProcessAccesses = ProcessAccesses;
@@ -0,0 +1,540 @@
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.ProcessFiles = void 0;
27
+ const ts_morph_1 = require("ts-morph");
28
+ const Famix = __importStar(require("../lib/famix/src/model/famix"));
29
+ const cyclomatic_service_1 = require("../lib/ts-complex/cyclomatic-service");
30
+ /**
31
+ * This class is used to build a Famix model for an array of source files
32
+ */
33
+ class ProcessFiles {
34
+ /**
35
+ * Initializes the ProcessFiles object
36
+ * @param famixFunctions FamixFunctions object, it contains all the functions needed to create Famix entities
37
+ */
38
+ constructor(famixFunctions) {
39
+ this.methodsAndFunctionsWithId = new Map(); // Maps the Famix method, constructor, getter, setter and function ids to their ts-morph method, constructor, getter, setter or function object
40
+ this.accesses = new Map(); // Maps the Famix parameter, variable, property and enum value ids to their ts-morph parameter, variable, property or enum member object
41
+ this.classes = new Array(); // Array of all the classes of the source files
42
+ this.interfaces = new Array(); // Array of all the interfaces of the source files
43
+ this.modules = new Array(); // Array of all the source files which are modules
44
+ this.exports = new Array(); // Array of all the exports
45
+ this.famixFunctions = famixFunctions;
46
+ }
47
+ /**
48
+ * Builds a Famix model for an array of source files
49
+ * @param sourceFiles An array of source files
50
+ */
51
+ processFiles(sourceFiles) {
52
+ sourceFiles.forEach(file => {
53
+ console.info(`processFiles: File: >>>>>>>>>> ${file.getBaseName()}`);
54
+ // Computes the cyclomatic complexity metrics for the current source file
55
+ this.currentCC = (0, cyclomatic_service_1.calculate)(file.getFilePath());
56
+ this.processFile(file);
57
+ });
58
+ }
59
+ /**
60
+ * Gets the map of methods and functions with their id
61
+ * @returns The map of methods and functions with their id
62
+ */
63
+ getMethodsAndFunctionsWithId() {
64
+ return this.methodsAndFunctionsWithId;
65
+ }
66
+ /**
67
+ * Gets the map of accesses
68
+ * @returns The map of accesses
69
+ */
70
+ getAccesses() {
71
+ return this.accesses;
72
+ }
73
+ /**
74
+ * Gets the array of classes
75
+ * @returns The array of classes
76
+ */
77
+ getClasses() {
78
+ return this.classes;
79
+ }
80
+ /**
81
+ * Gets the array of interfaces
82
+ * @returns The array of interfaces
83
+ */
84
+ getInterfaces() {
85
+ return this.interfaces;
86
+ }
87
+ /**
88
+ * Gets the array of modules
89
+ * @returns The array of modules
90
+ */
91
+ getModules() {
92
+ return this.modules;
93
+ }
94
+ /**
95
+ * Gets the array of exports
96
+ * @returns The array of exports
97
+ */
98
+ getExports() {
99
+ return this.exports;
100
+ }
101
+ /**
102
+ * Builds a Famix model for a source file
103
+ * @param f A source file
104
+ */
105
+ processFile(f) {
106
+ const isModule = this.isModule(f);
107
+ if (isModule) {
108
+ this.modules.push(f);
109
+ }
110
+ const fmxFile = this.famixFunctions.createOrGetFamixFile(f, isModule);
111
+ console.info(`processFile: file: ${f.getBaseName()}, fqn = ${fmxFile.getFullyQualifiedName()}`);
112
+ this.processComments(f, fmxFile);
113
+ this.processAliases(f, fmxFile);
114
+ this.processClasses(f, fmxFile);
115
+ this.processInterfaces(f, fmxFile);
116
+ this.processVariables(f, fmxFile);
117
+ this.processEnums(f, fmxFile);
118
+ this.processFunctions(f, fmxFile);
119
+ this.processNamespaces(f, fmxFile);
120
+ }
121
+ /**
122
+ * Builds a Famix model for a namespace
123
+ * @param m A namespace
124
+ * @returns A Famix.Namespace representing the namespace
125
+ */
126
+ processNamespace(m) {
127
+ const fmxNamespace = this.famixFunctions.createOrGetFamixNamespace(m);
128
+ console.info(`processNamespace: namespace: ${m.getName()}, (${m.getType().getText()}), ${fmxNamespace.getFullyQualifiedName()}`);
129
+ this.processComments(m, fmxNamespace);
130
+ this.processAliases(m, fmxNamespace);
131
+ this.processClasses(m, fmxNamespace);
132
+ this.processInterfaces(m, fmxNamespace);
133
+ this.processVariables(m, fmxNamespace);
134
+ this.processEnums(m, fmxNamespace);
135
+ this.processFunctions(m, fmxNamespace);
136
+ this.processNamespaces(m, fmxNamespace);
137
+ return fmxNamespace;
138
+ }
139
+ /**
140
+ * Builds a Famix model for the aliases of a container
141
+ * @param m A container (a source file, a namespace, a function or a method)
142
+ * @param fmxScope The Famix model of the container
143
+ */
144
+ processAliases(m, fmxScope) {
145
+ console.info(`processAliases: ---------- Finding Aliases:`);
146
+ m.getTypeAliases().forEach(a => {
147
+ const fmxAlias = this.processAlias(a);
148
+ fmxScope.addAlias(fmxAlias);
149
+ });
150
+ }
151
+ /**
152
+ * Builds a Famix model for the classes of a container
153
+ * @param m A container (a source file or a namespace)
154
+ * @param fmxScope The Famix model of the container
155
+ */
156
+ processClasses(m, fmxScope) {
157
+ console.info(`processClasses: ---------- Finding Classes:`);
158
+ m.getClasses().forEach(c => {
159
+ const fmxClass = this.processClass(c);
160
+ fmxScope.addType(fmxClass);
161
+ });
162
+ }
163
+ /**
164
+ * Builds a Famix model for the interfaces of a container
165
+ * @param m A container (a source file or a namespace)
166
+ * @param fmxScope The Famix model of the container
167
+ */
168
+ processInterfaces(m, fmxScope) {
169
+ console.info(`processInterfaces: ---------- Finding Interfaces:`);
170
+ m.getInterfaces().forEach(i => {
171
+ const fmxInterface = this.processInterface(i);
172
+ fmxScope.addType(fmxInterface);
173
+ });
174
+ }
175
+ /**
176
+ * Builds a Famix model for the variables of a container
177
+ * @param m A container (a source file, a namespace, a function or a method)
178
+ * @param fmxScope The Famix model of the container
179
+ */
180
+ processVariables(m, fmxScope) {
181
+ console.info(`processVariables: ---------- Finding Variables:`);
182
+ m.getVariableStatements().forEach(v => {
183
+ const fmxVariables = this.processVariableStatement(v);
184
+ fmxVariables.forEach(fmxVariable => {
185
+ fmxScope.addVariable(fmxVariable);
186
+ });
187
+ });
188
+ }
189
+ /**
190
+ * Builds a Famix model for the enums of a container
191
+ * @param m A container (a source file, a namespace, a function or a method)
192
+ * @param fmxScope The Famix model of the container
193
+ */
194
+ processEnums(m, fmxScope) {
195
+ console.info(`processEnums: ---------- Finding Enums:`);
196
+ m.getEnums().forEach(e => {
197
+ const fmxEnum = this.processEnum(e);
198
+ fmxScope.addType(fmxEnum);
199
+ });
200
+ }
201
+ /**
202
+ * Builds a Famix model for the functions of a container
203
+ * @param m A container (a source file, a namespace, a function or a method)
204
+ * @param fmxScope The Famix model of the container
205
+ */
206
+ processFunctions(m, fmxScope) {
207
+ console.info(`processFunctions: ---------- Finding Functions:`);
208
+ m.getFunctions().forEach(f => {
209
+ const fmxFunction = this.processFunction(f);
210
+ fmxScope.addFunction(fmxFunction);
211
+ });
212
+ }
213
+ /**
214
+ * Builds a Famix model for the namespaces of a container
215
+ * @param m A container (a source file or a namespace)
216
+ * @param fmxScope The Famix model of the container
217
+ */
218
+ processNamespaces(m, fmxScope) {
219
+ console.info(`processNamespaces: ---------- Finding Namespaces:`);
220
+ m.getModules().forEach(md => {
221
+ const fmxNsp = this.processNamespace(md);
222
+ fmxScope.addNamespace(fmxNsp);
223
+ });
224
+ }
225
+ /**
226
+ * Builds a Famix model for an alias
227
+ * @param a An alias
228
+ * @returns A Famix.Alias representing the alias
229
+ */
230
+ processAlias(a) {
231
+ const fmxAlias = this.famixFunctions.createFamixAlias(a);
232
+ console.info(`processAlias: alias: ${a.getName()}, (${a.getType().getText()}), fqn = ${fmxAlias.getFullyQualifiedName()}`);
233
+ this.processComments(a, fmxAlias);
234
+ return fmxAlias;
235
+ }
236
+ /**
237
+ * Builds a Famix model for a class
238
+ * @param c A class
239
+ * @returns A Famix.Class or a Famix.ParameterizableClass representing the class
240
+ */
241
+ processClass(c) {
242
+ this.classes.push(c);
243
+ const fmxClass = this.famixFunctions.createOrGetFamixClass(c);
244
+ console.info(`processClass: class: ${c.getName()}, (${c.getType().getText()}), fqn = ${fmxClass.getFullyQualifiedName()}`);
245
+ this.processComments(c, fmxClass);
246
+ this.processDecorators(c, fmxClass);
247
+ this.processStructuredType(c, fmxClass);
248
+ c.getConstructors().forEach(con => {
249
+ const fmxCon = this.processMethod(con);
250
+ fmxClass.addMethod(fmxCon);
251
+ });
252
+ c.getGetAccessors().forEach(acc => {
253
+ const fmxAcc = this.processMethod(acc);
254
+ fmxClass.addMethod(fmxAcc);
255
+ });
256
+ c.getSetAccessors().forEach(acc => {
257
+ const fmxAcc = this.processMethod(acc);
258
+ fmxClass.addMethod(fmxAcc);
259
+ });
260
+ return fmxClass;
261
+ }
262
+ /**
263
+ * Builds a Famix model for an interface
264
+ * @param i An interface
265
+ * @returns A Famix.Interface or a Famix.ParameterizableInterface representing the interface
266
+ */
267
+ processInterface(i) {
268
+ this.interfaces.push(i);
269
+ const fmxInterface = this.famixFunctions.createOrGetFamixInterface(i);
270
+ console.info(`processInterface: interface: ${i.getName()}, (${i.getType().getText()}), fqn = ${fmxInterface.getFullyQualifiedName()}`);
271
+ this.processComments(i, fmxInterface);
272
+ this.processStructuredType(i, fmxInterface);
273
+ return fmxInterface;
274
+ }
275
+ /**
276
+ * Builds a Famix model for the type parameters, properties and methods of a structured type
277
+ * @param c A structured type (a class or an interface)
278
+ * @param fmxScope The Famix model of the structured type
279
+ */
280
+ processStructuredType(c, fmxScope) {
281
+ console.info(`processStructuredType: ---------- Finding Properties and Methods:`);
282
+ if (fmxScope instanceof Famix.ParameterizableClass || fmxScope instanceof Famix.ParameterizableInterface) {
283
+ this.processTypeParameters(c, fmxScope);
284
+ }
285
+ c.getProperties().forEach(prop => {
286
+ const fmxProperty = this.processProperty(prop);
287
+ fmxScope.addProperty(fmxProperty);
288
+ });
289
+ c.getMethods().forEach(m => {
290
+ const fmxMethod = this.processMethod(m);
291
+ fmxScope.addMethod(fmxMethod);
292
+ });
293
+ }
294
+ /**
295
+ * Builds a Famix model for a property
296
+ * @param p A property
297
+ * @returns A Famix.Property representing the property
298
+ */
299
+ processProperty(p) {
300
+ const fmxProperty = this.famixFunctions.createFamixProperty(p);
301
+ console.info(`processProperty: property: ${p.getName()}, (${p.getType().getText()}), fqn = ${fmxProperty.getFullyQualifiedName()}`);
302
+ this.processComments(p, fmxProperty);
303
+ if (!(p instanceof ts_morph_1.PropertySignature)) {
304
+ this.processDecorators(p, fmxProperty);
305
+ this.accesses.set(fmxProperty.id, p);
306
+ }
307
+ return fmxProperty;
308
+ }
309
+ /**
310
+ * Builds a Famix model for a method or an accessor
311
+ * @param m A method or an accessor
312
+ * @returns A Famix.Method or a Famix.Accessor representing the method or the accessor
313
+ */
314
+ processMethod(m) {
315
+ const fmxMethod = this.famixFunctions.createFamixMethod(m, this.currentCC);
316
+ console.info(`processMethod: method: ${!(m instanceof ts_morph_1.ConstructorDeclaration) ? m.getName() : "constructor"}, (${m.getType().getText()}), parent: ${m.getParent().getName()}, fqn = ${fmxMethod.getFullyQualifiedName()}`);
317
+ this.processComments(m, fmxMethod);
318
+ this.processTypeParameters(m, fmxMethod);
319
+ this.processParameters(m, fmxMethod);
320
+ if (!(m instanceof ts_morph_1.MethodSignature)) {
321
+ this.processAliases(m, fmxMethod);
322
+ this.processVariables(m, fmxMethod);
323
+ this.processEnums(m, fmxMethod);
324
+ this.processFunctions(m, fmxMethod);
325
+ this.processFunctionExpressions(m, fmxMethod);
326
+ this.methodsAndFunctionsWithId.set(fmxMethod.id, m);
327
+ }
328
+ if (m instanceof ts_morph_1.MethodDeclaration || m instanceof ts_morph_1.GetAccessorDeclaration || m instanceof ts_morph_1.SetAccessorDeclaration) {
329
+ this.processDecorators(m, fmxMethod);
330
+ }
331
+ return fmxMethod;
332
+ }
333
+ /**
334
+ * Builds a Famix model for a function
335
+ * @param f A function
336
+ * @returns A Famix.Function representing the function
337
+ */
338
+ processFunction(f) {
339
+ const fmxFunction = this.famixFunctions.createFamixFunction(f, this.currentCC);
340
+ console.info(`processFunction: function: ${(f.getName()) ? f.getName() : "anonymous"}, (${f.getType().getText()}), fqn = ${fmxFunction.getFullyQualifiedName()}`);
341
+ this.processComments(f, fmxFunction);
342
+ this.processAliases(f, fmxFunction);
343
+ this.processTypeParameters(f, fmxFunction);
344
+ this.processParameters(f, fmxFunction);
345
+ this.processVariables(f, fmxFunction);
346
+ this.processEnums(f, fmxFunction);
347
+ this.processFunctions(f, fmxFunction);
348
+ if (f instanceof ts_morph_1.FunctionDeclaration && !(f.getParent() instanceof ts_morph_1.Block)) {
349
+ this.processFunctionExpressions(f, fmxFunction);
350
+ }
351
+ this.methodsAndFunctionsWithId.set(fmxFunction.id, f);
352
+ return fmxFunction;
353
+ }
354
+ /**
355
+ * Builds a Famix model for the function expressions of a function or a method
356
+ * @param f A function or a method
357
+ * @param fmxScope The Famix model of the function or the method
358
+ */
359
+ processFunctionExpressions(f, fmxScope) {
360
+ console.info(`processFunctionExpressions: ---------- Finding Function Expressions:`);
361
+ const functionExpressions = f.getDescendantsOfKind(ts_morph_1.SyntaxKind.FunctionExpression);
362
+ functionExpressions.forEach((func) => {
363
+ const fmxFunc = this.processFunction(func);
364
+ fmxScope.addFunction(fmxFunc);
365
+ });
366
+ }
367
+ /**
368
+ * Builds a Famix model for the parameters of a method or a function
369
+ * @param m A method or a function
370
+ * @param fmxScope The Famix model of the method or the function
371
+ */
372
+ processParameters(m, fmxScope) {
373
+ console.info(`processParameters: ---------- Finding Parameters:`);
374
+ m.getParameters().forEach(param => {
375
+ const fmxParam = this.processParameter(param);
376
+ fmxScope.addParameter(fmxParam);
377
+ });
378
+ }
379
+ /**
380
+ * Builds a Famix model for a parameter
381
+ * @param p A parameter
382
+ * @returns A Famix.Parameter representing the parameter
383
+ */
384
+ processParameter(p) {
385
+ const fmxParam = this.famixFunctions.createFamixParameter(p);
386
+ console.info(`processParameter: parameter: ${p.getName()}, (${p.getType().getText()}), fqn = ${fmxParam.getFullyQualifiedName()}`);
387
+ this.processComments(p, fmxParam);
388
+ this.processDecorators(p, fmxParam);
389
+ const parent = p.getParent();
390
+ if (!(parent instanceof ts_morph_1.MethodSignature)) {
391
+ this.accesses.set(fmxParam.id, p);
392
+ }
393
+ return fmxParam;
394
+ }
395
+ /**
396
+ * Builds a Famix model for the type parameters of a class, an interface, a method or a function
397
+ * @param e A class, an interface, a method or a function
398
+ * @param fmxScope The Famix model of the class, the interface, the method or the function
399
+ */
400
+ processTypeParameters(e, fmxScope) {
401
+ console.info(`processTypeParameters: ---------- Finding Type Parameters:`);
402
+ e.getTypeParameters().forEach(tp => {
403
+ const fmxParam = this.processTypeParameter(tp);
404
+ fmxScope.addTypeParameter(fmxParam);
405
+ });
406
+ }
407
+ /**
408
+ * Builds a Famix model for a type parameter
409
+ * @param tp A type parameter
410
+ * @returns A Famix.TypeParameter representing the type parameter
411
+ */
412
+ processTypeParameter(tp) {
413
+ const fmxTypeParameter = this.famixFunctions.createFamixTypeParameter(tp);
414
+ console.info(`processTypeParameter: type parameter: ${tp.getName()}, (${tp.getType().getText()}), fqn = ${fmxTypeParameter.getFullyQualifiedName()}`);
415
+ this.processComments(tp, fmxTypeParameter);
416
+ return fmxTypeParameter;
417
+ }
418
+ /**
419
+ * Builds a Famix model for the variables of a variable statement
420
+ * @param v A variable statement
421
+ * @returns An array of Famix.Variable representing the variables
422
+ */
423
+ processVariableStatement(v) {
424
+ const fmxVariables = new Array();
425
+ console.info(`processVariableStatement: variable statement: variable statement, (${v.getType().getText()}), ${v.getDeclarationKindKeyword().getText()}`);
426
+ v.getDeclarations().forEach(variable => {
427
+ const fmxVar = this.processVariable(variable);
428
+ this.processComments(v, fmxVar);
429
+ fmxVariables.push(fmxVar);
430
+ });
431
+ return fmxVariables;
432
+ }
433
+ /**
434
+ * Builds a Famix model for a variable
435
+ * @param v A variable
436
+ * @returns A Famix.Variable representing the variable
437
+ */
438
+ processVariable(v) {
439
+ const fmxVar = this.famixFunctions.createFamixVariable(v);
440
+ console.info(`processVariable: variable: ${v.getName()}, (${v.getType().getText()}), ${v.getInitializer() ? "initializer: " + v.getInitializer().getText() : "initializer: "}, fqn = ${fmxVar.getFullyQualifiedName()}`);
441
+ this.processComments(v, fmxVar);
442
+ this.accesses.set(fmxVar.id, v);
443
+ return fmxVar;
444
+ }
445
+ /**
446
+ * Builds a Famix model for an enum
447
+ * @param e An enum
448
+ * @returns A Famix.Enum representing the enum
449
+ */
450
+ processEnum(e) {
451
+ const fmxEnum = this.famixFunctions.createFamixEnum(e);
452
+ console.info(`processEnum: enum: ${e.getName()}, (${e.getType().getText()}), fqn = ${fmxEnum.getFullyQualifiedName()}`);
453
+ this.processComments(e, fmxEnum);
454
+ e.getMembers().forEach(m => {
455
+ const fmxEnumValue = this.processEnumValue(m);
456
+ fmxEnum.addValue(fmxEnumValue);
457
+ });
458
+ return fmxEnum;
459
+ }
460
+ /**
461
+ * Builds a Famix model for an enum member
462
+ * @param v An enum member
463
+ * @returns A Famix.EnumValue representing the enum member
464
+ */
465
+ processEnumValue(v) {
466
+ const fmxEnumValue = this.famixFunctions.createFamixEnumValue(v);
467
+ console.info(`processEnumValue: enum value: ${v.getName()}, (${v.getType().getText()}), fqn = ${fmxEnumValue.getFullyQualifiedName()}`);
468
+ this.processComments(v, fmxEnumValue);
469
+ this.accesses.set(fmxEnumValue.id, v);
470
+ return fmxEnumValue;
471
+ }
472
+ /**
473
+ * Builds a Famix model for the decorators of a class, a method, a parameter or a property
474
+ * @param e A class, a method, a parameter or a property
475
+ * @param fmxScope The Famix model of the class, the method, the parameter or the property
476
+ */
477
+ processDecorators(e, fmxScope) {
478
+ console.info(`processDecorators: ---------- Finding Decorators:`);
479
+ e.getDecorators().forEach(dec => {
480
+ const fmxDec = this.processDecorator(dec, e);
481
+ fmxScope.addDecorator(fmxDec);
482
+ });
483
+ }
484
+ /**
485
+ * Builds a Famix model for a decorator
486
+ * @param d A decorator
487
+ * @param e A class, a method, a parameter or a property
488
+ * @returns A Famix.Decorator representing the decorator
489
+ */
490
+ processDecorator(d, e) {
491
+ const fmxDec = this.famixFunctions.createOrGetFamixDecorator(d, e);
492
+ console.info(`processDecorator: decorator: ${d.getName()}, (${d.getType().getText()}), fqn = ${fmxDec.getFullyQualifiedName()}`);
493
+ this.processComments(d, fmxDec);
494
+ return fmxDec;
495
+ }
496
+ /**
497
+ * Builds a Famix model for the comments
498
+ * @param e A ts-morph element
499
+ * @param fmxScope The Famix model of the named entity
500
+ */
501
+ processComments(e, fmxScope) {
502
+ console.info(`processComments: ---------- Finding Comments:`);
503
+ e.getLeadingCommentRanges().forEach(c => {
504
+ const fmxComment = this.processComment(c, fmxScope);
505
+ fmxScope.addComment(fmxComment);
506
+ });
507
+ e.getTrailingCommentRanges().forEach(c => {
508
+ const fmxComment = this.processComment(c, fmxScope);
509
+ fmxScope.addComment(fmxComment);
510
+ });
511
+ }
512
+ /**
513
+ * Builds a Famix model for a comment
514
+ * @param c A comment
515
+ * @param fmxScope The Famix model of the comment's container
516
+ * @returns A Famix.Comment representing the comment
517
+ */
518
+ processComment(c, fmxScope) {
519
+ let isJSDoc = false;
520
+ if (c.getText().substring(0, 3) === "/**") {
521
+ isJSDoc = true;
522
+ }
523
+ const fmxComment = this.famixFunctions.createFamixComment(c, fmxScope, isJSDoc);
524
+ console.info(`processComment: comment: ${c.getText()}`);
525
+ return fmxComment;
526
+ }
527
+ /**
528
+ * Checks if the file has any imports or exports to be considered a module
529
+ * @param sourceFile A source file
530
+ * @returns A boolean indicating if the file is a module
531
+ */
532
+ isModule(sourceFile) {
533
+ if (sourceFile.getImportDeclarations().length > 0 || sourceFile.getExportedDeclarations().size > 0) {
534
+ this.exports.push(sourceFile.getExportedDeclarations());
535
+ return true;
536
+ }
537
+ return false;
538
+ }
539
+ }
540
+ exports.ProcessFiles = ProcessFiles;