ts2famix 1.4.1 → 2.0.1

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 (210) hide show
  1. package/LICENSE +1 -0
  2. package/README.md +30 -61
  3. package/dist/analyze.js +4 -2
  4. package/dist/analyze_functions/process_functions.js +285 -131
  5. package/dist/famix_functions/EntityDictionary.js +864 -231
  6. package/dist/famix_functions/helpers_creation.js +61 -10
  7. package/dist/fqn.js +160 -111
  8. package/dist/lib/famix/famix_JSON_exporter.js +55 -0
  9. package/dist/lib/famix/famix_base_element.js +18 -0
  10. package/dist/lib/famix/famix_repository.js +224 -0
  11. package/dist/lib/famix/{src/index.js → index.js} +1 -0
  12. package/dist/lib/famix/model/famix/access.js +40 -0
  13. package/dist/lib/famix/model/famix/accessor.js +17 -0
  14. package/dist/lib/famix/model/famix/alias.js +33 -0
  15. package/dist/lib/famix/model/famix/arrow_function.js +17 -0
  16. package/dist/lib/famix/model/famix/behavioral_entity.js +79 -0
  17. package/dist/lib/famix/model/famix/class.js +71 -0
  18. package/dist/lib/famix/model/famix/comment.js +39 -0
  19. package/dist/lib/famix/model/famix/concretisation.js +31 -0
  20. package/dist/lib/famix/model/famix/container_entity.js +126 -0
  21. package/dist/lib/famix/model/famix/decorator.js +32 -0
  22. package/dist/lib/famix/model/famix/entity.js +17 -0
  23. package/dist/lib/famix/model/famix/enum.js +31 -0
  24. package/dist/lib/famix/model/famix/enum_value.js +25 -0
  25. package/dist/lib/famix/model/famix/function.js +17 -0
  26. package/dist/lib/famix/model/famix/import_clause.js +41 -0
  27. package/dist/lib/famix/model/famix/index.js +86 -0
  28. package/dist/lib/famix/model/famix/indexed_file_anchor.js +38 -0
  29. package/dist/lib/famix/model/famix/inheritance.js +33 -0
  30. package/dist/lib/famix/model/famix/interface.js +64 -0
  31. package/dist/lib/famix/model/famix/invocation.js +54 -0
  32. package/dist/lib/famix/model/famix/method.js +67 -0
  33. package/dist/lib/famix/model/famix/module.js +60 -0
  34. package/dist/lib/famix/model/famix/named_entity.js +78 -0
  35. package/dist/lib/famix/model/famix/parameter.js +25 -0
  36. package/dist/lib/famix/model/famix/parameter_concretisation.js +44 -0
  37. package/dist/lib/famix/model/famix/parameter_type.js +45 -0
  38. package/dist/lib/famix/model/famix/parametric_arrow_function.js +31 -0
  39. package/dist/lib/famix/model/famix/parametric_class.js +44 -0
  40. package/dist/lib/famix/model/famix/parametric_function.js +31 -0
  41. package/dist/lib/famix/model/famix/parametric_interface.js +44 -0
  42. package/dist/lib/famix/model/famix/parametric_method.js +31 -0
  43. package/dist/lib/famix/model/famix/primitive_type.js +17 -0
  44. package/dist/lib/famix/model/famix/property.js +73 -0
  45. package/dist/lib/famix/model/famix/reference.js +33 -0
  46. package/dist/lib/famix/model/famix/scoping_entity.js +36 -0
  47. package/dist/lib/famix/model/famix/script_entity.js +29 -0
  48. package/dist/lib/famix/model/famix/source_anchor.js +27 -0
  49. package/dist/lib/famix/model/famix/source_language.js +35 -0
  50. package/dist/lib/famix/model/famix/sourced_entity.js +60 -0
  51. package/dist/lib/famix/model/famix/structural_entity.js +39 -0
  52. package/dist/lib/famix/model/famix/type.js +73 -0
  53. package/dist/lib/famix/model/famix/variable.js +24 -0
  54. package/dist/lib/ts-complex/cyclomatic-service.js +3 -3
  55. package/dist/refactorer/refactor-getter-setter.js +142 -0
  56. package/dist/ts2famix-cli-wrapper.js +42 -0
  57. package/dist/ts2famix-cli.js +8 -1
  58. package/dist/ts2famix-tsconfig.js +1 -0
  59. package/doc-uml/famix-typescript-model.puml +608 -0
  60. package/doc-uml/famix-typescript-model.svg +1 -0
  61. package/jest.config.json +2 -1
  62. package/package.json +13 -12
  63. package/src/analyze.ts +24 -23
  64. package/src/analyze_functions/process_functions.ts +310 -129
  65. package/src/famix_functions/EntityDictionary.ts +949 -271
  66. package/src/famix_functions/helpers_creation.ts +64 -6
  67. package/src/fqn.ts +169 -96
  68. package/{dist/lib/famix/src/famix_JSON_exporter.js → src/lib/famix/famix_JSON_exporter.ts} +16 -14
  69. package/src/lib/famix/famix_base_element.ts +22 -0
  70. package/{dist/lib/famix/src/famix_repository.js → src/lib/famix/famix_repository.ts} +96 -75
  71. package/src/lib/famix/model/famix/access.ts +50 -0
  72. package/src/lib/famix/model/famix/alias.ts +39 -0
  73. package/src/lib/famix/{src/model/famix/implicit_variable.ts → model/famix/arrow_function.ts} +3 -3
  74. package/src/lib/famix/model/famix/behavioral_entity.ts +97 -0
  75. package/src/lib/famix/model/famix/class.ts +85 -0
  76. package/src/lib/famix/model/famix/comment.ts +47 -0
  77. package/src/lib/famix/model/famix/concretisation.ts +40 -0
  78. package/src/lib/famix/model/famix/container_entity.ts +160 -0
  79. package/src/lib/famix/model/famix/decorator.ts +37 -0
  80. package/src/lib/famix/model/famix/enum.ts +30 -0
  81. package/src/lib/famix/model/famix/enum_value.ts +28 -0
  82. package/src/lib/famix/model/famix/import_clause.ts +51 -0
  83. package/src/lib/famix/{src/model → model}/famix/index.ts +8 -7
  84. package/src/lib/famix/model/famix/indexed_file_anchor.ts +46 -0
  85. package/src/lib/famix/model/famix/inheritance.ts +40 -0
  86. package/src/lib/famix/model/famix/interface.ts +75 -0
  87. package/src/lib/famix/model/famix/invocation.ts +65 -0
  88. package/src/lib/famix/model/famix/method.ts +89 -0
  89. package/src/lib/famix/model/famix/module.ts +71 -0
  90. package/src/lib/famix/model/famix/named_entity.ts +95 -0
  91. package/src/lib/famix/{src/model → model}/famix/parameter.ts +11 -12
  92. package/src/lib/famix/model/famix/parameter_concretisation.ts +51 -0
  93. package/src/lib/famix/model/famix/parameter_type.ts +58 -0
  94. package/src/lib/famix/model/famix/parametric_arrow_function.ts +32 -0
  95. package/src/lib/famix/model/famix/parametric_class.ts +49 -0
  96. package/src/lib/famix/model/famix/parametric_function.ts +32 -0
  97. package/src/lib/famix/model/famix/parametric_interface.ts +49 -0
  98. package/src/lib/famix/model/famix/parametric_method.ts +32 -0
  99. package/src/lib/famix/model/famix/primitive_type.ts +15 -0
  100. package/src/lib/famix/model/famix/property.ts +94 -0
  101. package/src/lib/famix/model/famix/reference.ts +40 -0
  102. package/src/lib/famix/model/famix/scoping_entity.ts +35 -0
  103. package/src/lib/famix/model/famix/script_entity.ts +34 -0
  104. package/src/lib/famix/model/famix/source_anchor.ts +30 -0
  105. package/src/lib/famix/model/famix/source_language.ts +35 -0
  106. package/src/lib/famix/model/famix/sourced_entity.ts +70 -0
  107. package/src/lib/famix/model/famix/structural_entity.ts +43 -0
  108. package/src/lib/famix/model/famix/type.ts +87 -0
  109. package/src/lib/famix/model/famix/variable.ts +27 -0
  110. package/src/lib/famix/package.json +1 -1
  111. package/src/lib/ts-complex/cyclomatic-service.ts +10 -10
  112. package/src/refactorer/refactor-getter-setter.ts +140 -0
  113. package/src/ts2famix-cli-wrapper.ts +21 -0
  114. package/src/ts2famix-cli.ts +8 -2
  115. package/tsconfig.check-tests.json +14 -0
  116. package/tsconfig.json +71 -69
  117. package/dist/famix2puml.js +0 -125
  118. package/dist/lib/famix/src/famix_base_element.js +0 -17
  119. package/dist/lib/famix/src/model/famix/access.js +0 -39
  120. package/dist/lib/famix/src/model/famix/accessor.js +0 -16
  121. package/dist/lib/famix/src/model/famix/alias.js +0 -32
  122. package/dist/lib/famix/src/model/famix/association.js +0 -36
  123. package/dist/lib/famix/src/model/famix/behavioral_entity.js +0 -81
  124. package/dist/lib/famix/src/model/famix/class.js +0 -70
  125. package/dist/lib/famix/src/model/famix/comment.js +0 -38
  126. package/dist/lib/famix/src/model/famix/container_entity.js +0 -125
  127. package/dist/lib/famix/src/model/famix/decorator.js +0 -31
  128. package/dist/lib/famix/src/model/famix/entity.js +0 -16
  129. package/dist/lib/famix/src/model/famix/enum.js +0 -30
  130. package/dist/lib/famix/src/model/famix/enum_value.js +0 -24
  131. package/dist/lib/famix/src/model/famix/function.js +0 -16
  132. package/dist/lib/famix/src/model/famix/implicit_variable.js +0 -16
  133. package/dist/lib/famix/src/model/famix/import_clause.js +0 -39
  134. package/dist/lib/famix/src/model/famix/index.js +0 -83
  135. package/dist/lib/famix/src/model/famix/indexed_file_anchor.js +0 -51
  136. package/dist/lib/famix/src/model/famix/inheritance.js +0 -32
  137. package/dist/lib/famix/src/model/famix/interface.js +0 -63
  138. package/dist/lib/famix/src/model/famix/invocation.js +0 -53
  139. package/dist/lib/famix/src/model/famix/method.js +0 -66
  140. package/dist/lib/famix/src/model/famix/module.js +0 -31
  141. package/dist/lib/famix/src/model/famix/named_entity.js +0 -77
  142. package/dist/lib/famix/src/model/famix/namespace.js +0 -24
  143. package/dist/lib/famix/src/model/famix/parameter.js +0 -24
  144. package/dist/lib/famix/src/model/famix/parameter_type.js +0 -24
  145. package/dist/lib/famix/src/model/famix/parameterizable_class.js +0 -30
  146. package/dist/lib/famix/src/model/famix/parameterizable_interface.js +0 -30
  147. package/dist/lib/famix/src/model/famix/parameterized_type.js +0 -36
  148. package/dist/lib/famix/src/model/famix/primitive_type.js +0 -16
  149. package/dist/lib/famix/src/model/famix/property.js +0 -44
  150. package/dist/lib/famix/src/model/famix/reference.js +0 -32
  151. package/dist/lib/famix/src/model/famix/scoping_entity.js +0 -35
  152. package/dist/lib/famix/src/model/famix/script_entity.js +0 -30
  153. package/dist/lib/famix/src/model/famix/source_anchor.js +0 -26
  154. package/dist/lib/famix/src/model/famix/source_language.js +0 -35
  155. package/dist/lib/famix/src/model/famix/sourced_entity.js +0 -59
  156. package/dist/lib/famix/src/model/famix/structural_entity.js +0 -38
  157. package/dist/lib/famix/src/model/famix/text_anchor.js +0 -37
  158. package/dist/lib/famix/src/model/famix/type.js +0 -71
  159. package/dist/lib/famix/src/model/famix/variable.js +0 -23
  160. package/doc-uml/metamodel-full.svg +0 -1
  161. package/doc-uml/metamodel.svg +0 -1
  162. package/jest.config-old.ts +0 -199
  163. package/plantuml.jar +0 -0
  164. package/src/famix2puml.ts +0 -119
  165. package/src/lib/famix/package-lock.json +0 -301
  166. package/src/lib/famix/readme.md +0 -5
  167. package/src/lib/famix/src/famix_JSON_exporter.ts +0 -56
  168. package/src/lib/famix/src/famix_base_element.ts +0 -22
  169. package/src/lib/famix/src/famix_repository.ts +0 -243
  170. package/src/lib/famix/src/model/famix/access.ts +0 -53
  171. package/src/lib/famix/src/model/famix/alias.ts +0 -41
  172. package/src/lib/famix/src/model/famix/association.ts +0 -44
  173. package/src/lib/famix/src/model/famix/behavioral_entity.ts +0 -107
  174. package/src/lib/famix/src/model/famix/class.ts +0 -86
  175. package/src/lib/famix/src/model/famix/comment.ts +0 -50
  176. package/src/lib/famix/src/model/famix/container_entity.ts +0 -165
  177. package/src/lib/famix/src/model/famix/decorator.ts +0 -39
  178. package/src/lib/famix/src/model/famix/enum.ts +0 -31
  179. package/src/lib/famix/src/model/famix/enum_value.ts +0 -29
  180. package/src/lib/famix/src/model/famix/import_clause.ts +0 -53
  181. package/src/lib/famix/src/model/famix/indexed_file_anchor.ts +0 -71
  182. package/src/lib/famix/src/model/famix/inheritance.ts +0 -42
  183. package/src/lib/famix/src/model/famix/interface.ts +0 -75
  184. package/src/lib/famix/src/model/famix/invocation.ts +0 -68
  185. package/src/lib/famix/src/model/famix/method.ts +0 -96
  186. package/src/lib/famix/src/model/famix/module.ts +0 -31
  187. package/src/lib/famix/src/model/famix/named_entity.ts +0 -98
  188. package/src/lib/famix/src/model/famix/namespace.ts +0 -28
  189. package/src/lib/famix/src/model/famix/parameter_type.ts +0 -33
  190. package/src/lib/famix/src/model/famix/parameterizable_class.ts +0 -31
  191. package/src/lib/famix/src/model/famix/parameterizable_interface.ts +0 -31
  192. package/src/lib/famix/src/model/famix/parameterized_type.ts +0 -40
  193. package/src/lib/famix/src/model/famix/primitive_type.ts +0 -15
  194. package/src/lib/famix/src/model/famix/property.ts +0 -54
  195. package/src/lib/famix/src/model/famix/reference.ts +0 -42
  196. package/src/lib/famix/src/model/famix/scoping_entity.ts +0 -35
  197. package/src/lib/famix/src/model/famix/script_entity.ts +0 -38
  198. package/src/lib/famix/src/model/famix/source_anchor.ts +0 -31
  199. package/src/lib/famix/src/model/famix/source_language.ts +0 -37
  200. package/src/lib/famix/src/model/famix/sourced_entity.ts +0 -73
  201. package/src/lib/famix/src/model/famix/structural_entity.ts +0 -44
  202. package/src/lib/famix/src/model/famix/text_anchor.ts +0 -49
  203. package/src/lib/famix/src/model/famix/type.ts +0 -88
  204. package/src/lib/famix/src/model/famix/variable.ts +0 -28
  205. package/src/lib/famix/tsconfig.json +0 -27
  206. package/src/lib/famix/tslint.json +0 -15
  207. /package/src/lib/famix/{src/index.ts → index.ts} +0 -0
  208. /package/src/lib/famix/{src/model → model}/famix/accessor.ts +0 -0
  209. /package/src/lib/famix/{src/model → model}/famix/entity.ts +0 -0
  210. /package/src/lib/famix/{src/model → model}/famix/function.ts +0 -0
@@ -1,216 +1,238 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FamixRepository = void 0;
4
- const famix_1 = require("./model/famix");
1
+ import { FamixBaseElement } from "./famix_base_element";
2
+ import { Class, Interface, Variable, Method, ArrowFunction, Function as FamixFunctionEntity, Type, NamedEntity, ScriptEntity, Module, SourceLanguage } from "./model/famix";
3
+ import * as Famix from "./model/famix";
4
+ import { TSMorphObjectType } from "../../famix_functions/EntityDictionary";
5
5
  /**
6
6
  * This class is used to store all Famix elements
7
7
  */
8
- class FamixRepository {
8
+ export class FamixRepository {
9
+ private elements = new Set<FamixBaseElement>(); // All Famix elements
10
+ private famixClasses = new Set<Class>(); // All Famix classes
11
+ private famixInterfaces = new Set<Interface>(); // All Famix interfaces
12
+ private famixModules = new Set<Module>(); // All Famix namespaces
13
+ private famixMethods = new Set<Method>(); // All Famix methods
14
+ private famixVariables = new Set<Variable>(); // All Famix variables
15
+ private famixFunctions = new Set<FamixFunctionEntity>(); // All Famix functions
16
+ private famixFiles = new Set<ScriptEntity | Module>(); // All Famix files
17
+ private idCounter = 1; // Id counter
18
+ private absolutePath: string = "";
19
+ private fmxElementObjectMap = new Map<Famix.Entity, TSMorphObjectType>();
20
+ private tsMorphObjectMap = new Map<TSMorphObjectType, Famix.Entity>(); // TODO: add this map to have two-way mapping between Famix and TS Morph objects
21
+
9
22
  constructor() {
10
- this.elements = new Set(); // All Famix elements
11
- this.famixClasses = new Set(); // All Famix classes
12
- this.famixInterfaces = new Set(); // All Famix interfaces
13
- this.famixNamespaces = new Set(); // All Famix namespaces
14
- this.famixMethods = new Set(); // All Famix methods
15
- this.famixVariables = new Set(); // All Famix variables
16
- this.famixFunctions = new Set(); // All Famix functions
17
- this.famixFiles = new Set(); // All Famix files
18
- this.idCounter = 1; // Id counter
19
- this.absolutePath = "";
20
- this.fmxElementObjectMap = new Map();
21
- this.addElement(new famix_1.SourceLanguage()); // add the source language entity (TypeScript)
22
- }
23
- setFmxElementObjectMap(fmxElementObjectMap) {
23
+ this.addElement(new SourceLanguage()); // add the source language entity (TypeScript)
24
+ }
25
+
26
+ public setFmxElementObjectMap(fmxElementObjectMap: Map<Famix.Entity, TSMorphObjectType>) {
24
27
  this.fmxElementObjectMap = fmxElementObjectMap;
25
28
  }
26
- getFmxElementObjectMap() {
29
+
30
+ public getFmxElementObjectMap() {
27
31
  return this.fmxElementObjectMap;
28
32
  }
29
- getAbsolutePath() {
33
+
34
+ public getAbsolutePath(): string {
30
35
  return this.absolutePath;
31
36
  }
32
- setAbsolutePath(path) {
37
+
38
+ public setAbsolutePath(path: string) {
33
39
  this.absolutePath = path;
34
40
  }
41
+
35
42
  /**
36
43
  * Gets a Famix entity by id
37
44
  * @param id An id of a Famix entity
38
45
  * @returns The Famix entity corresponding to the id or undefined if it doesn't exist
39
46
  */
40
- getFamixEntityById(id) {
47
+ public getFamixEntityById(id: number): FamixBaseElement | undefined {
41
48
  const entity = Array.from(this.elements.values()).find(e => e.id === id);
42
49
  return entity;
43
50
  }
51
+
44
52
  /**
45
53
  * Gets a Famix entity by fully qualified name
46
54
  * @param fullyQualifiedName A fully qualified name
47
55
  * @returns The Famix entity corresponding to the fully qualified name or undefined if it doesn't exist
48
56
  */
49
- getFamixEntityByFullyQualifiedName(fullyQualifiedName) {
50
- const allEntities = Array.from(this.elements.values()).filter(e => e instanceof famix_1.NamedEntity);
51
- const entity = allEntities.find(e => e.getFullyQualifiedName() === fullyQualifiedName);
57
+ public getFamixEntityByFullyQualifiedName(fullyQualifiedName: string): FamixBaseElement | undefined {
58
+ const allEntities = Array.from(this.elements.values()).filter(e => e instanceof NamedEntity) as Array<NamedEntity>;
59
+ const entity = allEntities.find(e => e.fullyQualifiedName === fullyQualifiedName);
52
60
  return entity;
53
61
  }
54
- export(arg0) {
62
+
63
+ export(arg0: { format: string; }) {
55
64
  if (arg0.format === "json") {
56
65
  return this.getJSON();
57
- }
58
- else {
66
+ } else {
59
67
  throw new Error("Unsupported format");
60
68
  }
61
69
  }
70
+
71
+
62
72
  // Only for tests
73
+
63
74
  /**
64
75
  * Gets all Famix entities
65
76
  * @returns All Famix entities
66
77
  */
67
- _getAllEntities() {
78
+ public _getAllEntities(): Set<FamixBaseElement> {
68
79
  return new Set(Array.from(this.elements.values()));
69
80
  }
81
+
70
82
  /**
71
83
  * Gets all Famix entities of a given type
72
84
  * @param theType A type of Famix entity
73
85
  * @returns All Famix entities of the given type
74
86
  */
75
- _getAllEntitiesWithType(theType) {
76
- return new Set(Array.from(this.elements.values()).filter(e => e.constructor.name === theType));
87
+ public _getAllEntitiesWithType(theType: string): Set<FamixBaseElement> {
88
+ return new Set(Array.from(this.elements.values()).filter(e => (e as FamixBaseElement).constructor.name === theType));
77
89
  }
90
+
78
91
  /**
79
92
  * Gets a Famix class by name
80
93
  * @param name A class name
81
94
  * @returns The Famix class corresponding to the name or undefined if it doesn't exist
82
95
  */
83
- _getFamixClass(fullyQualifiedName) {
84
- return Array.from(this.famixClasses.values()).find(ns => ns.getFullyQualifiedName() === fullyQualifiedName);
96
+ public _getFamixClass(fullyQualifiedName: string): Class | undefined {
97
+ return Array.from(this.famixClasses.values()).find(ns => ns.fullyQualifiedName === fullyQualifiedName);
85
98
  }
99
+
86
100
  /**
87
101
  * Gets a Famix interface by name
88
102
  * @param name An interface name
89
103
  * @returns The Famix interface corresponding to the name or undefined if it doesn't exist
90
104
  */
91
- _getFamixInterface(fullyQualifiedName) {
92
- return Array.from(this.famixInterfaces.values()).find(ns => ns.getFullyQualifiedName() === fullyQualifiedName);
105
+ public _getFamixInterface(fullyQualifiedName: string): Interface | undefined {
106
+ return Array.from(this.famixInterfaces.values()).find(ns => ns.fullyQualifiedName === fullyQualifiedName);
93
107
  }
108
+
94
109
  /**
95
110
  * Gets a Famix method by name
96
111
  * @param name A method name
97
112
  * @returns The Famix method corresponding to the name or undefined if it doesn't exist
98
113
  */
99
- _getFamixMethod(fullyQualifiedName) {
100
- return Array.from(this.famixMethods.values()).find(ns => ns.getFullyQualifiedName() === fullyQualifiedName);
114
+ public _getFamixMethod(fullyQualifiedName: string): Method | undefined {
115
+ return Array.from(this.famixMethods.values()).find(ns => ns.fullyQualifiedName === fullyQualifiedName);
101
116
  }
117
+
102
118
  /**
103
119
  * Gets a Famix function by name
104
120
  * @param name A function name
105
121
  * @returns The Famix function corresponding to the name or undefined if it doesn't exist
106
122
  */
107
- _getFamixFunction(fullyQualifiedName) {
108
- return Array.from(this.famixFunctions.values()).find(ns => ns.getFullyQualifiedName() === fullyQualifiedName);
123
+ public _getFamixFunction(fullyQualifiedName: string): FamixFunctionEntity | undefined {
124
+ return Array.from(this.famixFunctions.values()).find(ns => ns.fullyQualifiedName === fullyQualifiedName);
109
125
  }
126
+
127
+
110
128
  /**
111
129
  * Gets a Famix variable by name
112
130
  * @param name A variable name
113
131
  * @returns The Famix variable corresponding to the name or undefined if it doesn't exist
114
132
  */
115
- _getFamixVariable(fullyQualifiedName) {
116
- return Array.from(this.famixVariables.values()).find(v => v.getFullyQualifiedName() === fullyQualifiedName);
133
+ public _getFamixVariable(fullyQualifiedName: string): Variable | undefined {
134
+ return Array.from(this.famixVariables.values()).find(v => v.fullyQualifiedName === fullyQualifiedName);
117
135
  }
136
+
118
137
  /**
119
138
  * Gets a Famix namespace by name
120
139
  * @param name A namespace name
121
140
  * @returns The Famix namespace corresponding to the name or undefined if it doesn't exist
122
141
  */
123
- _getFamixNamespace(fullyQualifiedName) {
124
- return Array.from(this.famixNamespaces.values()).find(ns => ns.getFullyQualifiedName() === fullyQualifiedName);
142
+ public _getFamixModule(fullyQualifiedName: string): Module | undefined {
143
+ return Array.from(this.famixModules.values()).find(ns => ns.fullyQualifiedName === fullyQualifiedName);
125
144
  }
145
+
126
146
  /**
127
147
  * Gets all Famix namespaces
128
148
  * @returns All Famix namespaces
129
149
  */
130
- _getFamixNamespaces() {
131
- return new Set(Array.from(this.famixNamespaces.values()));
150
+ public _getFamixModules(): Set<Module> {
151
+ return new Set(Array.from(this.famixModules.values()));
132
152
  }
153
+
133
154
  /**
134
155
  * Gets a Famix file by name
135
156
  * @param name A file name
136
157
  * @returns The Famix file corresponding to the name or undefined if it doesn't exist
137
158
  */
138
- _getFamixFile(fullyQualifiedName) {
139
- return Array.from(this.famixFiles.values()).find(ns => ns.getName() === fullyQualifiedName);
159
+ public _getFamixFile(fullyQualifiedName: string): ScriptEntity | Module | undefined {
160
+ return Array.from(this.famixFiles.values()).find(ns => ns.name === fullyQualifiedName);
140
161
  }
162
+
141
163
  /**
142
164
  * Gets all Famix files
143
165
  * @returns All Famix files
144
166
  */
145
- _getFamixFiles() {
167
+ public _getFamixFiles(): Set<ScriptEntity | Module> {
146
168
  return new Set(Array.from(this.famixFiles.values()));
147
169
  }
170
+
148
171
  /**
149
172
  * Gets all method names as a set from a class
150
173
  * @param className A class name
151
174
  * @returns The set of class "className" method names
152
175
  */
153
- _methodNamesAsSetFromClass(className) {
154
- const theClass = this._getFamixClass(className);
155
- return new Set(Array.from(theClass.getMethods()).map(m => m.getName()));
176
+ public _methodNamesAsSetFromClass(className: string): Set<string> {
177
+ const theClass = this._getFamixClass(className) as Class;
178
+ return new Set(Array.from(theClass.methods).map(m => m.name));
156
179
  }
180
+
157
181
  /**
158
182
  * Gets all method parents as a set from a class
159
183
  * @param className A class name
160
184
  * @returns The set of class "className" method parents
161
185
  */
162
- _methodParentsAsSetFromClass(className) {
163
- const theClass = this._getFamixClass(className);
164
- return new Set(Array.from(theClass.getMethods()).map(m => m.getParentEntity()));
186
+ public _methodParentsAsSetFromClass(className: string): Set<Type> {
187
+ const theClass = this._getFamixClass(className) as Class;
188
+ return new Set(Array.from(theClass.methods).map(m => m.parentEntity));
165
189
  }
190
+
166
191
  /**
167
192
  * Gets the map of Famix element ids and their Famix element from a JSON model
168
193
  * @param model A JSON model
169
194
  * @returns The map of Famix element ids and their Famix element from the JSON model
170
195
  */
171
- _initMapFromModel(model) {
172
- const parsedModel = JSON.parse(model);
173
- const idToElementMap = new Map();
196
+ public _initMapFromModel(model: string): Map<number, unknown> {
197
+ const parsedModel: Array<FamixBaseElement> = JSON.parse(model);
198
+ const idToElementMap: Map<number, unknown> = new Map();
174
199
  parsedModel.forEach(element => {
175
200
  idToElementMap.set(element.id, element);
176
201
  });
177
202
  return idToElementMap;
178
203
  }
204
+
205
+
179
206
  /**
180
207
  * Adds a Famix element to the repository
181
208
  * @param element A Famix element
182
209
  */
183
- addElement(element) {
184
- if (element instanceof famix_1.Class) {
210
+ public addElement(element: FamixBaseElement): void {
211
+ if (element instanceof Class) {
185
212
  this.famixClasses.add(element);
186
- }
187
- else if (element instanceof famix_1.Interface) {
213
+ } else if (element instanceof Interface) {
188
214
  this.famixInterfaces.add(element);
189
- }
190
- else if (element instanceof famix_1.Namespace) {
191
- this.famixNamespaces.add(element);
192
- }
193
- else if (element instanceof famix_1.Variable) {
215
+ } else if (element instanceof Module) {
216
+ this.famixModules.add(element);
217
+ } else if (element instanceof Variable) {
194
218
  this.famixVariables.add(element);
195
- }
196
- else if (element instanceof famix_1.Method) {
219
+ } else if (element instanceof Method) {
197
220
  this.famixMethods.add(element);
198
- }
199
- else if (element instanceof famix_1.Function) {
221
+ } else if (element instanceof FamixFunctionEntity || element instanceof ArrowFunction) {
200
222
  this.famixFunctions.add(element);
201
- }
202
- else if (element instanceof famix_1.ScriptEntity || element instanceof famix_1.Module) {
223
+ } else if (element instanceof ScriptEntity || element instanceof Module) {
203
224
  this.famixFiles.add(element);
204
225
  }
205
226
  this.elements.add(element);
206
227
  element.id = this.idCounter;
207
228
  this.idCounter++;
208
229
  }
230
+
209
231
  /**
210
232
  * Gets a JSON representation of the repository
211
233
  * @returns A JSON representation of the repository
212
234
  */
213
- getJSON() {
235
+ public getJSON(): string {
214
236
  let ret = "[";
215
237
  for (const element of Array.from(this.elements.values())) {
216
238
  ret = ret + element.getJSON() + ",";
@@ -219,4 +241,3 @@ class FamixRepository {
219
241
  return ret + "]";
220
242
  }
221
243
  }
222
- exports.FamixRepository = FamixRepository;
@@ -0,0 +1,50 @@
1
+ import { FamixJSONExporter } from "../../famix_JSON_exporter";
2
+ import { StructuralEntity } from "./structural_entity";
3
+ import { ContainerEntity } from "./container_entity";
4
+ import { Entity } from "./entity";
5
+
6
+ export class Access extends Entity {
7
+
8
+ private _accessor!: ContainerEntity;
9
+ private _variable!: StructuralEntity;
10
+ private _isWrite!: boolean;
11
+
12
+ public getJSON(): string {
13
+ const json: FamixJSONExporter = new FamixJSONExporter("Access", this);
14
+ this.addPropertiesToExporter(json);
15
+ return json.getJSON();
16
+ }
17
+
18
+ public addPropertiesToExporter(exporter: FamixJSONExporter): void {
19
+ super.addPropertiesToExporter(exporter);
20
+ exporter.addProperty("accessor", this.accessor);
21
+ exporter.addProperty("variable", this.variable);
22
+ exporter.addProperty("isWrite", this.isWrite);
23
+ }
24
+
25
+ get accessor(): ContainerEntity {
26
+ return this._accessor;
27
+ }
28
+
29
+ set accessor(accessor: ContainerEntity) {
30
+ this._accessor = accessor;
31
+ accessor.addAccess(this);
32
+ }
33
+
34
+ get variable(): StructuralEntity {
35
+ return this._variable;
36
+ }
37
+
38
+ set variable(variable: StructuralEntity) {
39
+ this._variable = variable;
40
+ variable.addIncomingAccess(this);
41
+ }
42
+
43
+ get isWrite(): boolean {
44
+ return this._isWrite;
45
+ }
46
+
47
+ set isWrite(isWrite: boolean) {
48
+ this._isWrite = isWrite;
49
+ }
50
+ }
@@ -0,0 +1,39 @@
1
+ import { FamixJSONExporter } from "../../famix_JSON_exporter";
2
+ import { NamedEntity } from "./named_entity";
3
+ import { Type } from "./type";
4
+
5
+ export class Alias extends NamedEntity {
6
+
7
+ private _parentEntity!: NamedEntity;
8
+ private _aliasedEntity!: Type;
9
+
10
+ public getJSON(): string {
11
+ const json: FamixJSONExporter = new FamixJSONExporter("Alias", this);
12
+ this.addPropertiesToExporter(json);
13
+ return json.getJSON();
14
+ }
15
+
16
+ public addPropertiesToExporter(exporter: FamixJSONExporter): void {
17
+ super.addPropertiesToExporter(exporter);
18
+ exporter.addProperty("parentType", this.parentEntity);
19
+ exporter.addProperty("aliasedEntity", this.aliasedEntity);
20
+ }
21
+
22
+ get parentEntity(): NamedEntity {
23
+ return this._parentEntity;
24
+ }
25
+
26
+ set parentEntity(parentEntity: NamedEntity) {
27
+ this._parentEntity = parentEntity;
28
+ parentEntity.addAlias(this);
29
+ }
30
+
31
+ get aliasedEntity(): Type {
32
+ return this._aliasedEntity;
33
+ }
34
+
35
+ set aliasedEntity(aliasedEntity: Type) {
36
+ this._aliasedEntity = aliasedEntity;
37
+ aliasedEntity.addTypeAlias(this);
38
+ }
39
+ }
@@ -1,10 +1,10 @@
1
1
  import { FamixJSONExporter } from "../../famix_JSON_exporter";
2
- import { Variable } from "./variable";
2
+ import { BehavioralEntity } from "./behavioral_entity";
3
3
 
4
- export class ImplicitVariable extends Variable {
4
+ export class ArrowFunction extends BehavioralEntity {
5
5
 
6
6
  public getJSON(): string {
7
- const json: FamixJSONExporter = new FamixJSONExporter("ImplicitVariable", this);
7
+ const json: FamixJSONExporter = new FamixJSONExporter("ArrowFunction", this);
8
8
  this.addPropertiesToExporter(json);
9
9
  return json.getJSON();
10
10
  }
@@ -0,0 +1,97 @@
1
+ import { FamixJSONExporter } from "../../famix_JSON_exporter";
2
+ import { Type } from "./type";
3
+ import { ContainerEntity } from "./container_entity";
4
+ import { Parameter } from "./parameter";
5
+ import { Invocation } from "./invocation";
6
+ import { ParameterType } from "./parameter_type";
7
+
8
+ export class BehavioralEntity extends ContainerEntity {
9
+
10
+ private _signature!: string;
11
+ private _parameters: Set<Parameter> = new Set();
12
+
13
+ public addParameter(parameter: Parameter): void {
14
+ if (!this._parameters.has(parameter)) {
15
+ this._parameters.add(parameter);
16
+ parameter.parentEntity = this;
17
+ }
18
+ }
19
+
20
+ private _numberOfParameters!: number;
21
+ private _incomingInvocations: Set<Invocation> = new Set();
22
+
23
+ public addIncomingInvocation(incomingInvocation: Invocation): void {
24
+ if (!this._incomingInvocations.has(incomingInvocation)) {
25
+ this._incomingInvocations.add(incomingInvocation);
26
+ incomingInvocation.addCandidate(this);
27
+ }
28
+ }
29
+
30
+ private _declaredType!: Type;
31
+ private _genericParameters: Set<ParameterType> = new Set();
32
+
33
+ public addGenericParameter(genericParameter: ParameterType): void {
34
+ if (!this._genericParameters.has(genericParameter)) {
35
+ this._genericParameters.add(genericParameter);
36
+ genericParameter.parentGeneric = this;
37
+ }
38
+ }
39
+
40
+ clearGenericParameters(): void {
41
+ this._genericParameters.clear();
42
+ }
43
+
44
+ public getJSON(): string {
45
+ const json: FamixJSONExporter = new FamixJSONExporter("BehavioralEntity", this);
46
+ this.addPropertiesToExporter(json);
47
+ return json.getJSON();
48
+ }
49
+
50
+ public addPropertiesToExporter(exporter: FamixJSONExporter): void {
51
+ super.addPropertiesToExporter(exporter);
52
+ exporter.addProperty("signature", this.signature);
53
+ exporter.addProperty("parameters", this.parameters);
54
+ exporter.addProperty("numberOfParameters", this.numberOfParameters);
55
+ exporter.addProperty("incomingInvocations", this.incomingInvocations);
56
+ exporter.addProperty("declaredType", this.declaredType);
57
+ /* don't add the property here, since it doesn't apply to all subclasses */
58
+ // exporter.addProperty("genericParameters", this.getGenericParameters());
59
+ }
60
+
61
+ get signature(): string {
62
+ return this._signature;
63
+ }
64
+
65
+ set signature(signature: string) {
66
+ this._signature = signature;
67
+ }
68
+
69
+ get parameters(): Set<Parameter> {
70
+ return this._parameters;
71
+ }
72
+
73
+ get numberOfParameters(): number {
74
+ return this._numberOfParameters;
75
+ }
76
+
77
+ set numberOfParameters(numberOfParameters: number) {
78
+ this._numberOfParameters = numberOfParameters;
79
+ }
80
+
81
+ get incomingInvocations(): Set<Invocation> {
82
+ return this._incomingInvocations;
83
+ }
84
+
85
+ get declaredType(): Type {
86
+ return this._declaredType;
87
+ }
88
+
89
+ set declaredType(declaredType: Type) {
90
+ this._declaredType = declaredType;
91
+ declaredType.addBehavioralEntityWithDeclaredType(this);
92
+ }
93
+
94
+ get genericParameters(): Set<ParameterType> {
95
+ return this._genericParameters;
96
+ }
97
+ }
@@ -0,0 +1,85 @@
1
+ import { FamixJSONExporter } from "../../famix_JSON_exporter";
2
+ import { Type } from "./type";
3
+ import { Method } from "./method";
4
+ import { Property } from "./property";
5
+ import { Inheritance } from "./inheritance";
6
+
7
+ export class Class extends Type {
8
+
9
+ private _isAbstract!: boolean;
10
+ private _properties: Set<Property> = new Set();
11
+
12
+ public addProperty(property: Property): void {
13
+ if (!this._properties.has(property)) {
14
+ this._properties.add(property);
15
+ property.parentEntity = this;
16
+ }
17
+ }
18
+
19
+ private _methods: Set<Method> = new Set();
20
+
21
+ public addMethod(method: Method): void {
22
+ if (!this._methods.has(method)) {
23
+ this._methods.add(method);
24
+ method.parentEntity = this;
25
+ }
26
+ }
27
+
28
+ private _superInheritances: Set<Inheritance> = new Set();
29
+
30
+ public addSuperInheritance(superInheritance: Inheritance): void {
31
+ if (!this._superInheritances.has(superInheritance)) {
32
+ this._superInheritances.add(superInheritance);
33
+ superInheritance.subclass = this;
34
+ }
35
+ }
36
+
37
+ private _subInheritances: Set<Inheritance> = new Set();
38
+
39
+ public addSubInheritance(subInheritance: Inheritance): void {
40
+ if (!this._subInheritances.has(subInheritance)) {
41
+ this._subInheritances.add(subInheritance);
42
+ subInheritance.superclass = this;
43
+ }
44
+ }
45
+
46
+
47
+ public getJSON(): string {
48
+ const json: FamixJSONExporter = new FamixJSONExporter("Class", this);
49
+ this.addPropertiesToExporter(json);
50
+ return json.getJSON();
51
+ }
52
+
53
+ public addPropertiesToExporter(exporter: FamixJSONExporter): void {
54
+ super.addPropertiesToExporter(exporter);
55
+ exporter.addProperty("isAbstract", this.isAbstract);
56
+ exporter.addProperty("attributes", this.properties); // Moose (10) codes them as attributes
57
+ exporter.addProperty("methods", this.methods);
58
+ exporter.addProperty("superInheritances", this.superInheritances);
59
+ exporter.addProperty("subInheritances", this.subInheritances);
60
+ }
61
+
62
+ get isAbstract(): boolean {
63
+ return this._isAbstract;
64
+ }
65
+
66
+ set isAbstract(isAbstract: boolean) {
67
+ this._isAbstract = isAbstract;
68
+ }
69
+
70
+ get properties(): Set<Property> {
71
+ return this._properties;
72
+ }
73
+
74
+ get methods(): Set<Method> {
75
+ return this._methods;
76
+ }
77
+
78
+ get superInheritances(): Set<Inheritance> {
79
+ return this._superInheritances;
80
+ }
81
+
82
+ get subInheritances(): Set<Inheritance> {
83
+ return this._subInheritances;
84
+ }
85
+ }
@@ -0,0 +1,47 @@
1
+ import { FamixJSONExporter } from "../../famix_JSON_exporter";
2
+ import { SourcedEntity } from "./sourced_entity";
3
+
4
+ export class Comment extends SourcedEntity {
5
+
6
+ private _isJSDoc!: boolean;
7
+ private _container!: SourcedEntity;
8
+ private _content!: string;
9
+
10
+ public getJSON(): string {
11
+ const json: FamixJSONExporter = new FamixJSONExporter("Comment", this);
12
+ this.addPropertiesToExporter(json);
13
+ return json.getJSON();
14
+ }
15
+
16
+ public addPropertiesToExporter(exporter: FamixJSONExporter): void {
17
+ super.addPropertiesToExporter(exporter);
18
+ exporter.addProperty("isJSDoc", this.isJSDoc);
19
+ exporter.addProperty("commentedEntity", this.container);
20
+ exporter.addProperty("content", this.content);
21
+ }
22
+
23
+ get isJSDoc(): boolean {
24
+ return this._isJSDoc;
25
+ }
26
+
27
+ set isJSDoc(isJSDoc: boolean) {
28
+ this._isJSDoc = isJSDoc;
29
+ }
30
+
31
+ get container(): SourcedEntity {
32
+ return this._container;
33
+ }
34
+
35
+ set container(container: SourcedEntity) {
36
+ this._container = container;
37
+ container.addComment(this);
38
+ }
39
+
40
+ get content(): string {
41
+ return this._content;
42
+ }
43
+
44
+ set content(content: string) {
45
+ this._content = content;
46
+ }
47
+ }