ts2famix 1.0.13 → 1.0.15

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 (135) hide show
  1. package/.eslintrc.json +24 -24
  2. package/LICENSE +23 -23
  3. package/README.md +109 -109
  4. package/dist/analyze.js +107 -0
  5. package/dist/analyze_functions/processAccesses.js +55 -0
  6. package/dist/analyze_functions/processFiles.js +554 -0
  7. package/dist/analyze_functions/processImportClauses.js +70 -0
  8. package/dist/analyze_functions/processInheritances.js +73 -0
  9. package/dist/analyze_functions/processInvocations.js +49 -0
  10. package/dist/famix2puml.js +125 -0
  11. package/dist/famix_functions/famix_functions.js +525 -0
  12. package/dist/famix_functions/famix_functions_associations.js +223 -0
  13. package/dist/famix_functions/famix_functions_index.js +62 -0
  14. package/dist/famix_functions/famix_functions_types.js +114 -0
  15. package/dist/fqn.js +126 -0
  16. package/dist/lib/famix/src/famix_JSON_exporter.js +54 -0
  17. package/dist/lib/famix/src/famix_base_element.js +13 -0
  18. package/dist/lib/famix/src/famix_repository.js +199 -0
  19. package/dist/lib/famix/src/index.js +30 -0
  20. package/dist/lib/famix/src/model/famix/access.js +39 -0
  21. package/dist/lib/famix/src/model/famix/accessor.js +16 -0
  22. package/dist/lib/famix/src/model/famix/alias.js +32 -0
  23. package/dist/lib/famix/src/model/famix/association.js +36 -0
  24. package/dist/lib/famix/src/model/famix/behavioral_entity.js +81 -0
  25. package/dist/lib/famix/src/model/famix/c_source_language.js +16 -0
  26. package/dist/lib/famix/src/model/famix/class.js +70 -0
  27. package/dist/lib/famix/src/model/famix/comment.js +38 -0
  28. package/dist/lib/famix/src/model/famix/container_entity.js +125 -0
  29. package/dist/lib/famix/src/model/famix/custom_source_language.js +23 -0
  30. package/dist/lib/famix/src/model/famix/decorator.js +31 -0
  31. package/dist/lib/famix/src/model/famix/entity.js +16 -0
  32. package/dist/lib/famix/src/model/famix/enum.js +30 -0
  33. package/dist/lib/famix/src/model/famix/enum_value.js +24 -0
  34. package/dist/lib/famix/src/model/famix/function.js +16 -0
  35. package/dist/lib/famix/src/model/famix/implicit_variable.js +16 -0
  36. package/dist/lib/famix/src/model/famix/import_clause.js +39 -0
  37. package/dist/lib/famix/src/model/famix/index.js +87 -0
  38. package/dist/lib/famix/src/model/famix/indexed_file_anchor.js +37 -0
  39. package/dist/lib/famix/src/model/famix/inheritance.js +32 -0
  40. package/dist/lib/famix/src/model/famix/interface.js +63 -0
  41. package/dist/lib/famix/src/model/famix/invocation.js +53 -0
  42. package/dist/lib/famix/src/model/famix/method.js +66 -0
  43. package/dist/lib/famix/src/model/famix/module.js +31 -0
  44. package/dist/lib/famix/src/model/famix/named_entity.js +77 -0
  45. package/dist/lib/famix/src/model/famix/namespace.js +24 -0
  46. package/dist/lib/famix/src/model/famix/parameter.js +24 -0
  47. package/dist/lib/famix/src/model/famix/parameterizable_class.js +30 -0
  48. package/dist/lib/famix/src/model/famix/parameterizable_interface.js +30 -0
  49. package/dist/lib/famix/src/model/famix/parameterized_type.js +36 -0
  50. package/dist/lib/famix/src/model/famix/primitive_type.js +16 -0
  51. package/dist/lib/famix/src/model/famix/property.js +44 -0
  52. package/dist/lib/famix/src/model/famix/reference.js +32 -0
  53. package/dist/lib/famix/src/model/famix/scoping_entity.js +34 -0
  54. package/dist/lib/famix/src/model/famix/script_entity.js +30 -0
  55. package/dist/lib/famix/src/model/famix/source_anchor.js +26 -0
  56. package/dist/lib/famix/src/model/famix/source_language.js +30 -0
  57. package/dist/lib/famix/src/model/famix/sourced_entity.js +55 -0
  58. package/dist/lib/famix/src/model/famix/structural_entity.js +38 -0
  59. package/dist/lib/famix/src/model/famix/text_anchor.js +37 -0
  60. package/dist/lib/famix/src/model/famix/type.js +71 -0
  61. package/dist/lib/famix/src/model/famix/type_parameter.js +24 -0
  62. package/dist/lib/famix/src/model/famix/variable.js +23 -0
  63. package/dist/lib/ts-complex/cyclomatic-service.js +83 -0
  64. package/dist/ts2famix-cli.js +63 -0
  65. package/dist/ts2famix-tsconfig.js +53 -0
  66. package/jest.config-old.ts +199 -199
  67. package/package.json +47 -47
  68. package/src/analyze.ts +94 -94
  69. package/src/analyze_functions/processAccesses.ts +57 -57
  70. package/src/analyze_functions/processFiles.ts +669 -669
  71. package/src/analyze_functions/processImportClauses.ts +77 -77
  72. package/src/analyze_functions/processInheritances.ts +84 -84
  73. package/src/analyze_functions/processInvocations.ts +51 -51
  74. package/src/famix2puml.ts +119 -119
  75. package/src/famix_functions/famix_functions.ts +565 -559
  76. package/src/famix_functions/famix_functions_associations.ts +225 -215
  77. package/src/famix_functions/famix_functions_index.ts +44 -44
  78. package/src/famix_functions/famix_functions_types.ts +105 -105
  79. package/src/generate_uml.sh +16 -16
  80. package/src/lib/famix/License.md +22 -22
  81. package/src/lib/famix/package-lock.json +301 -301
  82. package/src/lib/famix/package.json +27 -27
  83. package/src/lib/famix/readme.md +4 -4
  84. package/src/lib/famix/src/famix_JSON_exporter.ts +56 -56
  85. package/src/lib/famix/src/famix_base_element.ts +18 -18
  86. package/src/lib/famix/src/famix_repository.ts +212 -199
  87. package/src/lib/famix/src/index.ts +8 -8
  88. package/src/lib/famix/src/model/famix/access.ts +53 -53
  89. package/src/lib/famix/src/model/famix/accessor.ts +15 -15
  90. package/src/lib/famix/src/model/famix/alias.ts +41 -41
  91. package/src/lib/famix/src/model/famix/association.ts +44 -44
  92. package/src/lib/famix/src/model/famix/behavioral_entity.ts +107 -107
  93. package/src/lib/famix/src/model/famix/c_source_language.ts +15 -15
  94. package/src/lib/famix/src/model/famix/class.ts +86 -86
  95. package/src/lib/famix/src/model/famix/comment.ts +50 -50
  96. package/src/lib/famix/src/model/famix/container_entity.ts +165 -165
  97. package/src/lib/famix/src/model/famix/custom_source_language.ts +27 -27
  98. package/src/lib/famix/src/model/famix/decorator.ts +39 -39
  99. package/src/lib/famix/src/model/famix/entity.ts +15 -15
  100. package/src/lib/famix/src/model/famix/enum.ts +31 -31
  101. package/src/lib/famix/src/model/famix/enum_value.ts +29 -29
  102. package/src/lib/famix/src/model/famix/function.ts +15 -15
  103. package/src/lib/famix/src/model/famix/implicit_variable.ts +15 -15
  104. package/src/lib/famix/src/model/famix/import_clause.ts +53 -53
  105. package/src/lib/famix/src/model/famix/index.ts +42 -42
  106. package/src/lib/famix/src/model/famix/indexed_file_anchor.ts +49 -49
  107. package/src/lib/famix/src/model/famix/inheritance.ts +42 -42
  108. package/src/lib/famix/src/model/famix/interface.ts +75 -75
  109. package/src/lib/famix/src/model/famix/invocation.ts +68 -68
  110. package/src/lib/famix/src/model/famix/method.ts +96 -96
  111. package/src/lib/famix/src/model/famix/module.ts +31 -31
  112. package/src/lib/famix/src/model/famix/named_entity.ts +98 -98
  113. package/src/lib/famix/src/model/famix/namespace.ts +28 -28
  114. package/src/lib/famix/src/model/famix/parameter.ts +29 -29
  115. package/src/lib/famix/src/model/famix/parameterizable_class.ts +31 -31
  116. package/src/lib/famix/src/model/famix/parameterizable_interface.ts +31 -31
  117. package/src/lib/famix/src/model/famix/parameterized_type.ts +40 -40
  118. package/src/lib/famix/src/model/famix/primitive_type.ts +15 -15
  119. package/src/lib/famix/src/model/famix/property.ts +54 -54
  120. package/src/lib/famix/src/model/famix/reference.ts +42 -42
  121. package/src/lib/famix/src/model/famix/scoping_entity.ts +34 -31
  122. package/src/lib/famix/src/model/famix/script_entity.ts +38 -38
  123. package/src/lib/famix/src/model/famix/source_anchor.ts +31 -31
  124. package/src/lib/famix/src/model/famix/source_language.ts +31 -31
  125. package/src/lib/famix/src/model/famix/sourced_entity.ts +70 -70
  126. package/src/lib/famix/src/model/famix/structural_entity.ts +44 -44
  127. package/src/lib/famix/src/model/famix/text_anchor.ts +49 -49
  128. package/src/lib/famix/src/model/famix/type.ts +88 -88
  129. package/src/lib/famix/src/model/famix/type_parameter.ts +33 -33
  130. package/src/lib/famix/src/model/famix/variable.ts +28 -28
  131. package/src/lib/famix/tsconfig.json +26 -26
  132. package/src/lib/famix/tslint.json +14 -14
  133. package/src/lib/ts-complex/cyclomatic-service.ts +85 -85
  134. package/src/ts2famix-cli.ts +39 -39
  135. package/tsconfig.json +69 -69
package/.eslintrc.json CHANGED
@@ -1,24 +1,24 @@
1
- {
2
- "env": {
3
- "browser": true,
4
- "es2021": true
5
- },
6
- "extends": [
7
- "eslint:recommended",
8
- "plugin:@typescript-eslint/recommended"
9
- ],
10
- "overrides": [
11
- ],
12
- "parser": "@typescript-eslint/parser",
13
- "parserOptions": {
14
- "ecmaVersion": "latest",
15
- "sourceType": "module"
16
- },
17
- "plugins": [
18
- "@typescript-eslint"
19
- ],
20
- "rules": {
21
- "@typescript-eslint/no-namespace": "off",
22
- "semi": [1, "always"]
23
- }
24
- }
1
+ {
2
+ "env": {
3
+ "browser": true,
4
+ "es2021": true
5
+ },
6
+ "extends": [
7
+ "eslint:recommended",
8
+ "plugin:@typescript-eslint/recommended"
9
+ ],
10
+ "overrides": [
11
+ ],
12
+ "parser": "@typescript-eslint/parser",
13
+ "parserOptions": {
14
+ "ecmaVersion": "latest",
15
+ "sourceType": "module"
16
+ },
17
+ "plugins": [
18
+ "@typescript-eslint"
19
+ ],
20
+ "rules": {
21
+ "@typescript-eslint/no-namespace": "off",
22
+ "semi": [1, "always"]
23
+ }
24
+ }
package/LICENSE CHANGED
@@ -1,23 +1,23 @@
1
- MIT License
2
-
3
- Copyright (c) 2021 Arezoo Nasrollah Zadeh
4
- Copyright (c) 2021 Christopher Fuhrman
5
- Copyright (c) 2023 Maël Paul
6
-
7
- Permission is hereby granted, free of charge, to any person obtaining a copy
8
- of this software and associated documentation files (the "Software"), to deal
9
- in the Software without restriction, including without limitation the rights
10
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- copies of the Software, and to permit persons to whom the Software is
12
- furnished to do so, subject to the following conditions:
13
-
14
- The above copyright notice and this permission notice shall be included in all
15
- copies or substantial portions of the Software.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Arezoo Nasrollah Zadeh
4
+ Copyright (c) 2021 Christopher Fuhrman
5
+ Copyright (c) 2023 Maël Paul
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
package/README.md CHANGED
@@ -1,109 +1,109 @@
1
- # FamixTypeScriptImporter
2
-
3
- [![Node.js CI](https://github.com/maelpaul/FamixTypeScriptImporter/actions/workflows/node.js.yml/badge.svg)](https://github.com/maelpaul/FamixTypeScriptImporter/actions/workflows/node.js.yml)
4
-
5
- Create a [FamixTypeScript](https://github.com/fuhrmanator/FamixTypeScript) model in JSON of TypeScript files.
6
-
7
- ## Installation
8
-
9
- ```sh
10
- npm install ts2famix
11
- ```
12
-
13
- ## Usage
14
-
15
- Instructions for using the command-line importer:
16
-
17
- ```sh
18
- ts2famix --help
19
- ```
20
-
21
- ## Parse a full project
22
-
23
- ```sh
24
- ts2famix -i ../path/to/project/tsconfig.json -o JSONModels/projectName.json
25
- ```
26
- or
27
- ```sh
28
- ts2famix -i "../path/to/project/**/*.ts" -o JSONModels/projectName.json
29
- ```
30
-
31
- ## Import the JSON model into Moose 🫎
32
-
33
- You need to copy the "```JSONModels/projectName.json```" into your "```Pharo/images/[imageName]```" directory.
34
-
35
- For a Moose Suite 10 (stable) user with the Pharo directory in the root directory, do :
36
- ```sh
37
- cp JSONModels/projectName.json ~/Pharo/images/Moose\ Suite\ 10\ \(stable\)/.
38
- ```
39
-
40
- Then, in a Moose Playground, do :
41
- ```st
42
- Metacello new
43
- githubUser: 'fuhrmanator' project: 'FamixTypeScript' commitish: 'master' path: 'src';
44
- baseline: 'FamixTypeScript';
45
- load
46
- ```
47
-
48
- This command installs the TypeScript metamodel into Moose.
49
-
50
- Then, generate the metamodel with :
51
- ```Library > Famix > Manage metamodels > Regenerate all metamodels```
52
-
53
- Then, in a Moose Playground, do :
54
- ```st
55
- 'projectName.json' asFileReference readStreamDo:
56
- [ :stream | model := FamixTypeScriptModel new
57
- importFromJSONStream: stream. model install ].
58
- ```
59
-
60
- This command imports the JSON model into Moose.
61
-
62
- ## Developer info
63
-
64
- Run tests :
65
- ```sh
66
- npm test
67
- ```
68
-
69
- Generate coverage :
70
- ```sh
71
- npm run coverage
72
- ```
73
-
74
- Then, open "```coverage/lcov-report/index.html```" with your favorite browser :
75
- ```sh
76
- firefox coverage/lcov-report/index.html &
77
- ```
78
-
79
- Generate documentation :
80
- ```sh
81
- npm run doc
82
- ```
83
-
84
- Then, open "```docs/index.html```" with your favorite browser :
85
- ```sh
86
- firefox docs/index.html &
87
- ```
88
-
89
- Generate plantuml and svg of the metamodel :
90
- ```sh
91
- npm run uml
92
- ```
93
-
94
- Then, open "```doc-uml/metamodel.svg```" with your favorite image viewer :
95
- ```sh
96
- eog doc-uml/metamodel.svg &
97
- ```
98
-
99
- ## Generate an object diagram of the JSON model
100
-
101
- ```sh
102
- ts-node src/famix2puml.ts -i JSONModels/projectName.json -o PUMLModels/projectName.puml
103
- ```
104
-
105
- ## TypeScript Metamodel API documentation (visualization)
106
-
107
- The following was generated by CI using [tplant](https://github.com/bafolts/tplant), in a similar fashion described [here](https://modularmoose.org/2021/07/19/automatic-metamodel-documentation-generation.html).
108
-
109
- ![FamixTypeScript API Metamodel](https://raw.githubusercontent.com/maelpaul/FamixTypeScriptImporter/v1/doc/metamodel.svg)
1
+ # FamixTypeScriptImporter
2
+
3
+ [![Node.js CI](https://github.com/maelpaul/FamixTypeScriptImporter/actions/workflows/node.js.yml/badge.svg)](https://github.com/maelpaul/FamixTypeScriptImporter/actions/workflows/node.js.yml)
4
+
5
+ Create a [FamixTypeScript](https://github.com/fuhrmanator/FamixTypeScript) model in JSON of TypeScript files.
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ npm install ts2famix
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Instructions for using the command-line importer:
16
+
17
+ ```sh
18
+ ts2famix --help
19
+ ```
20
+
21
+ ## Parse a full project
22
+
23
+ ```sh
24
+ ts2famix -i ../path/to/project/tsconfig.json -o JSONModels/projectName.json
25
+ ```
26
+ or
27
+ ```sh
28
+ ts2famix -i "../path/to/project/**/*.ts" -o JSONModels/projectName.json
29
+ ```
30
+
31
+ ## Import the JSON model into Moose 🫎
32
+
33
+ You need to copy the "```JSONModels/projectName.json```" into your "```Pharo/images/[imageName]```" directory.
34
+
35
+ For a Moose Suite 10 (stable) user with the Pharo directory in the root directory, do :
36
+ ```sh
37
+ cp JSONModels/projectName.json ~/Pharo/images/Moose\ Suite\ 10\ \(stable\)/.
38
+ ```
39
+
40
+ Then, in a Moose Playground, do :
41
+ ```st
42
+ Metacello new
43
+ githubUser: 'fuhrmanator' project: 'FamixTypeScript' commitish: 'master' path: 'src';
44
+ baseline: 'FamixTypeScript';
45
+ load
46
+ ```
47
+
48
+ This command installs the TypeScript metamodel into Moose.
49
+
50
+ Then, generate the metamodel with :
51
+ ```Library > Famix > Manage metamodels > Regenerate all metamodels```
52
+
53
+ Then, in a Moose Playground, do :
54
+ ```st
55
+ 'projectName.json' asFileReference readStreamDo:
56
+ [ :stream | model := FamixTypeScriptModel new
57
+ importFromJSONStream: stream. model install ].
58
+ ```
59
+
60
+ This command imports the JSON model into Moose.
61
+
62
+ ## Developer info
63
+
64
+ Run tests :
65
+ ```sh
66
+ npm test
67
+ ```
68
+
69
+ Generate coverage :
70
+ ```sh
71
+ npm run coverage
72
+ ```
73
+
74
+ Then, open "```coverage/lcov-report/index.html```" with your favorite browser :
75
+ ```sh
76
+ firefox coverage/lcov-report/index.html &
77
+ ```
78
+
79
+ Generate documentation :
80
+ ```sh
81
+ npm run doc
82
+ ```
83
+
84
+ Then, open "```docs/index.html```" with your favorite browser :
85
+ ```sh
86
+ firefox docs/index.html &
87
+ ```
88
+
89
+ Generate plantuml and svg of the metamodel :
90
+ ```sh
91
+ npm run uml
92
+ ```
93
+
94
+ Then, open "```doc-uml/metamodel.svg```" with your favorite image viewer :
95
+ ```sh
96
+ eog doc-uml/metamodel.svg &
97
+ ```
98
+
99
+ ## Generate an object diagram of the JSON model
100
+
101
+ ```sh
102
+ ts-node src/famix2puml.ts -i JSONModels/projectName.json -o PUMLModels/projectName.puml
103
+ ```
104
+
105
+ ## TypeScript Metamodel API documentation (visualization)
106
+
107
+ The following was generated by CI using [tplant](https://github.com/bafolts/tplant), in a similar fashion described [here](https://modularmoose.org/2021/07/19/automatic-metamodel-documentation-generation.html).
108
+
109
+ ![FamixTypeScript API Metamodel](https://raw.githubusercontent.com/maelpaul/FamixTypeScriptImporter/v1/doc/metamodel.svg)
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.Importer = void 0;
27
+ const ts_morph_1 = require("ts-morph");
28
+ const fs = __importStar(require("fs"));
29
+ const famix_functions_1 = require("./famix_functions/famix_functions");
30
+ const processFiles_1 = require("./analyze_functions/processFiles");
31
+ const processAccesses_1 = require("./analyze_functions/processAccesses");
32
+ const processInvocations_1 = require("./analyze_functions/processInvocations");
33
+ const processInheritances_1 = require("./analyze_functions/processInheritances");
34
+ const processImportClauses_1 = require("./analyze_functions/processImportClauses");
35
+ /**
36
+ * This class is used to build a Famix model from a TypeScript source code
37
+ */
38
+ class Importer {
39
+ constructor() {
40
+ this.project = new ts_morph_1.Project(); // The project containing the source files to analyze
41
+ this.famixFunctions = new famix_functions_1.FamixFunctions(); // FamixFunctions object, it contains all the functions needed to create Famix entities
42
+ this.processFiles = new processFiles_1.ProcessFiles(this.famixFunctions); // ProcessFiles object, it contains all the functions needed to process the source files
43
+ this.processAccesses = new processAccesses_1.ProcessAccesses(this.famixFunctions); // ProcessAccesses object, it contains all the functions needed to process the accesses
44
+ this.processInvocations = new processInvocations_1.ProcessInvocations(this.famixFunctions); // ProcessInvocations object, it contains all the functions needed to process the invocations
45
+ this.processInheritances = new processInheritances_1.ProcessInheritances(this.famixFunctions); // ProcessInheritances object, it contains all the functions needed to process the inheritances
46
+ this.processImportClauses = new processImportClauses_1.ProcessImportClauses(this.famixFunctions); // ProcessImportClauses object, it contains all the functions needed to process the import clauses
47
+ }
48
+ /**
49
+ * Main method
50
+ * @param paths An array of paths to the source files to analyze
51
+ * @returns The Famix repository containing the Famix model
52
+ */
53
+ famixRepFromPaths(paths) {
54
+ // try {
55
+ console.info(`famixRepFromPaths: paths: ${paths}`);
56
+ this.project.addSourceFilesAtPaths(paths);
57
+ this.processEntities(this.project);
58
+ const famixRep = this.famixFunctions.getFamixRepository();
59
+ // }
60
+ // catch (error) {
61
+ // console.error(`> ERROR: got exception ${error}. Exiting...`);
62
+ // console.error(error.message);
63
+ // console.error(error.stack);
64
+ // process.exit(1);
65
+ // }
66
+ return famixRep;
67
+ }
68
+ processEntities(project) {
69
+ this.processFiles.processFiles(project.getSourceFiles());
70
+ const accesses = this.processFiles.getAccesses();
71
+ const methodsAndFunctionsWithId = this.processFiles.getMethodsAndFunctionsWithId();
72
+ const classes = this.processFiles.getClasses();
73
+ const interfaces = this.processFiles.getInterfaces();
74
+ const modules = this.processFiles.getModules();
75
+ const exports = this.processFiles.getExports();
76
+ this.processImportClauses.processImportClauses(modules, exports);
77
+ this.processAccesses.processAccesses(accesses);
78
+ this.processInvocations.processInvocations(methodsAndFunctionsWithId);
79
+ this.processInheritances.processInheritances(classes, interfaces);
80
+ }
81
+ /**
82
+ * Main method for tests
83
+ *
84
+ * @param filename The name of the file to analyze
85
+ * @param source A TypeScript source code
86
+ * @returns The Famix repository containing the Famix model
87
+ */
88
+ // TODO: this is slow because it writes the source code to a file and then reads it again - it's possible to just pass the source code to the ts-morph project
89
+ famixRepFromSource(filename, source) {
90
+ const filePath = `./test_src/${filename}.ts`;
91
+ fs.writeFileSync(filePath, source, 'utf-8');
92
+ const famixRep = this.famixRepFromPaths([filePath]);
93
+ return famixRep;
94
+ }
95
+ /**
96
+ * Main method for a ts-morph project
97
+ * @param project A ts-morph project
98
+ * @returns The Famix repository containing the Famix model
99
+ */
100
+ famixRepFromProject(project) {
101
+ //const sourceFileNames = project.getSourceFiles().map(f => f.getFilePath()) as Array<string>;
102
+ //const famixRep = this.famixRepFromPaths(sourceFileNames);
103
+ this.processEntities(project);
104
+ return this.famixFunctions.getFamixRepository();
105
+ }
106
+ }
107
+ exports.Importer = Importer;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProcessAccesses = void 0;
4
+ /**
5
+ * This class is used to build a Famix model for the accesses
6
+ */
7
+ class ProcessAccesses {
8
+ /**
9
+ * Initializes the ProcessAccesses object
10
+ * @param famixFunctions FamixFunctions object, it contains all the functions needed to create Famix entities
11
+ */
12
+ constructor(famixFunctions) {
13
+ this.famixFunctions = famixFunctions;
14
+ }
15
+ /**
16
+ * Builds a Famix model for the accesses on the parameters, variables, properties and enum members of the source files
17
+ * @param accessMap A map of parameters, variables, properties and enum members with their id
18
+ */
19
+ processAccesses(accessMap) {
20
+ console.info(`processAccesses: Creating accesses:`);
21
+ accessMap.forEach((v, id) => {
22
+ console.info(`processAccesses: Accesses to ${v.getName()}`);
23
+ try {
24
+ const temp_nodes = v.findReferencesAsNodes();
25
+ temp_nodes.forEach(node => this.processNodeForAccesses(node, id));
26
+ }
27
+ catch (error) {
28
+ console.error(`> WARNING: got exception ${error}. Continuing...`);
29
+ }
30
+ });
31
+ }
32
+ /**
33
+ * Builds a Famix model for an access on a parameter, variable, property or enum member
34
+ * @param n A node
35
+ * @param id An id of a parameter, a variable, a property or an enum member
36
+ */
37
+ processNodeForAccesses(n, id) {
38
+ try {
39
+ // sometimes node's first ancestor is a PropertyDeclaration, which is not an access
40
+ // see https://github.com/fuhrmanator/FamixTypeScriptImporter/issues/9
41
+ // check for a node whose first ancestor is a property declaration and bail?
42
+ // This may be a bug in ts-morph?
43
+ if (n.getFirstAncestorOrThrow().getKindName() === "PropertyDeclaration") {
44
+ console.info(`processNodeForAccesses: node kind: ${n.getKindName()}, ${n.getText()}, (${n.getType().getText()})'s first ancestor is a PropertyDeclaration. Skipping...`);
45
+ return;
46
+ }
47
+ this.famixFunctions.createFamixAccess(n, id);
48
+ console.info(`processNodeForAccesses: node kind: ${n.getKindName()}, ${n.getText()}, (${n.getType().getText()})`);
49
+ }
50
+ catch (error) {
51
+ console.error(`> WARNING: got exception ${error}. ScopeDeclaration invalid for ${n.getSymbol().getFullyQualifiedName()}. Continuing...`);
52
+ }
53
+ }
54
+ }
55
+ exports.ProcessAccesses = ProcessAccesses;