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,205 +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.FamixFunctionsAssociations = void 0;
27
- const ts_morph_1 = require("ts-morph");
28
- const Famix = __importStar(require("../lib/famix/src/model/famix"));
29
- const fqn_1 = require("../fqn");
30
- const famix_functions_index_1 = require("./famix_functions_index");
31
- /**
32
- * This class is used to build a Famix model for the associations
33
- */
34
- class FamixFunctionsAssociations {
35
- /**
36
- * Initializes the FamixFunctionsAssociations object
37
- * @param famixRep The Famix repository
38
- * @param fmxClasses The map of the class names and their Famix model
39
- * @param fmxInterfaces The map of the interface names and their Famix model
40
- */
41
- constructor(famixRep, fmxClasses, fmxInterfaces) {
42
- this.FQNFunctions = new fqn_1.FQNFunctions(); // The fully qualified name functions
43
- this.famixRep = famixRep;
44
- this.famixClasses = fmxClasses;
45
- this.famixInterfaces = fmxInterfaces;
46
- this.famixFunctionsIndex = new famix_functions_index_1.FamixFunctionsIndex(famixRep);
47
- }
48
- /**
49
- * Creates a Famix access
50
- * @param node A node
51
- * @param id An id of a parameter, a variable, a property or an enum member
52
- */
53
- createFamixAccess(node, id) {
54
- const fmxVar = this.famixRep.getFamixEntityById(id);
55
- const nodeReferenceAncestor = this.findAncestor(node);
56
- const ancestorFullyQualifiedName = this.FQNFunctions.getFQN(nodeReferenceAncestor);
57
- const accessor = this.getFamixEntityByFullyQualifiedName(ancestorFullyQualifiedName);
58
- const fmxAccess = new Famix.Access(this.famixRep);
59
- fmxAccess.setAccessor(accessor);
60
- fmxAccess.setVariable(fmxVar);
61
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(node, fmxAccess);
62
- }
63
- /**
64
- * Creates a Famix invocation
65
- * @param node A node
66
- * @param m A method or a function
67
- * @param id The id of the method or the function
68
- */
69
- createFamixInvocation(node, m, id) {
70
- const fmxMethodOrFunction = this.getFamixEntityById(id);
71
- const nodeReferenceAncestor = this.findAncestor(node);
72
- const ancestorFullyQualifiedName = this.FQNFunctions.getFQN(nodeReferenceAncestor);
73
- const sender = this.getFamixEntityByFullyQualifiedName(ancestorFullyQualifiedName);
74
- const receiverFullyQualifiedName = this.FQNFunctions.getFQN(m.getParent());
75
- const receiver = this.getFamixEntityByFullyQualifiedName(receiverFullyQualifiedName);
76
- const fmxInvocation = new Famix.Invocation(this.famixRep);
77
- fmxInvocation.setSender(sender);
78
- fmxInvocation.setReceiver(receiver);
79
- fmxInvocation.addCandidate(fmxMethodOrFunction);
80
- fmxInvocation.setSignature(fmxMethodOrFunction.getSignature());
81
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(node, fmxInvocation);
82
- }
83
- /**
84
- * Creates a Famix inheritance
85
- * @param cls A class or an interface (subclass)
86
- * @param inhClass The inherited class or interface (superclass)
87
- */
88
- createFamixInheritance(cls, inhClass) {
89
- const fmxInheritance = new Famix.Inheritance(this.famixRep);
90
- const clsName = cls.getName();
91
- let subClass;
92
- if (cls instanceof ts_morph_1.ClassDeclaration) {
93
- subClass = this.famixClasses.get(clsName);
94
- }
95
- else {
96
- subClass = this.famixInterfaces.get(clsName);
97
- }
98
- let inhClassName;
99
- let superClass;
100
- if (inhClass instanceof ts_morph_1.ClassDeclaration || inhClass instanceof ts_morph_1.InterfaceDeclaration) {
101
- inhClassName = inhClass.getName();
102
- if (inhClass instanceof ts_morph_1.ClassDeclaration) {
103
- superClass = this.famixClasses.get(inhClassName);
104
- }
105
- else {
106
- superClass = this.famixInterfaces.get(inhClassName);
107
- }
108
- }
109
- else {
110
- inhClassName = inhClass.getExpression().getText();
111
- }
112
- if (superClass === undefined) {
113
- if (inhClass instanceof ts_morph_1.ClassDeclaration) {
114
- superClass = new Famix.Class(this.famixRep);
115
- this.famixClasses.set(inhClassName, superClass);
116
- }
117
- else {
118
- superClass = new Famix.Interface(this.famixRep);
119
- this.famixInterfaces.set(inhClassName, superClass);
120
- }
121
- superClass.setName(inhClassName);
122
- superClass.setIsStub(true);
123
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(inhClass, superClass);
124
- }
125
- fmxInheritance.setSubclass(subClass);
126
- fmxInheritance.setSuperclass(superClass);
127
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(null, fmxInheritance);
128
- }
129
- /**
130
- * Creates a Famix import clause
131
- * @param importer A source file which is a module
132
- * @param moduleSpecifier The name of the module where the export declaration is
133
- * @param moduleSpecifierFilePath The path of the module where the export declaration is
134
- * @param importElement The imported entity
135
- * @param isInExports A boolean indicating if the imported entity is in the exports
136
- * @param isDefaultExport A boolean indicating if the imported entity is a default export
137
- */
138
- createFamixImportClause(importer, moduleSpecifier, moduleSpecifierFilePath, importElement, isInExports, isDefaultExport) {
139
- const fmxImportClause = new Famix.ImportClause(this.famixRep);
140
- let importedEntity;
141
- let importedEntityName;
142
- let pathName = "\"" + moduleSpecifierFilePath + "\".";
143
- if (importElement instanceof ts_morph_1.ImportSpecifier) {
144
- importedEntityName = importElement.getName();
145
- pathName = pathName + importedEntityName;
146
- if (isInExports) {
147
- importedEntity = this.getFamixEntityByFullyQualifiedName(pathName);
148
- }
149
- if (importedEntity === undefined) {
150
- importedEntity = new Famix.NamedEntity(this.famixRep);
151
- importedEntity.setName(importedEntityName);
152
- if (!isInExports) {
153
- importedEntity.setIsStub(true);
154
- }
155
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(importElement, importedEntity);
156
- importedEntity.setFullyQualifiedName(pathName);
157
- }
158
- }
159
- else {
160
- importedEntityName = importElement.getText();
161
- if (isDefaultExport) {
162
- pathName = pathName + "defaultExport";
163
- }
164
- else {
165
- pathName = pathName + "namespaceExport";
166
- }
167
- importedEntity = new Famix.NamedEntity(this.famixRep);
168
- importedEntity.setName(importedEntityName);
169
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(importElement, importedEntity);
170
- importedEntity.setFullyQualifiedName(pathName);
171
- }
172
- const importerFullyQualifiedName = this.FQNFunctions.getFQN(importer);
173
- const fmxImporter = this.getFamixEntityByFullyQualifiedName(importerFullyQualifiedName);
174
- fmxImportClause.setImporter(fmxImporter);
175
- fmxImportClause.setImportedEntity(importedEntity);
176
- fmxImportClause.setModuleSpecifier(moduleSpecifier);
177
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(null, fmxImportClause);
178
- fmxImporter.addImportClause(fmxImportClause);
179
- }
180
- /**
181
- * Gets a Famix entity by id
182
- * @param famixId An id of a Famix entity
183
- * @returns The Famix entity corresponding to the id
184
- */
185
- getFamixEntityById(famixId) {
186
- return this.famixRep.getFamixEntityById(famixId);
187
- }
188
- /**
189
- * Gets a Famix entity by fully qualified name
190
- * @param fullyQualifiedName A fully qualified name
191
- * @returns The Famix entity corresponding to the fully qualified name
192
- */
193
- getFamixEntityByFullyQualifiedName(fullyQualifiedName) {
194
- return this.famixRep.getFamixEntityByFullyQualifiedName(fullyQualifiedName);
195
- }
196
- /**
197
- * Finds the ancestor of a node
198
- * @param node A node
199
- * @returns The ancestor of the node
200
- */
201
- findAncestor(node) {
202
- return node.getAncestors().find(a => a.getKind() === ts_morph_1.SyntaxKind.MethodDeclaration || a.getKind() === ts_morph_1.SyntaxKind.Constructor || a.getKind() === ts_morph_1.SyntaxKind.FunctionDeclaration || a.getKind() === ts_morph_1.SyntaxKind.FunctionExpression || a.getKind() === ts_morph_1.SyntaxKind.ModuleDeclaration || a.getKind() === ts_morph_1.SyntaxKind.SourceFile || a.getKindName() === "GetAccessor" || a.getKindName() === "SetAccessor" || a.getKind() === ts_morph_1.SyntaxKind.ClassDeclaration);
203
- }
204
- }
205
- exports.FamixFunctionsAssociations = FamixFunctionsAssociations;
@@ -1,62 +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.FamixFunctionsIndex = void 0;
27
- const ts_morph_1 = require("ts-morph");
28
- const Famix = __importStar(require("../lib/famix/src/model/famix"));
29
- const fqn_1 = require("../fqn");
30
- /**
31
- * This class is used to build a Famix model for the index file anchors
32
- */
33
- class FamixFunctionsIndex {
34
- /**
35
- * Initializes the FamixFunctionsIndex object
36
- * @param famixRep The Famix repository
37
- */
38
- constructor(famixRep) {
39
- this.FQNFunctions = new fqn_1.FQNFunctions(); // The fully qualified name functions
40
- this.famixRep = famixRep;
41
- }
42
- /**
43
- * Makes a Famix index file anchor
44
- * @param sourceElement A source element
45
- * @param famixElement The Famix model of the source element
46
- */
47
- makeFamixIndexFileAnchor(sourceElement, famixElement) {
48
- const fmxIndexFileAnchor = new Famix.IndexedFileAnchor(this.famixRep);
49
- fmxIndexFileAnchor.setElement(famixElement);
50
- if (sourceElement !== null) {
51
- fmxIndexFileAnchor.setFileName(sourceElement.getSourceFile().getFilePath());
52
- if (!(sourceElement instanceof ts_morph_1.CommentRange)) {
53
- fmxIndexFileAnchor.setStartPos(sourceElement.getStart());
54
- fmxIndexFileAnchor.setEndPos(sourceElement.getEnd());
55
- }
56
- if (!(famixElement instanceof Famix.Association) && !(famixElement instanceof Famix.Comment) && !(sourceElement instanceof ts_morph_1.CommentRange) && !(sourceElement instanceof ts_morph_1.Identifier) && !(sourceElement instanceof ts_morph_1.ImportSpecifier) && !(sourceElement instanceof ts_morph_1.ExpressionWithTypeArguments)) {
57
- famixElement.setFullyQualifiedName(this.FQNFunctions.getFQN(sourceElement));
58
- }
59
- }
60
- }
61
- }
62
- exports.FamixFunctionsIndex = FamixFunctionsIndex;
@@ -1,110 +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.FamixFunctionsTypes = void 0;
27
- const ts_morph_1 = require("ts-morph");
28
- const Famix = __importStar(require("../lib/famix/src/model/famix"));
29
- const fqn_1 = require("../fqn");
30
- const famix_functions_index_1 = require("./famix_functions_index");
31
- /**
32
- * This class is used to build a Famix model for the types
33
- */
34
- class FamixFunctionsTypes {
35
- /**
36
- * Initializes the FamixFunctionsIndex object
37
- * @param famixRep The Famix repository
38
- */
39
- constructor(famixRep) {
40
- this.FQNFunctions = new fqn_1.FQNFunctions(); // The fully qualified name functions
41
- this.fmxTypes = new Map(); // Maps the type names to their Famix model
42
- this.famixRep = famixRep;
43
- this.famixFunctionsIndex = new famix_functions_index_1.FamixFunctionsIndex(famixRep);
44
- }
45
- /**
46
- * Creates or gets a Famix type
47
- * @param typeName A type name
48
- * @param element A ts-morph element
49
- * @returns The Famix model of the type
50
- */
51
- createOrGetFamixType(typeName, element) {
52
- let fmxType;
53
- let isPrimitiveType = false;
54
- let isParameterizedType = false;
55
- const typeAncestor = this.findTypeAncestor(element);
56
- const ancestorFullyQualifiedName = this.FQNFunctions.getFQN(typeAncestor);
57
- const ancestor = this.getFamixEntityByFullyQualifiedName(ancestorFullyQualifiedName);
58
- if (typeName === "number" || typeName === "string" || typeName === "boolean" || typeName === "bigint" || typeName === "symbol" || typeName === "undefined" || typeName === "null") {
59
- isPrimitiveType = true;
60
- }
61
- if (!isPrimitiveType && typeName.includes("<") && typeName.includes(">") && !(typeName.includes("=>"))) {
62
- isParameterizedType = true;
63
- }
64
- if (!this.fmxTypes.has(typeName)) {
65
- if (isPrimitiveType) {
66
- fmxType = new Famix.PrimitiveType(this.famixRep);
67
- fmxType.setIsStub(true);
68
- }
69
- else if (isParameterizedType) {
70
- fmxType = new Famix.ParameterizedType(this.famixRep);
71
- const parameterTypeNames = typeName.substring(typeName.indexOf("<") + 1, typeName.indexOf(">")).split(",").map(s => s.trim());
72
- const baseTypeName = typeName.substring(0, typeName.indexOf("<")).trim();
73
- parameterTypeNames.forEach(parameterTypeName => {
74
- const fmxParameterType = this.createOrGetFamixType(parameterTypeName, element);
75
- fmxType.addArgument(fmxParameterType);
76
- });
77
- const fmxBaseType = this.createOrGetFamixType(baseTypeName, element);
78
- fmxType.setBaseType(fmxBaseType);
79
- }
80
- else {
81
- fmxType = new Famix.Type(this.famixRep);
82
- }
83
- fmxType.setName(typeName);
84
- fmxType.setContainer(ancestor);
85
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(null, fmxType);
86
- this.fmxTypes.set(typeName, fmxType);
87
- }
88
- else {
89
- fmxType = this.fmxTypes.get(typeName);
90
- }
91
- return fmxType;
92
- }
93
- /**
94
- * Gets a Famix entity by fully qualified name
95
- * @param fullyQualifiedName A fully qualified name
96
- * @returns The Famix entity corresponding to the fully qualified name
97
- */
98
- getFamixEntityByFullyQualifiedName(fullyQualifiedName) {
99
- return this.famixRep.getFamixEntityByFullyQualifiedName(fullyQualifiedName);
100
- }
101
- /**
102
- * Finds the ancestor of a ts-morph element
103
- * @param element A ts-morph element
104
- * @returns The ancestor of the ts-morph element
105
- */
106
- findTypeAncestor(element) {
107
- return element.getAncestors().find(a => a.getKind() === ts_morph_1.SyntaxKind.MethodDeclaration || a.getKind() === ts_morph_1.SyntaxKind.Constructor || a.getKind() === ts_morph_1.SyntaxKind.MethodSignature || a.getKind() === ts_morph_1.SyntaxKind.FunctionDeclaration || a.getKind() === ts_morph_1.SyntaxKind.FunctionExpression || a.getKind() === ts_morph_1.SyntaxKind.ModuleDeclaration || a.getKind() === ts_morph_1.SyntaxKind.SourceFile || a.getKindName() === "GetAccessor" || a.getKindName() === "SetAccessor" || a.getKind() === ts_morph_1.SyntaxKind.ClassDeclaration || a.getKind() === ts_morph_1.SyntaxKind.InterfaceDeclaration);
108
- }
109
- }
110
- exports.FamixFunctionsTypes = FamixFunctionsTypes;
package/dist/fqn.js DELETED
@@ -1,126 +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.FQNFunctions = void 0;
27
- const ts = __importStar(require("ts-morph"));
28
- /**
29
- * This class is used to get the fully qualified name of a node
30
- */
31
- class FQNFunctions {
32
- /**
33
- * Gets the fully qualified name of a node, if it has one
34
- * @param node A node
35
- * @returns The fully qualified name of the node, or undefined if it doesn't have one
36
- */
37
- getFQN(node) {
38
- if (node instanceof ts.SourceFile) {
39
- return `"${node.getFilePath()}"`;
40
- }
41
- const symbol = node.getSymbol();
42
- if (!symbol) {
43
- return undefined;
44
- }
45
- const declarations = symbol.getDeclarations();
46
- if (!declarations) {
47
- return undefined;
48
- }
49
- const sourceFile = declarations[0].getSourceFile();
50
- if (!sourceFile) {
51
- return undefined;
52
- }
53
- const sourceFilePath = sourceFile.getFilePath();
54
- const sourceFileDirectory = sourceFilePath.substring(0, sourceFilePath.lastIndexOf("/"));
55
- const qualifiedNameParts = [];
56
- const nodeName = this.getNameOfNode(node);
57
- if (nodeName)
58
- qualifiedNameParts.push(nodeName);
59
- const ancestors = node.getAncestors();
60
- ancestors.forEach(a => {
61
- const partName = this.getNameOfNode(a);
62
- if (partName)
63
- qualifiedNameParts.push(partName);
64
- });
65
- if (qualifiedNameParts.length > 0) {
66
- return `"${sourceFileDirectory}/${qualifiedNameParts.pop()}".${qualifiedNameParts.reverse().join(".")}`;
67
- }
68
- else {
69
- return undefined;
70
- }
71
- }
72
- /**
73
- * Gets the name of a node, if it has one
74
- * @param a A node
75
- * @returns The name of the node, or an empty string if it doesn't have one
76
- */
77
- getNameOfNode(a) {
78
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
79
- switch (a.getKind()) {
80
- case ts.SyntaxKind.SourceFile:
81
- return (_a = a.asKind(ts.SyntaxKind.SourceFile)) === null || _a === void 0 ? void 0 : _a.getBaseName();
82
- case ts.SyntaxKind.ModuleDeclaration:
83
- return (_b = a.asKind(ts.SyntaxKind.ModuleDeclaration)) === null || _b === void 0 ? void 0 : _b.getName();
84
- case ts.SyntaxKind.ClassDeclaration:
85
- return (_c = a.asKind(ts.SyntaxKind.ClassDeclaration)) === null || _c === void 0 ? void 0 : _c.getName();
86
- case ts.SyntaxKind.InterfaceDeclaration:
87
- return (_d = a.asKind(ts.SyntaxKind.InterfaceDeclaration)) === null || _d === void 0 ? void 0 : _d.getName();
88
- case ts.SyntaxKind.PropertyDeclaration:
89
- return (_e = a.asKind(ts.SyntaxKind.PropertyDeclaration)) === null || _e === void 0 ? void 0 : _e.getName();
90
- case ts.SyntaxKind.PropertySignature:
91
- return (_f = a.asKind(ts.SyntaxKind.PropertySignature)) === null || _f === void 0 ? void 0 : _f.getName();
92
- case ts.SyntaxKind.MethodDeclaration:
93
- return (_g = a.asKind(ts.SyntaxKind.MethodDeclaration)) === null || _g === void 0 ? void 0 : _g.getName();
94
- case ts.SyntaxKind.MethodSignature:
95
- return (_h = a.asKind(ts.SyntaxKind.MethodSignature)) === null || _h === void 0 ? void 0 : _h.getName();
96
- case ts.SyntaxKind.GetAccessor:
97
- return (_j = a.asKind(ts.SyntaxKind.GetAccessor)) === null || _j === void 0 ? void 0 : _j.getName();
98
- case ts.SyntaxKind.SetAccessor:
99
- return (_k = a.asKind(ts.SyntaxKind.SetAccessor)) === null || _k === void 0 ? void 0 : _k.getName();
100
- case ts.SyntaxKind.FunctionDeclaration:
101
- return (_l = a.asKind(ts.SyntaxKind.FunctionDeclaration)) === null || _l === void 0 ? void 0 : _l.getName();
102
- case ts.SyntaxKind.FunctionExpression:
103
- return ((_m = a.asKind(ts.SyntaxKind.FunctionExpression)) === null || _m === void 0 ? void 0 : _m.getName()) ? (_o = a.asKind(ts.SyntaxKind.FunctionExpression)) === null || _o === void 0 ? void 0 : _o.getName() : "anonymous";
104
- case ts.SyntaxKind.Parameter:
105
- return (_p = a.asKind(ts.SyntaxKind.Parameter)) === null || _p === void 0 ? void 0 : _p.getName();
106
- case ts.SyntaxKind.VariableDeclaration:
107
- return (_q = a.asKind(ts.SyntaxKind.VariableDeclaration)) === null || _q === void 0 ? void 0 : _q.getName();
108
- case ts.SyntaxKind.Decorator:
109
- return "@" + ((_r = a.asKind(ts.SyntaxKind.Decorator)) === null || _r === void 0 ? void 0 : _r.getName());
110
- case ts.SyntaxKind.TypeParameter:
111
- return (_s = a.asKind(ts.SyntaxKind.TypeParameter)) === null || _s === void 0 ? void 0 : _s.getName();
112
- case ts.SyntaxKind.EnumDeclaration:
113
- return (_t = a.asKind(ts.SyntaxKind.EnumDeclaration)) === null || _t === void 0 ? void 0 : _t.getName();
114
- case ts.SyntaxKind.EnumMember:
115
- return (_u = a.asKind(ts.SyntaxKind.EnumMember)) === null || _u === void 0 ? void 0 : _u.getName();
116
- case ts.SyntaxKind.TypeAliasDeclaration:
117
- return (_v = a.asKind(ts.SyntaxKind.TypeAliasDeclaration)) === null || _v === void 0 ? void 0 : _v.getName();
118
- case ts.SyntaxKind.Constructor:
119
- return "constructor";
120
- default:
121
- // ancestor hasn't got a useful name
122
- return "";
123
- }
124
- }
125
- }
126
- exports.FQNFunctions = FQNFunctions;
@@ -1,73 +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
- const ts = __importStar(require("typescript"));
27
- function getFullyQualifiedName(node, checker) {
28
- // Traverse the lexical hierarchy to construct the fully qualified name.
29
- function getQualifiedName(node) {
30
- console.log(`getFullyQualifiedName: ${node}`);
31
- if (node === undefined) {
32
- return undefined;
33
- }
34
- console.log(`getFullyQualifiedName kind: ${node.kind}, ${ts.SyntaxKind[node.kind]}`);
35
- if (ts.isSourceFile(node)) {
36
- return undefined;
37
- }
38
- else if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name)) {
39
- const symbol = checker.getSymbolAtLocation(node.name);
40
- if (symbol) {
41
- const name = symbol.getName();
42
- const parentName = getQualifiedName(node.parent);
43
- return parentName ? `${parentName}.${name}` : name;
44
- }
45
- }
46
- return getQualifiedName(node.parent);
47
- }
48
- return getQualifiedName(node);
49
- }
50
- const sourceFile = ts.createSourceFile("test.ts", "function foo() { const x = 1; }", ts.ScriptTarget.ES2015);
51
- // create a program instance, which is needed to create a type checker
52
- const program = ts.createProgram(["test.ts"], {});
53
- const typeChecker = program.getTypeChecker();
54
- const statements = sourceFile.statements;
55
- statements.forEach((statement) => {
56
- var _a;
57
- console.log(`statement: ${statement.kind}`);
58
- if (ts.isFunctionDeclaration(statement)) {
59
- console.log(`function name: ${(_a = statement.name) === null || _a === void 0 ? void 0 : _a.text}`);
60
- }
61
- });
62
- // find all the identifiers in the source file (don't use ts.createTypeChecker here, make it work for TS 5.1.x)
63
- const identifiers = [];
64
- ts.forEachChild(sourceFile, function walk(node) {
65
- if (ts.isIdentifier(node)) {
66
- identifiers.push(node);
67
- }
68
- ts.forEachChild(node, walk);
69
- });
70
- console.log(identifiers.map((identifier) => identifier.text).join(", "));
71
- // find the fully qualified name of each identifier (don't use ts.createTypeChecker here)
72
- const fullyQualifiedNames = identifiers.map((identifier) => getFullyQualifiedName(identifier, typeChecker));
73
- console.log(fullyQualifiedNames.join(", "));
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FamixJSONExporter = void 0;
4
- const famix_base_element_1 = require("./famix_base_element");
5
- /**
6
- * This class is used to export Famix elements to JSON
7
- */
8
- class FamixJSONExporter {
9
- /**
10
- * Constructor of the FamixJSONExporter class
11
- * @param packageClass Name of a Famix class
12
- * @param element A Famix element to export, this element is an instance of the class named "packageClass"
13
- */
14
- constructor(packageClass, element) {
15
- this.bufferArray = {}; // A buffer to store the properties of the Famix element
16
- this.FamixPrefix = "FamixTypeScript"; // Prefix of the Famix element
17
- this.element = element;
18
- this.bufferArray["FM3"] = this.FamixPrefix + "." + packageClass;
19
- this.bufferArray["id"] = this.element.id;
20
- }
21
- /**
22
- * Adds a property to the Famix element
23
- * @param name Name of the property
24
- * @param prop A property
25
- */
26
- addProperty(name, prop) {
27
- if (prop instanceof Set) {
28
- const valueArray = [];
29
- for (const value of Array.from(prop.values())) {
30
- if (value instanceof famix_base_element_1.FamixBaseElement) {
31
- valueArray.push({ "ref": value.id });
32
- }
33
- else {
34
- valueArray.push(value);
35
- }
36
- }
37
- this.bufferArray[name] = valueArray;
38
- }
39
- else if (prop instanceof famix_base_element_1.FamixBaseElement) {
40
- this.bufferArray[name] = { "ref": prop.id };
41
- }
42
- else if (prop !== undefined && !(prop instanceof Set)) {
43
- this.bufferArray[name] = prop;
44
- }
45
- }
46
- /**
47
- * Gets a JSON representation of the Famix element
48
- * @returns A JSON representation of the Famix element
49
- */
50
- getJSON() {
51
- return JSON.stringify(this.bufferArray);
52
- }
53
- }
54
- exports.FamixJSONExporter = FamixJSONExporter;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FamixBaseElement = void 0;
4
- class FamixBaseElement {
5
- constructor(repo) {
6
- repo.addElement(this);
7
- }
8
- // @ts-ignore
9
- // tslint:disable-next-line:no-empty
10
- addPropertiesToExporter(exporter) {
11
- }
12
- }
13
- exports.FamixBaseElement = FamixBaseElement;