ts2famix 2.1.0-beta.2 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +24 -24
- package/LICENSE +24 -24
- package/README.md +78 -78
- package/dist/analyze.js +3 -3
- package/dist/analyze_functions/process_functions.js +92 -62
- package/dist/famix_functions/EntityDictionary.js +674 -599
- package/dist/famix_functions/helpers_creation.js +18 -12
- package/dist/fqn.js +351 -18
- package/dist/lib/famix/famix_JSON_exporter.js +1 -1
- package/dist/lib/famix/famix_base_element.js +1 -1
- package/dist/lib/famix/famix_repository.js +14 -5
- package/dist/lib/famix/index.js +1 -1
- package/dist/lib/famix/model/famix/access.js +1 -1
- package/dist/lib/famix/model/famix/accessor.js +1 -1
- package/dist/lib/famix/model/famix/alias.js +1 -1
- package/dist/lib/famix/model/famix/arrow_function.js +1 -1
- package/dist/lib/famix/model/famix/behavioral_entity.js +1 -1
- package/dist/lib/famix/model/famix/class.js +1 -1
- package/dist/lib/famix/model/famix/comment.js +1 -1
- package/dist/lib/famix/model/famix/concretisation.js +1 -1
- package/dist/lib/famix/model/famix/container_entity.js +1 -1
- package/dist/lib/famix/model/famix/decorator.js +1 -1
- package/dist/lib/famix/model/famix/entity.js +1 -1
- package/dist/lib/famix/model/famix/enum.js +1 -1
- package/dist/lib/famix/model/famix/enum_value.js +1 -1
- package/dist/lib/famix/model/famix/function.js +1 -1
- package/dist/lib/famix/model/famix/import_clause.js +1 -1
- package/dist/lib/famix/model/famix/index.js +1 -1
- package/dist/lib/famix/model/famix/indexed_file_anchor.js +1 -1
- package/dist/lib/famix/model/famix/inheritance.js +1 -1
- package/dist/lib/famix/model/famix/interface.js +1 -1
- package/dist/lib/famix/model/famix/invocation.js +1 -1
- package/dist/lib/famix/model/famix/method.js +1 -1
- package/dist/lib/famix/model/famix/module.js +2 -2
- package/dist/lib/famix/model/famix/named_entity.js +1 -1
- package/dist/lib/famix/model/famix/parameter.js +1 -1
- package/dist/lib/famix/model/famix/parameter_concretisation.js +1 -1
- package/dist/lib/famix/model/famix/parameter_type.js +1 -1
- package/dist/lib/famix/model/famix/parametric_arrow_function.js +1 -1
- package/dist/lib/famix/model/famix/parametric_class.js +1 -1
- package/dist/lib/famix/model/famix/parametric_function.js +1 -1
- package/dist/lib/famix/model/famix/parametric_interface.js +1 -1
- package/dist/lib/famix/model/famix/parametric_method.js +1 -1
- package/dist/lib/famix/model/famix/primitive_type.js +1 -1
- package/dist/lib/famix/model/famix/property.js +1 -1
- package/dist/lib/famix/model/famix/reference.js +1 -1
- package/dist/lib/famix/model/famix/scoping_entity.js +1 -1
- package/dist/lib/famix/model/famix/script_entity.js +1 -1
- package/dist/lib/famix/model/famix/source_anchor.js +1 -1
- package/dist/lib/famix/model/famix/source_language.js +1 -1
- package/dist/lib/famix/model/famix/sourced_entity.js +1 -1
- package/dist/lib/famix/model/famix/structural_entity.js +1 -1
- package/dist/lib/famix/model/famix/type.js +1 -1
- package/dist/lib/famix/model/famix/variable.js +1 -1
- package/dist/lib/ts-complex/cyclomatic-service.js +1 -1
- package/dist/refactorer/refactor-getter-setter.js +1 -1
- package/dist/ts2famix-cli-wrapper.js +1 -1
- package/dist/ts2famix-cli.js +3 -1
- package/doc-uml/famix-typescript-model.puml +619 -607
- package/doc-uml/famix-typescript-model.svg +1 -1
- package/eslint.config.mjs +28 -28
- package/jest.config.json +1 -1
- package/package.json +70 -70
- package/src/analyze.ts +120 -120
- package/src/analyze_functions/process_functions.ts +1069 -1040
- package/src/famix_functions/EntityDictionary.ts +2061 -2016
- package/src/famix_functions/helpers_creation.ts +143 -135
- package/src/fqn.ts +416 -50
- package/src/generate_uml.sh +20 -20
- package/src/lib/famix/License.md +22 -22
- package/src/lib/famix/famix_JSON_exporter.ts +56 -56
- package/src/lib/famix/famix_base_element.ts +22 -22
- package/src/lib/famix/famix_repository.ts +288 -278
- package/src/lib/famix/index.ts +8 -8
- package/src/lib/famix/model/famix/access.ts +50 -50
- package/src/lib/famix/model/famix/accessor.ts +15 -15
- package/src/lib/famix/model/famix/alias.ts +39 -39
- package/src/lib/famix/model/famix/arrow_function.ts +15 -15
- package/src/lib/famix/model/famix/behavioral_entity.ts +97 -97
- package/src/lib/famix/model/famix/class.ts +85 -85
- package/src/lib/famix/model/famix/comment.ts +47 -47
- package/src/lib/famix/model/famix/concretisation.ts +40 -40
- package/src/lib/famix/model/famix/container_entity.ts +160 -160
- package/src/lib/famix/model/famix/decorator.ts +37 -37
- package/src/lib/famix/model/famix/entity.ts +15 -15
- package/src/lib/famix/model/famix/enum.ts +30 -30
- package/src/lib/famix/model/famix/enum_value.ts +28 -28
- package/src/lib/famix/model/famix/function.ts +15 -15
- package/src/lib/famix/model/famix/import_clause.ts +51 -51
- package/src/lib/famix/model/famix/index.ts +41 -41
- package/src/lib/famix/model/famix/indexed_file_anchor.ts +46 -46
- package/src/lib/famix/model/famix/inheritance.ts +40 -40
- package/src/lib/famix/model/famix/interface.ts +75 -75
- package/src/lib/famix/model/famix/invocation.ts +65 -65
- package/src/lib/famix/model/famix/method.ts +89 -89
- package/src/lib/famix/model/famix/module.ts +71 -71
- package/src/lib/famix/model/famix/named_entity.ts +95 -95
- package/src/lib/famix/model/famix/parameter.ts +28 -28
- package/src/lib/famix/model/famix/parameter_concretisation.ts +51 -51
- package/src/lib/famix/model/famix/parameter_type.ts +58 -58
- package/src/lib/famix/model/famix/parametric_arrow_function.ts +32 -32
- package/src/lib/famix/model/famix/parametric_class.ts +49 -49
- package/src/lib/famix/model/famix/parametric_function.ts +32 -32
- package/src/lib/famix/model/famix/parametric_interface.ts +49 -49
- package/src/lib/famix/model/famix/parametric_method.ts +32 -32
- package/src/lib/famix/model/famix/primitive_type.ts +15 -15
- package/src/lib/famix/model/famix/property.ts +94 -94
- package/src/lib/famix/model/famix/reference.ts +40 -40
- package/src/lib/famix/model/famix/scoping_entity.ts +35 -35
- package/src/lib/famix/model/famix/script_entity.ts +34 -34
- package/src/lib/famix/model/famix/source_anchor.ts +30 -30
- package/src/lib/famix/model/famix/source_language.ts +35 -35
- package/src/lib/famix/model/famix/sourced_entity.ts +70 -70
- package/src/lib/famix/model/famix/structural_entity.ts +43 -43
- package/src/lib/famix/model/famix/type.ts +87 -87
- package/src/lib/famix/model/famix/variable.ts +27 -27
- package/src/lib/famix/package.json +28 -28
- package/src/lib/ts-complex/cyclomatic-service.ts +83 -83
- package/src/refactorer/refactor-getter-setter.ts +140 -140
- package/src/ts2famix-cli-wrapper.ts +21 -21
- package/src/ts2famix-cli.ts +62 -60
- package/tsconfig.check-tests.json +14 -14
- package/tsconfig.json +73 -72
- package/.vscode/settings.json +0 -4
- package/TODO +0 -1
- package/arwea-fix.json +0 -1
- package/bogus.ts +0 -3
- package/class-diagram.puml +0 -792
- package/debug.txt +0 -13332
- package/debuglog.txt +0 -12073
- package/dist/famix2puml.js +0 -126
- package/dist/getClasses-arrow-body.js +0 -43
- package/dist/lib/famix/src/famix_JSON_exporter.js +0 -55
- package/dist/lib/famix/src/famix_base_element.js +0 -18
- package/dist/lib/famix/src/famix_repository.js +0 -224
- package/dist/lib/famix/src/index.js +0 -31
- package/dist/lib/famix/src/model/famix/access.js +0 -40
- package/dist/lib/famix/src/model/famix/accessor.js +0 -17
- package/dist/lib/famix/src/model/famix/alias.js +0 -33
- package/dist/lib/famix/src/model/famix/arrowFunction.js +0 -17
- package/dist/lib/famix/src/model/famix/arrow_function.js +0 -17
- package/dist/lib/famix/src/model/famix/behavioral_entity.js +0 -79
- package/dist/lib/famix/src/model/famix/class.js +0 -71
- package/dist/lib/famix/src/model/famix/comment.js +0 -39
- package/dist/lib/famix/src/model/famix/concretisation.js +0 -31
- package/dist/lib/famix/src/model/famix/container_entity.js +0 -126
- package/dist/lib/famix/src/model/famix/decorator.js +0 -32
- package/dist/lib/famix/src/model/famix/entity.js +0 -17
- package/dist/lib/famix/src/model/famix/enum.js +0 -31
- package/dist/lib/famix/src/model/famix/enum_value.js +0 -25
- package/dist/lib/famix/src/model/famix/function.js +0 -17
- package/dist/lib/famix/src/model/famix/implicit_variable.js +0 -17
- package/dist/lib/famix/src/model/famix/import_clause.js +0 -41
- package/dist/lib/famix/src/model/famix/index.js +0 -86
- package/dist/lib/famix/src/model/famix/indexed_file_anchor.js +0 -38
- package/dist/lib/famix/src/model/famix/inheritance.js +0 -33
- package/dist/lib/famix/src/model/famix/interface.js +0 -64
- package/dist/lib/famix/src/model/famix/invocation.js +0 -54
- package/dist/lib/famix/src/model/famix/method.js +0 -67
- package/dist/lib/famix/src/model/famix/module.js +0 -60
- package/dist/lib/famix/src/model/famix/named_entity.js +0 -78
- package/dist/lib/famix/src/model/famix/parameter.js +0 -25
- package/dist/lib/famix/src/model/famix/parameterConcretisation.js +0 -44
- package/dist/lib/famix/src/model/famix/parameter_concretisation.js +0 -44
- package/dist/lib/famix/src/model/famix/parameter_type.js +0 -45
- package/dist/lib/famix/src/model/famix/parametricArrowFunction.js +0 -29
- package/dist/lib/famix/src/model/famix/parametric_arrow_function.js +0 -31
- package/dist/lib/famix/src/model/famix/parametric_class.js +0 -44
- package/dist/lib/famix/src/model/famix/parametric_function.js +0 -31
- package/dist/lib/famix/src/model/famix/parametric_interface.js +0 -44
- package/dist/lib/famix/src/model/famix/parametric_method.js +0 -31
- package/dist/lib/famix/src/model/famix/primitive_type.js +0 -17
- package/dist/lib/famix/src/model/famix/property.js +0 -73
- package/dist/lib/famix/src/model/famix/reference.js +0 -33
- package/dist/lib/famix/src/model/famix/scoping_entity.js +0 -36
- package/dist/lib/famix/src/model/famix/script_entity.js +0 -29
- package/dist/lib/famix/src/model/famix/source_anchor.js +0 -27
- package/dist/lib/famix/src/model/famix/source_language.js +0 -35
- package/dist/lib/famix/src/model/famix/sourced_entity.js +0 -60
- package/dist/lib/famix/src/model/famix/structural_entity.js +0 -39
- package/dist/lib/famix/src/model/famix/text_anchor.js +0 -38
- package/dist/lib/famix/src/model/famix/type.js +0 -73
- package/dist/lib/famix/src/model/famix/variable.js +0 -24
- package/fqn-model.json +0 -1
- package/iterateGenericTypes.ts +0 -69
- package/out/class-diagram/class-diagram.svg +0 -1
- package/sample.json +0 -1
- package/sample.ts +0 -1
- package/stats.txt +0 -3091
- package/tabby-debug-output.txt +0 -19433
- package/ts2famix.log +0 -22656
- package/validate-references.js +0 -103
|
@@ -1,278 +1,288 @@
|
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
private
|
|
12
|
-
private
|
|
13
|
-
private
|
|
14
|
-
private
|
|
15
|
-
private
|
|
16
|
-
private
|
|
17
|
-
private
|
|
18
|
-
private
|
|
19
|
-
private
|
|
20
|
-
private
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
*
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
*
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
e.fullyQualifiedName
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
*
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
*
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
*
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
*
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
*
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
*
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
*
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
*
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
*
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
*
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
*
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
parsedModel.
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
this.
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
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
|
+
import { logger } from "../../analyze";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* This class is used to store all Famix elements
|
|
9
|
+
*/
|
|
10
|
+
export class FamixRepository {
|
|
11
|
+
private elements = new Set<FamixBaseElement>(); // All Famix elements
|
|
12
|
+
private famixClasses = new Set<Class>(); // All Famix classes
|
|
13
|
+
private famixInterfaces = new Set<Interface>(); // All Famix interfaces
|
|
14
|
+
private famixModules = new Set<Module>(); // All Famix namespaces
|
|
15
|
+
private famixMethods = new Set<Method>(); // All Famix methods
|
|
16
|
+
private famixVariables = new Set<Variable>(); // All Famix variables
|
|
17
|
+
private famixFunctions = new Set<FamixFunctionEntity>(); // All Famix functions
|
|
18
|
+
private famixFiles = new Set<ScriptEntity | Module>(); // All Famix files
|
|
19
|
+
private idCounter = 1; // Id counter
|
|
20
|
+
private absolutePath: string = "";
|
|
21
|
+
private fmxElementObjectMap = new Map<Famix.Entity, TSMorphObjectType>();
|
|
22
|
+
private tsMorphObjectMap = new Map<TSMorphObjectType, Famix.Entity>(); // TODO: add this map to have two-way mapping between Famix and TS Morph objects
|
|
23
|
+
|
|
24
|
+
constructor() {
|
|
25
|
+
this.addElement(new SourceLanguage()); // add the source language entity (TypeScript)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public setFmxElementObjectMap(fmxElementObjectMap: Map<Famix.Entity, TSMorphObjectType>) {
|
|
29
|
+
this.fmxElementObjectMap = fmxElementObjectMap;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public getFmxElementObjectMap() {
|
|
33
|
+
return this.fmxElementObjectMap;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public getAbsolutePath(): string {
|
|
37
|
+
return this.absolutePath;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public setAbsolutePath(path: string) {
|
|
41
|
+
this.absolutePath = path;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Gets a Famix entity by id
|
|
46
|
+
* @param id An id of a Famix entity
|
|
47
|
+
* @returns The Famix entity corresponding to the id or undefined if it doesn't exist
|
|
48
|
+
*/
|
|
49
|
+
public getFamixEntityById(id: number): FamixBaseElement | undefined {
|
|
50
|
+
const entity = Array.from(this.elements.values()).find(e => e.id === id);
|
|
51
|
+
return entity;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Gets a Famix entity by fully qualified name
|
|
56
|
+
* @param fullyQualifiedName A fully qualified name
|
|
57
|
+
* @returns The Famix entity corresponding to the fully qualified name or undefined if it doesn't exist
|
|
58
|
+
*/
|
|
59
|
+
public getFamixEntityByFullyQualifiedName(fullyQualifiedName: string): FamixBaseElement | undefined {
|
|
60
|
+
const allEntities = Array.from(this.elements.values()).filter(e => e instanceof NamedEntity) as Array<NamedEntity>;
|
|
61
|
+
const entity = allEntities.find(e =>
|
|
62
|
+
// {console.log(`namedEntity: ${e.fullyQualifiedName}`);
|
|
63
|
+
// return
|
|
64
|
+
e.fullyQualifiedName === fullyQualifiedName
|
|
65
|
+
// }
|
|
66
|
+
);
|
|
67
|
+
return entity;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Method to get Famix access by accessor and variable
|
|
71
|
+
public getFamixAccessByAccessorAndVariable(accessor: Famix.ContainerEntity, variable: Famix.StructuralEntity): Famix.Access | undefined {
|
|
72
|
+
// Iterate through the list of Famix accesses to find the matching one
|
|
73
|
+
for (const access of Array.from(this.elements.values()).filter(e => e instanceof Famix.Access) as Array<Famix.Access>) {
|
|
74
|
+
if (access.accessor === accessor && access.variable === variable) {
|
|
75
|
+
return access;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Return undefined if no matching access is found
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
export(arg0: { format: string; }) {
|
|
84
|
+
if (arg0.format === "json") {
|
|
85
|
+
return this.getJSON();
|
|
86
|
+
} else {
|
|
87
|
+
throw new Error("Unsupported format");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
// Only for tests
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Gets all Famix entities
|
|
96
|
+
* @returns All Famix entities
|
|
97
|
+
*/
|
|
98
|
+
public _getAllEntities(): Set<FamixBaseElement> {
|
|
99
|
+
return new Set(Array.from(this.elements.values()));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Gets all Famix entities of a given type
|
|
104
|
+
* @param theType A type of Famix entity
|
|
105
|
+
* @returns All Famix entities of the given type
|
|
106
|
+
*/
|
|
107
|
+
public _getAllEntitiesWithType(theType: string): Set<FamixBaseElement> {
|
|
108
|
+
return new Set(Array.from(this.elements.values()).filter(e => (e as FamixBaseElement).constructor.name === theType));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Gets a Famix class by name
|
|
113
|
+
* @param name A class name
|
|
114
|
+
* @returns The Famix class corresponding to the name or undefined if it doesn't exist
|
|
115
|
+
*/
|
|
116
|
+
public _getFamixClass(fullyQualifiedName: string): Class | undefined {
|
|
117
|
+
return Array.from(this.famixClasses.values()).find(ns => ns.fullyQualifiedName === fullyQualifiedName);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Gets a Famix interface by name
|
|
122
|
+
* @param name An interface name
|
|
123
|
+
* @returns The Famix interface corresponding to the name or undefined if it doesn't exist
|
|
124
|
+
*/
|
|
125
|
+
public _getFamixInterface(fullyQualifiedName: string): Interface | undefined {
|
|
126
|
+
return Array.from(this.famixInterfaces.values()).find(ns => ns.fullyQualifiedName === fullyQualifiedName);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Gets a Famix method by name
|
|
131
|
+
* @param name A method name
|
|
132
|
+
* @returns The Famix method corresponding to the name or undefined if it doesn't exist
|
|
133
|
+
*/
|
|
134
|
+
public _getFamixMethod(fullyQualifiedName: string): Method | undefined {
|
|
135
|
+
return Array.from(this.famixMethods.values()).find(ns => ns.fullyQualifiedName === fullyQualifiedName);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Gets a Famix function by name
|
|
140
|
+
* @param name A function name
|
|
141
|
+
* @returns The Famix function corresponding to the name or undefined if it doesn't exist
|
|
142
|
+
*/
|
|
143
|
+
public _getFamixFunction(fullyQualifiedName: string): FamixFunctionEntity | undefined {
|
|
144
|
+
return Array.from(this.famixFunctions.values()).find(ns => ns.fullyQualifiedName === fullyQualifiedName);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Gets a Famix variable by name
|
|
150
|
+
* @param name A variable name
|
|
151
|
+
* @returns The Famix variable corresponding to the name or undefined if it doesn't exist
|
|
152
|
+
*/
|
|
153
|
+
public _getFamixVariable(fullyQualifiedName: string): Variable | undefined {
|
|
154
|
+
return Array.from(this.famixVariables.values()).find(v => v.fullyQualifiedName === fullyQualifiedName);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Gets a Famix namespace by name
|
|
159
|
+
* @param name A namespace name
|
|
160
|
+
* @returns The Famix namespace corresponding to the name or undefined if it doesn't exist
|
|
161
|
+
*/
|
|
162
|
+
public _getFamixModule(fullyQualifiedName: string): Module | undefined {
|
|
163
|
+
return Array.from(this.famixModules.values()).find(ns => ns.fullyQualifiedName === fullyQualifiedName);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Gets all Famix namespaces
|
|
168
|
+
* @returns All Famix namespaces
|
|
169
|
+
*/
|
|
170
|
+
public _getFamixModules(): Set<Module> {
|
|
171
|
+
return new Set(Array.from(this.famixModules.values()));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Gets a Famix file by name
|
|
176
|
+
* @param name A file name
|
|
177
|
+
* @returns The Famix file corresponding to the name or undefined if it doesn't exist
|
|
178
|
+
*/
|
|
179
|
+
public _getFamixFile(fullyQualifiedName: string): ScriptEntity | Module | undefined {
|
|
180
|
+
return Array.from(this.famixFiles.values()).find(ns => ns.name === fullyQualifiedName);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Gets all Famix files
|
|
185
|
+
* @returns All Famix files
|
|
186
|
+
*/
|
|
187
|
+
public _getFamixFiles(): Set<ScriptEntity | Module> {
|
|
188
|
+
return new Set(Array.from(this.famixFiles.values()));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Gets all method names as a set from a class
|
|
193
|
+
* @param className A class name
|
|
194
|
+
* @returns The set of class "className" method names
|
|
195
|
+
*/
|
|
196
|
+
public _methodNamesAsSetFromClass(className: string): Set<string> {
|
|
197
|
+
const theClass = this._getFamixClass(className) as Class;
|
|
198
|
+
return new Set(Array.from(theClass.methods).map(m => m.name));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Gets all method parents as a set from a class
|
|
203
|
+
* @param className A class name
|
|
204
|
+
* @returns The set of class "className" method parents
|
|
205
|
+
*/
|
|
206
|
+
public _methodParentsAsSetFromClass(className: string): Set<Type> {
|
|
207
|
+
const theClass = this._getFamixClass(className) as Class;
|
|
208
|
+
return new Set(Array.from(theClass.methods).map(m => m.parentEntity));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Gets the map of Famix element ids and their Famix element from a JSON model
|
|
213
|
+
* @param model A JSON model
|
|
214
|
+
* @returns The map of Famix element ids and their Famix element from the JSON model
|
|
215
|
+
*/
|
|
216
|
+
public _initMapFromModel(model: string): Map<number, unknown> {
|
|
217
|
+
const parsedModel: Array<FamixBaseElement> = JSON.parse(model);
|
|
218
|
+
const idToElementMap: Map<number, unknown> = new Map();
|
|
219
|
+
parsedModel.forEach(element => {
|
|
220
|
+
idToElementMap.set(element.id, element);
|
|
221
|
+
});
|
|
222
|
+
return idToElementMap;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Adds a Famix element to the repository
|
|
228
|
+
* @param element A Famix element
|
|
229
|
+
*/
|
|
230
|
+
public addElement(element: FamixBaseElement): void {
|
|
231
|
+
logger.debug(`Adding Famix element ${element.constructor.name} with id ${element.id}`);
|
|
232
|
+
if (element instanceof Class) {
|
|
233
|
+
this.famixClasses.add(element);
|
|
234
|
+
} else if (element instanceof Interface) {
|
|
235
|
+
this.famixInterfaces.add(element);
|
|
236
|
+
} else if (element instanceof Module) {
|
|
237
|
+
this.famixModules.add(element);
|
|
238
|
+
} else if (element instanceof Variable) {
|
|
239
|
+
this.famixVariables.add(element);
|
|
240
|
+
} else if (element instanceof Method) {
|
|
241
|
+
this.famixMethods.add(element);
|
|
242
|
+
} else if (element instanceof FamixFunctionEntity || element instanceof ArrowFunction) {
|
|
243
|
+
this.famixFunctions.add(element);
|
|
244
|
+
} else if (element instanceof ScriptEntity || element instanceof Module) {
|
|
245
|
+
this.famixFiles.add(element);
|
|
246
|
+
}
|
|
247
|
+
this.elements.add(element);
|
|
248
|
+
element.id = this.idCounter;
|
|
249
|
+
this.idCounter++;
|
|
250
|
+
this.validateFQNs();
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Validates the fully qualified names of all Famix elements
|
|
255
|
+
*/
|
|
256
|
+
private validateFQNs(): void {
|
|
257
|
+
// make sure all elements have unique fully qualified names
|
|
258
|
+
const fqns = new Set<string>();
|
|
259
|
+
for (const element of Array.from(this.elements.values())) {
|
|
260
|
+
// ignore everything that is not a NamedEntity
|
|
261
|
+
if (element instanceof NamedEntity) {
|
|
262
|
+
if (element.fullyQualifiedName && fqns.has(element.fullyQualifiedName)) {
|
|
263
|
+
const theExistingElement = Array.from(this.elements.values()).find(e => (e as NamedEntity).fullyQualifiedName === element.fullyQualifiedName);
|
|
264
|
+
throw new Error(`The fully qualified name ${element.fullyQualifiedName} is not unique.\nIt exists for ${theExistingElement?.getJSON()}`);
|
|
265
|
+
}
|
|
266
|
+
const theName = (element as NamedEntity).fullyQualifiedName;
|
|
267
|
+
if (theName === undefined || theName === "") {
|
|
268
|
+
throw new Error(`The element ${element.constructor.name} with id ${element.id} has no valid fully qualified name`);
|
|
269
|
+
}
|
|
270
|
+
fqns.add(theName);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Gets a JSON representation of the repository
|
|
278
|
+
* @returns A JSON representation of the repository
|
|
279
|
+
*/
|
|
280
|
+
public getJSON(): string {
|
|
281
|
+
let ret = "[";
|
|
282
|
+
for (const element of Array.from(this.elements.values())) {
|
|
283
|
+
ret = ret + element.getJSON() + ",";
|
|
284
|
+
}
|
|
285
|
+
ret = ret.substring(0, ret.length - 1);
|
|
286
|
+
return ret + "]";
|
|
287
|
+
}
|
|
288
|
+
}
|
package/src/lib/famix/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as Famix from "./model/famix";
|
|
2
|
-
import { FamixBaseElement } from "./famix_base_element";
|
|
3
|
-
import { FamixJSONExporter } from "./famix_JSON_exporter";
|
|
4
|
-
import { FamixRepository } from "./famix_repository";
|
|
5
|
-
|
|
6
|
-
const model = { Famix };
|
|
7
|
-
|
|
8
|
-
export = { FamixBaseElement, FamixJSONExporter, FamixRepository, model };
|
|
1
|
+
import * as Famix from "./model/famix";
|
|
2
|
+
import { FamixBaseElement } from "./famix_base_element";
|
|
3
|
+
import { FamixJSONExporter } from "./famix_JSON_exporter";
|
|
4
|
+
import { FamixRepository } from "./famix_repository";
|
|
5
|
+
|
|
6
|
+
const model = { Famix };
|
|
7
|
+
|
|
8
|
+
export = { FamixBaseElement, FamixJSONExporter, FamixRepository, model };
|