arkanalyzer 1.0.20 → 1.0.21

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 (279) hide show
  1. package/lib/Config.d.ts +70 -70
  2. package/lib/Config.js +198 -198
  3. package/lib/Scene.d.ts +316 -316
  4. package/lib/Scene.js +1316 -1316
  5. package/lib/callgraph/algorithm/AbstractAnalysis.d.ts +28 -28
  6. package/lib/callgraph/algorithm/AbstractAnalysis.js +144 -144
  7. package/lib/callgraph/algorithm/ClassHierarchyAnalysis.d.ts +10 -10
  8. package/lib/callgraph/algorithm/ClassHierarchyAnalysis.js +69 -69
  9. package/lib/callgraph/algorithm/RapidTypeAnalysis.d.ts +15 -15
  10. package/lib/callgraph/algorithm/RapidTypeAnalysis.js +146 -146
  11. package/lib/callgraph/common/Statistics.d.ts +57 -57
  12. package/lib/callgraph/common/Statistics.js +228 -228
  13. package/lib/callgraph/model/CallGraph.d.ts +96 -96
  14. package/lib/callgraph/model/CallGraph.js +354 -354
  15. package/lib/callgraph/model/builder/CallGraphBuilder.d.ts +15 -15
  16. package/lib/callgraph/model/builder/CallGraphBuilder.js +106 -106
  17. package/lib/callgraph/pointerAnalysis/Context.d.ts +37 -37
  18. package/lib/callgraph/pointerAnalysis/Context.js +155 -155
  19. package/lib/callgraph/pointerAnalysis/DummyCallCreator.d.ts +22 -22
  20. package/lib/callgraph/pointerAnalysis/DummyCallCreator.js +104 -104
  21. package/lib/callgraph/pointerAnalysis/PTAUtils.d.ts +5 -5
  22. package/lib/callgraph/pointerAnalysis/PTAUtils.js +46 -46
  23. package/lib/callgraph/pointerAnalysis/Pag.d.ts +261 -261
  24. package/lib/callgraph/pointerAnalysis/Pag.js +930 -930
  25. package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts +157 -157
  26. package/lib/callgraph/pointerAnalysis/PagBuilder.js +1399 -1399
  27. package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts +72 -72
  28. package/lib/callgraph/pointerAnalysis/PointerAnalysis.js +573 -573
  29. package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.d.ts +15 -15
  30. package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.js +81 -81
  31. package/lib/callgraph/pointerAnalysis/PtsDS.d.ts +80 -80
  32. package/lib/callgraph/pointerAnalysis/PtsDS.js +308 -308
  33. package/lib/core/base/Constant.d.ts +48 -48
  34. package/lib/core/base/Constant.js +103 -103
  35. package/lib/core/base/Decorator.d.ts +15 -15
  36. package/lib/core/base/Decorator.js +46 -46
  37. package/lib/core/base/DefUseChain.d.ts +8 -8
  38. package/lib/core/base/DefUseChain.js +25 -25
  39. package/lib/core/base/Expr.d.ts +340 -340
  40. package/lib/core/base/Expr.js +917 -917
  41. package/lib/core/base/Local.d.ts +104 -104
  42. package/lib/core/base/Local.js +176 -176
  43. package/lib/core/base/Position.d.ts +30 -30
  44. package/lib/core/base/Position.js +147 -147
  45. package/lib/core/base/Ref.d.ts +173 -173
  46. package/lib/core/base/Ref.js +374 -374
  47. package/lib/core/base/Stmt.d.ts +237 -237
  48. package/lib/core/base/Stmt.js +525 -525
  49. package/lib/core/base/Trap.d.ts +8 -8
  50. package/lib/core/base/Trap.js +30 -30
  51. package/lib/core/base/Type.d.ts +308 -308
  52. package/lib/core/base/Type.js +639 -639
  53. package/lib/core/base/TypeExpr.d.ts +71 -71
  54. package/lib/core/base/TypeExpr.js +155 -155
  55. package/lib/core/base/Value.d.ts +32 -32
  56. package/lib/core/base/Value.js +16 -16
  57. package/lib/core/common/ArkError.d.ts +14 -14
  58. package/lib/core/common/ArkError.js +28 -28
  59. package/lib/core/common/ArkIRTransformer.d.ts +67 -67
  60. package/lib/core/common/ArkIRTransformer.js +690 -690
  61. package/lib/core/common/ArkValueTransformer.d.ts +89 -89
  62. package/lib/core/common/ArkValueTransformer.js +1478 -1478
  63. package/lib/core/common/Builtin.d.ts +36 -36
  64. package/lib/core/common/Builtin.js +81 -81
  65. package/lib/core/common/Const.d.ts +21 -21
  66. package/lib/core/common/Const.js +43 -43
  67. package/lib/core/common/DummyMainCreater.d.ts +46 -46
  68. package/lib/core/common/DummyMainCreater.js +319 -319
  69. package/lib/core/common/EtsConst.d.ts +73 -73
  70. package/lib/core/common/EtsConst.js +1021 -1021
  71. package/lib/core/common/ExprUseReplacer.d.ts +21 -21
  72. package/lib/core/common/ExprUseReplacer.js +124 -124
  73. package/lib/core/common/IRInference.d.ts +36 -36
  74. package/lib/core/common/IRInference.d.ts.map +1 -1
  75. package/lib/core/common/IRInference.js +651 -648
  76. package/lib/core/common/IRUtils.d.ts +18 -18
  77. package/lib/core/common/IRUtils.js +141 -141
  78. package/lib/core/common/ModelUtils.d.ts +70 -70
  79. package/lib/core/common/ModelUtils.js +712 -712
  80. package/lib/core/common/RefUseReplacer.d.ts +13 -13
  81. package/lib/core/common/RefUseReplacer.js +52 -52
  82. package/lib/core/common/SdkUtils.d.ts +8 -8
  83. package/lib/core/common/SdkUtils.js +105 -105
  84. package/lib/core/common/StmtDefReplacer.d.ts +12 -12
  85. package/lib/core/common/StmtDefReplacer.js +41 -41
  86. package/lib/core/common/StmtUseReplacer.d.ts +16 -16
  87. package/lib/core/common/StmtUseReplacer.js +108 -108
  88. package/lib/core/common/TSConst.d.ts +18 -18
  89. package/lib/core/common/TSConst.js +36 -36
  90. package/lib/core/common/TypeInference.d.ts +102 -102
  91. package/lib/core/common/TypeInference.js +748 -748
  92. package/lib/core/common/ValueUtil.d.ts +12 -12
  93. package/lib/core/common/ValueUtil.js +54 -54
  94. package/lib/core/common/VisibleValue.d.ts +36 -36
  95. package/lib/core/common/VisibleValue.js +212 -212
  96. package/lib/core/dataflow/DataflowProblem.d.ts +20 -20
  97. package/lib/core/dataflow/DataflowProblem.js +20 -20
  98. package/lib/core/dataflow/DataflowResult.d.ts +7 -7
  99. package/lib/core/dataflow/DataflowResult.js +26 -26
  100. package/lib/core/dataflow/DataflowSolver.d.ts +43 -43
  101. package/lib/core/dataflow/DataflowSolver.js +307 -307
  102. package/lib/core/dataflow/Edge.d.ts +11 -11
  103. package/lib/core/dataflow/Edge.js +31 -31
  104. package/lib/core/dataflow/Fact.d.ts +6 -6
  105. package/lib/core/dataflow/Fact.js +24 -24
  106. package/lib/core/dataflow/GenericDataFlow.d.ts +142 -142
  107. package/lib/core/dataflow/GenericDataFlow.js +109 -109
  108. package/lib/core/dataflow/ReachingDef.d.ts +62 -62
  109. package/lib/core/dataflow/ReachingDef.js +168 -168
  110. package/lib/core/dataflow/UndefinedVariable.d.ts +45 -45
  111. package/lib/core/dataflow/UndefinedVariable.js +288 -288
  112. package/lib/core/dataflow/Util.d.ts +9 -9
  113. package/lib/core/dataflow/Util.js +64 -64
  114. package/lib/core/graph/BaseExplicitGraph.d.ts +58 -58
  115. package/lib/core/graph/BaseExplicitGraph.js +157 -157
  116. package/lib/core/graph/BaseImplicitGraph.d.ts +77 -77
  117. package/lib/core/graph/BaseImplicitGraph.js +78 -78
  118. package/lib/core/graph/BasicBlock.d.ts +104 -104
  119. package/lib/core/graph/BasicBlock.js +280 -280
  120. package/lib/core/graph/Cfg.d.ts +59 -59
  121. package/lib/core/graph/Cfg.js +282 -282
  122. package/lib/core/graph/DependsGraph.d.ts +35 -35
  123. package/lib/core/graph/DependsGraph.js +87 -87
  124. package/lib/core/graph/DominanceFinder.d.ts +15 -15
  125. package/lib/core/graph/DominanceFinder.js +121 -121
  126. package/lib/core/graph/DominanceTree.d.ts +12 -12
  127. package/lib/core/graph/DominanceTree.js +70 -70
  128. package/lib/core/graph/GraphTraits.d.ts +7 -7
  129. package/lib/core/graph/GraphTraits.js +16 -16
  130. package/lib/core/graph/Scc.d.ts +61 -61
  131. package/lib/core/graph/Scc.js +222 -222
  132. package/lib/core/graph/ViewTree.d.ts +114 -114
  133. package/lib/core/graph/ViewTree.js +16 -16
  134. package/lib/core/graph/builder/CfgBuilder.d.ts +176 -176
  135. package/lib/core/graph/builder/CfgBuilder.js +1139 -1139
  136. package/lib/core/graph/builder/ConditionBuilder.d.ts +15 -15
  137. package/lib/core/graph/builder/ConditionBuilder.js +252 -252
  138. package/lib/core/graph/builder/LoopBuilder.d.ts +20 -20
  139. package/lib/core/graph/builder/LoopBuilder.js +251 -251
  140. package/lib/core/graph/builder/SwitchBuilder.d.ts +11 -11
  141. package/lib/core/graph/builder/SwitchBuilder.js +152 -152
  142. package/lib/core/graph/builder/TrapBuilder.d.ts +16 -16
  143. package/lib/core/graph/builder/TrapBuilder.js +272 -272
  144. package/lib/core/graph/builder/ViewTreeBuilder.d.ts +203 -203
  145. package/lib/core/graph/builder/ViewTreeBuilder.js +1055 -1055
  146. package/lib/core/model/ArkBaseModel.d.ts +59 -59
  147. package/lib/core/model/ArkBaseModel.js +274 -274
  148. package/lib/core/model/ArkBody.d.ts +24 -24
  149. package/lib/core/model/ArkBody.js +65 -65
  150. package/lib/core/model/ArkClass.d.ts +206 -206
  151. package/lib/core/model/ArkClass.js +439 -439
  152. package/lib/core/model/ArkExport.d.ts +72 -72
  153. package/lib/core/model/ArkExport.js +147 -147
  154. package/lib/core/model/ArkField.d.ts +62 -62
  155. package/lib/core/model/ArkField.js +113 -113
  156. package/lib/core/model/ArkFile.d.ts +131 -131
  157. package/lib/core/model/ArkFile.js +267 -267
  158. package/lib/core/model/ArkImport.d.ts +44 -44
  159. package/lib/core/model/ArkImport.js +108 -108
  160. package/lib/core/model/ArkMetadata.d.ts +31 -31
  161. package/lib/core/model/ArkMetadata.js +55 -55
  162. package/lib/core/model/ArkMethod.d.ts +261 -261
  163. package/lib/core/model/ArkMethod.js +592 -592
  164. package/lib/core/model/ArkNamespace.d.ts +66 -66
  165. package/lib/core/model/ArkNamespace.js +209 -209
  166. package/lib/core/model/ArkSignature.d.ts +162 -162
  167. package/lib/core/model/ArkSignature.js +379 -379
  168. package/lib/core/model/builder/ArkClassBuilder.d.ts +12 -12
  169. package/lib/core/model/builder/ArkClassBuilder.js +454 -454
  170. package/lib/core/model/builder/ArkExportBuilder.d.ts +24 -24
  171. package/lib/core/model/builder/ArkExportBuilder.js +210 -210
  172. package/lib/core/model/builder/ArkFieldBuilder.d.ts +8 -8
  173. package/lib/core/model/builder/ArkFieldBuilder.js +193 -193
  174. package/lib/core/model/builder/ArkFileBuilder.d.ts +9 -9
  175. package/lib/core/model/builder/ArkFileBuilder.js +165 -165
  176. package/lib/core/model/builder/ArkImportBuilder.d.ts +4 -4
  177. package/lib/core/model/builder/ArkImportBuilder.js +128 -128
  178. package/lib/core/model/builder/ArkMethodBuilder.d.ts +63 -63
  179. package/lib/core/model/builder/ArkMethodBuilder.js +486 -486
  180. package/lib/core/model/builder/ArkNamespaceBuilder.d.ts +5 -5
  181. package/lib/core/model/builder/ArkNamespaceBuilder.js +205 -205
  182. package/lib/core/model/builder/ArkSignatureBuilder.d.ts +8 -8
  183. package/lib/core/model/builder/ArkSignatureBuilder.js +40 -40
  184. package/lib/core/model/builder/BodyBuilder.d.ts +55 -30
  185. package/lib/core/model/builder/BodyBuilder.d.ts.map +1 -1
  186. package/lib/core/model/builder/BodyBuilder.js +542 -371
  187. package/lib/core/model/builder/builderUtils.d.ts +18 -18
  188. package/lib/core/model/builder/builderUtils.js +558 -558
  189. package/lib/index.d.ts +82 -80
  190. package/lib/index.d.ts.map +1 -1
  191. package/lib/index.js +201 -196
  192. package/lib/save/ArkStream.d.ts +23 -23
  193. package/lib/save/ArkStream.js +83 -83
  194. package/lib/save/DotPrinter.d.ts +43 -43
  195. package/lib/save/DotPrinter.js +170 -170
  196. package/lib/save/GraphPrinter.d.ts +16 -16
  197. package/lib/save/GraphPrinter.js +134 -134
  198. package/lib/save/JsonPrinter.d.ts +30 -30
  199. package/lib/save/JsonPrinter.js +580 -580
  200. package/lib/save/Printer.d.ts +12 -12
  201. package/lib/save/Printer.js +27 -27
  202. package/lib/save/PrinterBuilder.d.ts +53 -53
  203. package/lib/save/PrinterBuilder.js +145 -145
  204. package/lib/save/ViewTreePrinter.d.ts +14 -14
  205. package/lib/save/ViewTreePrinter.js +123 -123
  206. package/lib/save/arkir/ArkIRClassPrinter.d.ts +13 -13
  207. package/lib/save/arkir/ArkIRClassPrinter.js +92 -92
  208. package/lib/save/arkir/ArkIRFieldPrinter.d.ts +11 -11
  209. package/lib/save/arkir/ArkIRFieldPrinter.js +64 -64
  210. package/lib/save/arkir/ArkIRFilePrinter.d.ts +12 -12
  211. package/lib/save/arkir/ArkIRFilePrinter.js +54 -54
  212. package/lib/save/arkir/ArkIRMethodPrinter.d.ts +16 -16
  213. package/lib/save/arkir/ArkIRMethodPrinter.js +159 -159
  214. package/lib/save/arkir/ArkIRNamespacePrinter.d.ts +11 -11
  215. package/lib/save/arkir/ArkIRNamespacePrinter.js +66 -66
  216. package/lib/save/base/BasePrinter.d.ts +23 -23
  217. package/lib/save/base/BasePrinter.js +70 -70
  218. package/lib/save/base/ExportPrinter.d.ts +8 -8
  219. package/lib/save/base/ExportPrinter.js +67 -67
  220. package/lib/save/base/ImportPrinter.d.ts +9 -9
  221. package/lib/save/base/ImportPrinter.js +92 -92
  222. package/lib/save/base/PrinterUtils.d.ts +24 -24
  223. package/lib/save/base/PrinterUtils.js +208 -208
  224. package/lib/save/serializeArkIR.d.ts +8 -8
  225. package/lib/save/serializeArkIR.js +294 -294
  226. package/lib/save/source/SourceBase.d.ts +22 -22
  227. package/lib/save/source/SourceBase.js +64 -64
  228. package/lib/save/source/SourceBody.d.ts +58 -58
  229. package/lib/save/source/SourceBody.js +296 -296
  230. package/lib/save/source/SourceClass.d.ts +25 -25
  231. package/lib/save/source/SourceClass.js +187 -187
  232. package/lib/save/source/SourceField.d.ts +13 -13
  233. package/lib/save/source/SourceField.js +73 -73
  234. package/lib/save/source/SourceFilePrinter.d.ts +12 -12
  235. package/lib/save/source/SourceFilePrinter.js +69 -69
  236. package/lib/save/source/SourceMethod.d.ts +22 -22
  237. package/lib/save/source/SourceMethod.d.ts.map +1 -1
  238. package/lib/save/source/SourceMethod.js +196 -193
  239. package/lib/save/source/SourceNamespace.d.ts +11 -11
  240. package/lib/save/source/SourceNamespace.js +83 -83
  241. package/lib/save/source/SourceStmt.d.ts +178 -178
  242. package/lib/save/source/SourceStmt.js +838 -838
  243. package/lib/save/source/SourceTransformer.d.ts +46 -46
  244. package/lib/save/source/SourceTransformer.js +446 -446
  245. package/lib/transformer/FunctionTransformer.d.ts +2 -2
  246. package/lib/transformer/FunctionTransformer.js +17 -17
  247. package/lib/transformer/SceneTransformer.d.ts +2 -2
  248. package/lib/transformer/SceneTransformer.js +17 -17
  249. package/lib/transformer/StaticSingleAssignmentFormer.d.ts +12 -12
  250. package/lib/transformer/StaticSingleAssignmentFormer.js +259 -259
  251. package/lib/transformer/Transformer.d.ts +6 -6
  252. package/lib/transformer/Transformer.js +22 -22
  253. package/lib/utils/AstTreeUtils.d.ts +4 -4
  254. package/lib/utils/AstTreeUtils.js +26 -26
  255. package/lib/utils/CfgStructualAnalysis.d.ts +110 -110
  256. package/lib/utils/CfgStructualAnalysis.js +1277 -1277
  257. package/lib/utils/FileUtils.d.ts +18 -18
  258. package/lib/utils/FileUtils.js +135 -135
  259. package/lib/utils/SparseBitVector.d.ts +100 -100
  260. package/lib/utils/SparseBitVector.js +445 -445
  261. package/lib/utils/callGraphUtils.d.ts +30 -30
  262. package/lib/utils/callGraphUtils.js +205 -205
  263. package/lib/utils/crypto_utils.d.ts +5 -5
  264. package/lib/utils/crypto_utils.js +57 -57
  265. package/lib/utils/entryMethodUtils.d.ts +13 -13
  266. package/lib/utils/entryMethodUtils.js +110 -110
  267. package/lib/utils/getAllFiles.d.ts +9 -9
  268. package/lib/utils/getAllFiles.js +90 -90
  269. package/lib/utils/json5parser.d.ts +6 -6
  270. package/lib/utils/json5parser.js +146 -146
  271. package/lib/utils/logger.d.ts +18 -18
  272. package/lib/utils/logger.d.ts.map +1 -1
  273. package/lib/utils/logger.js +97 -90
  274. package/lib/utils/pathTransfer.d.ts +1 -1
  275. package/lib/utils/pathTransfer.js +25 -25
  276. package/node_modules/json5/lib/cli.js +0 -0
  277. package/node_modules/ohos-typescript/bin/tsc +0 -0
  278. package/node_modules/ohos-typescript/bin/tsserver +0 -0
  279. package/package.json +3 -3
@@ -1,714 +1,714 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2024 Huawei Device Co., Ltd.
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
17
- if (k2 === undefined) k2 = k;
18
- var desc = Object.getOwnPropertyDescriptor(m, k);
19
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
20
- desc = { enumerable: true, get: function() { return m[k]; } };
21
- }
22
- Object.defineProperty(o, k2, desc);
23
- }) : (function(o, m, k, k2) {
24
- if (k2 === undefined) k2 = k;
25
- o[k2] = m[k];
26
- }));
27
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
28
- Object.defineProperty(o, "default", { enumerable: true, value: v });
29
- }) : function(o, v) {
30
- o["default"] = v;
31
- });
32
- var __importStar = (this && this.__importStar) || function (mod) {
33
- if (mod && mod.__esModule) return mod;
34
- var result = {};
35
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
36
- __setModuleDefault(result, mod);
37
- return result;
38
- };
39
- var __importDefault = (this && this.__importDefault) || function (mod) {
40
- return (mod && mod.__esModule) ? mod : { "default": mod };
41
- };
42
- Object.defineProperty(exports, "__esModule", { value: true });
43
- exports.initModulePathMap = exports.findArkExportInFile = exports.findArkExport = exports.findExportInfo = exports.getArkFile = exports.sdkImportMap = exports.ModelUtils = void 0;
44
- const Local_1 = require("../base/Local");
45
- const ArkClass_1 = require("../model/ArkClass");
46
- const ArkMethod_1 = require("../model/ArkMethod");
47
- const ArkNamespace_1 = require("../model/ArkNamespace");
48
- const ArkSignature_1 = require("../model/ArkSignature");
49
- const ArkExport_1 = require("../model/ArkExport");
50
- const ArkField_1 = require("../model/ArkField");
51
- const logger_1 = __importStar(require("../../utils/logger"));
52
- const FileUtils_1 = require("../../utils/FileUtils");
53
- const path_1 = __importDefault(require("path"));
54
- const TSConst_1 = require("./TSConst");
55
- const ArkExportBuilder_1 = require("../model/builder/ArkExportBuilder");
56
- const Type_1 = require("../base/Type");
57
- const Const_1 = require("./Const");
58
- const ValueUtil_1 = require("./ValueUtil");
59
- class ModelUtils {
60
- static getMethodSignatureFromArkClass(arkClass, methodName) {
61
- for (const arkMethod of arkClass.getMethods()) {
62
- if (arkMethod.getName() === methodName) {
63
- return arkMethod.getSignature();
64
- }
65
- }
66
- return null;
67
- }
68
- static getClassWithNameInNamespaceRecursively(className, ns) {
69
- if (className === '') {
70
- return null;
71
- }
72
- let res = null;
73
- res = ns.getClassWithName(className);
74
- if (res == null) {
75
- let declaringNs = ns.getDeclaringArkNamespace();
76
- if (declaringNs != null) {
77
- res = this.getClassWithNameInNamespaceRecursively(className, declaringNs);
78
- }
79
- else {
80
- res = this.getClassInFileWithName(className, ns.getDeclaringArkFile());
81
- }
82
- }
83
- return res;
84
- }
85
- static getClassWithNameFromClass(className, startFrom) {
86
- if (!className.includes('.')) {
87
- let res = null;
88
- const arkNamespace = startFrom.getDeclaringArkNamespace();
89
- if (arkNamespace) {
90
- res = this.getClassWithNameInNamespaceRecursively(className, arkNamespace);
91
- }
92
- else {
93
- res = this.getClassInFileWithName(className, startFrom.getDeclaringArkFile());
94
- }
95
- return res;
96
- }
97
- else {
98
- const names = className.split('.');
99
- let nameSpace = this.getNamespaceWithNameFromClass(names[0], startFrom);
100
- for (let i = 1; i < names.length - 1; i++) {
101
- if (nameSpace)
102
- nameSpace = nameSpace.getNamespaceWithName(names[i]);
103
- }
104
- if (nameSpace) {
105
- return nameSpace.getClassWithName(names[names.length - 1]);
106
- }
107
- }
108
- return null;
109
- }
110
- /**
111
- * search class within the file that contain the given method
112
- */
113
- static getClassWithName(className, thisClass) {
114
- var _a;
115
- if (thisClass.getName() === className) {
116
- return thisClass;
117
- }
118
- let classSearched = (_a = thisClass.getDeclaringArkNamespace()) === null || _a === void 0 ? void 0 : _a.getClassWithName(className);
119
- if (!classSearched) {
120
- classSearched = thisClass.getDeclaringArkFile().getClassWithName(className);
121
- }
122
- return classSearched;
123
- }
124
- /** search class within the given file */
125
- static getClassInFileWithName(className, arkFile) {
126
- let classSearched = arkFile.getClassWithName(className);
127
- if (classSearched != null) {
128
- return classSearched;
129
- }
130
- return null;
131
- }
132
- static getClassInImportInfoWithName(className, arkFile) {
133
- let arkExport = this.getArkExportInImportInfoWithName(className, arkFile);
134
- if (arkExport instanceof ArkClass_1.ArkClass) {
135
- return arkExport;
136
- }
137
- return null;
138
- }
139
- /** search type within the given file import infos */
140
- static getArkExportInImportInfoWithName(name, arkFile) {
141
- var _a, _b, _c;
142
- return (_c = (_b = (_a = arkFile.getImportInfoBy(name)) === null || _a === void 0 ? void 0 : _a.getLazyExportInfo()) === null || _b === void 0 ? void 0 : _b.getArkExport()) !== null && _c !== void 0 ? _c : null;
143
- }
144
- /** search method within the file that contain the given method */
145
- static getMethodWithName(methodName, startFrom) {
146
- if (!methodName.includes('.')) {
147
- if (startFrom.getName() === methodName) {
148
- return startFrom;
149
- }
150
- const thisClass = startFrom.getDeclaringArkClass();
151
- let methodSearched = thisClass.getMethodWithName(methodName);
152
- if (!methodSearched) {
153
- methodSearched = thisClass.getStaticMethodWithName(methodName);
154
- }
155
- return methodSearched;
156
- }
157
- else {
158
- const names = methodName.split('.');
159
- let nameSpace = this.getNamespaceWithName(names[0], startFrom.getDeclaringArkClass());
160
- for (let i = 1; i < names.length - 1; i++) {
161
- if (nameSpace) {
162
- nameSpace = nameSpace.getNamespaceWithName(names[i]);
163
- }
164
- }
165
- if (nameSpace) {
166
- return nameSpace.getDefaultClass().getMethodWithName(names[names.length - 1]);
167
- }
168
- }
169
- return null;
170
- }
171
- static getNamespaceWithNameFromClass(namespaceName, startFrom) {
172
- const thisNamespace = startFrom.getDeclaringArkNamespace();
173
- let namespaceSearched = null;
174
- if (thisNamespace) {
175
- namespaceSearched = thisNamespace.getNamespaceWithName(namespaceName);
176
- if (namespaceSearched) {
177
- return namespaceSearched;
178
- }
179
- }
180
- const thisFile = startFrom.getDeclaringArkFile();
181
- namespaceSearched = this.getNamespaceInFileWithName(namespaceName, thisFile);
182
- return namespaceSearched;
183
- }
184
- static getNamespaceWithName(namespaceName, thisClass) {
185
- let thisNamespace = thisClass.getDeclaringArkNamespace();
186
- let namespaceSearched = null;
187
- while (!namespaceSearched && thisNamespace) {
188
- namespaceSearched = thisNamespace.getNamespaceWithName(namespaceName);
189
- thisNamespace = thisNamespace.getDeclaringArkNamespace();
190
- }
191
- if (!namespaceSearched) {
192
- namespaceSearched = thisClass.getDeclaringArkFile().getNamespaceWithName(namespaceName);
193
- }
194
- return namespaceSearched;
195
- }
196
- static getNamespaceInFileWithName(namespaceName, arkFile) {
197
- let namespaceSearched = arkFile.getNamespaceWithName(namespaceName);
198
- if (namespaceSearched) {
199
- return namespaceSearched;
200
- }
201
- return null;
202
- }
203
- static getNamespaceInImportInfoWithName(namespaceName, arkFile) {
204
- let arkExport = this.getArkExportInImportInfoWithName(namespaceName, arkFile);
205
- if (arkExport instanceof ArkNamespace_1.ArkNamespace) {
206
- return arkExport;
207
- }
208
- return null;
209
- }
210
- static getStaticMethodWithName(methodName, thisClass) {
211
- const thisNamespace = thisClass.getDeclaringArkNamespace();
212
- if (thisNamespace) {
213
- const defaultClass = thisNamespace.getClassWithName(Const_1.DEFAULT_ARK_CLASS_NAME);
214
- if (defaultClass) {
215
- const method = defaultClass.getMethodWithName(methodName);
216
- if (method) {
217
- return method;
218
- }
219
- }
220
- }
221
- return this.getStaticMethodInFileWithName(methodName, thisClass.getDeclaringArkFile());
222
- }
223
- static getStaticMethodInFileWithName(methodName, arkFile) {
224
- const defaultClass = arkFile.getClasses().find(cls => cls.getName() === Const_1.DEFAULT_ARK_CLASS_NAME) || null;
225
- if (defaultClass) {
226
- let method = defaultClass.getMethodWithName(methodName);
227
- if (method) {
228
- return method;
229
- }
230
- }
231
- return null;
232
- }
233
- static getStaticMethodInImportInfoWithName(methodName, arkFile) {
234
- let arkExport = this.getArkExportInImportInfoWithName(methodName, arkFile);
235
- if (arkExport instanceof ArkMethod_1.ArkMethod) {
236
- return arkExport;
237
- }
238
- return null;
239
- }
240
- static getLocalInImportInfoWithName(localName, arkFile) {
241
- let arkExport = this.getArkExportInImportInfoWithName(localName, arkFile);
242
- if (arkExport instanceof Local_1.Local) {
243
- return arkExport;
244
- }
245
- return null;
246
- }
247
- /* get nested namespaces in a file */
248
- static getAllNamespacesInFile(arkFile) {
249
- const arkNamespaces = arkFile.getNamespaces();
250
- for (const arkNamespace of arkFile.getNamespaces()) {
251
- this.getAllNamespacesInNamespace(arkNamespace, arkNamespaces);
252
- }
253
- return arkNamespaces;
254
- }
255
- /* get nested namespaces in a namespace */
256
- static getAllNamespacesInNamespace(arkNamespace, allNamespaces) {
257
- allNamespaces.push(...arkNamespace.getNamespaces());
258
- for (const nestedNamespace of arkNamespace.getNamespaces()) {
259
- this.getAllNamespacesInNamespace(nestedNamespace, allNamespaces);
260
- }
261
- }
262
- static getAllClassesInFile(arkFile) {
263
- const allClasses = arkFile.getClasses();
264
- this.getAllNamespacesInFile(arkFile).forEach((namespace) => {
265
- allClasses.push(...namespace.getClasses());
266
- });
267
- return allClasses;
268
- }
269
- static getAllMethodsInFile(arkFile) {
270
- const allMethods = [];
271
- this.getAllClassesInFile(arkFile).forEach((cls) => {
272
- allMethods.push(...cls.getMethods());
273
- });
274
- return allMethods;
275
- }
276
- static isArkUIBuilderMethod(arkMethod) {
277
- let isArkUIBuilderMethod = arkMethod.hasBuilderDecorator() || this.implicitArkUIBuilderMethods.has(arkMethod);
278
- if (!isArkUIBuilderMethod &&
279
- arkMethod.getName() === 'build' &&
280
- arkMethod.getDeclaringArkClass().hasComponentDecorator() &&
281
- !arkMethod.isStatic()) {
282
- const fileName = arkMethod.getDeclaringArkClass().getDeclaringArkFile().getName();
283
- if (fileName.endsWith('.ets')) {
284
- isArkUIBuilderMethod = true;
285
- }
286
- }
287
- return isArkUIBuilderMethod;
288
- }
289
- static getArkClassInBuild(scene, classType) {
290
- var _a;
291
- const classSignature = classType.getClassSignature();
292
- const file = scene.getFile(classSignature.getDeclaringFileSignature());
293
- const namespaceSignature = classSignature.getDeclaringNamespaceSignature();
294
- if (namespaceSignature) {
295
- return ((_a = file === null || file === void 0 ? void 0 : file.getNamespace(namespaceSignature)) === null || _a === void 0 ? void 0 : _a.getClass(classSignature)) || null;
296
- }
297
- return (file === null || file === void 0 ? void 0 : file.getClassWithName(classSignature.getClassName())) || null;
298
- }
299
- static getDefaultClass(arkClass) {
300
- var _a, _b;
301
- return (_b = (_a = arkClass.getDeclaringArkNamespace()) === null || _a === void 0 ? void 0 : _a.getDefaultClass()) !== null && _b !== void 0 ? _b : arkClass.getDeclaringArkFile().getDefaultClass();
302
- }
303
- static getClass(method, signature) {
304
- var _a;
305
- let cls = method.getDeclaringArkFile().getScene().getClass(signature);
306
- if (cls) {
307
- return cls;
308
- }
309
- let importInfo = method.getDeclaringArkFile().getImportInfoBy(signature.getClassName());
310
- let exportInfo = importInfo ? findExportInfo(importInfo) : null;
311
- let arkExport = exportInfo === null || exportInfo === void 0 ? void 0 : exportInfo.getArkExport();
312
- if (arkExport instanceof ArkClass_1.ArkClass) {
313
- return arkExport;
314
- }
315
- cls = (_a = method.getDeclaringArkClass().getDeclaringArkNamespace()) === null || _a === void 0 ? void 0 : _a.getClassWithName(signature.getClassName());
316
- if (cls) {
317
- return cls;
318
- }
319
- for (const ns of method.getDeclaringArkFile().getAllNamespacesUnderThisFile()) {
320
- cls = ns.getClassWithName(signature.getClassName());
321
- if (cls) {
322
- return cls;
323
- }
324
- }
325
- return method.getDeclaringArkFile().getClassWithName(signature.getClassName());
326
- }
327
- static findPropertyInNamespace(name, namespace) {
328
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
329
- return (_j = (_e = (_d = (_c = (_b = (_a = namespace.getDefaultClass()) === null || _a === void 0 ? void 0 : _a.getMethodWithName(name)) !== null && _b !== void 0 ? _b : findArkExport(namespace.getExportInfoBy(name))) !== null && _c !== void 0 ? _c : namespace.getClassWithName(name)) !== null && _d !== void 0 ? _d : namespace.getNamespaceWithName(name)) !== null && _e !== void 0 ? _e : (_h = (_g = (_f = namespace.getDefaultClass()) === null || _f === void 0 ? void 0 : _f.getDefaultArkMethod()) === null || _g === void 0 ? void 0 : _g.getBody()) === null || _h === void 0 ? void 0 : _h.getAliasTypeByName(name)) !== null && _j !== void 0 ? _j : (_o = (_m = (_l = (_k = namespace.getDefaultClass()) === null || _k === void 0 ? void 0 : _k.getDefaultArkMethod()) === null || _l === void 0 ? void 0 : _l.getBody()) === null || _m === void 0 ? void 0 : _m.getLocals()) === null || _o === void 0 ? void 0 : _o.get(name);
330
- }
331
- static findPropertyInClass(name, arkClass) {
332
- var _a, _b, _c;
333
- let property = (_c = (_b = (_a = arkClass.getMethodWithName(name)) !== null && _a !== void 0 ? _a : arkClass.getStaticMethodWithName(name)) !== null && _b !== void 0 ? _b : arkClass.getFieldWithName(name)) !== null && _c !== void 0 ? _c : arkClass.getStaticFieldWithName(name);
334
- if (property) {
335
- return property;
336
- }
337
- if (arkClass.isDefaultArkClass()) {
338
- return findArkExport(arkClass.getDeclaringArkFile().getExportInfoBy(name));
339
- }
340
- for (const heritage of arkClass.getAllHeritageClasses()) {
341
- property = this.findPropertyInClass(name, heritage);
342
- if (property) {
343
- return property;
344
- }
345
- }
346
- return null;
347
- }
348
- static findDeclaredLocal(local, arkMethod, times = 0) {
349
- var _a, _b, _c;
350
- if (arkMethod.getDeclaringArkFile().getScene().getOptions().isScanAbc) {
351
- return null;
352
- }
353
- const name = local.getName();
354
- if (name === TSConst_1.THIS_NAME || name.startsWith(Const_1.TEMP_LOCAL_PREFIX)) {
355
- return null;
356
- }
357
- if (times > 0) {
358
- const parameter = arkMethod.getParameters().find(p => p.getName() === name);
359
- if (parameter) {
360
- return new Local_1.Local(parameter.getName(), parameter.getType());
361
- }
362
- const declaredLocal = (_a = arkMethod.getBody()) === null || _a === void 0 ? void 0 : _a.getLocals().get(name);
363
- if (declaredLocal && declaredLocal.getDeclaringStmt()) {
364
- return declaredLocal;
365
- }
366
- }
367
- let parentName = arkMethod.getName();
368
- if (parentName === Const_1.DEFAULT_ARK_METHOD_NAME) {
369
- return null;
370
- }
371
- const start = parentName.indexOf(Const_1.NAME_DELIMITER);
372
- let invokeMethod;
373
- if (start < 0) {
374
- const cls = arkMethod.getDeclaringArkClass();
375
- invokeMethod = (_b = cls.getDefaultArkMethod()) !== null && _b !== void 0 ? _b : (_c = cls.getDeclaringArkFile().getDefaultClass()) === null || _c === void 0 ? void 0 : _c.getDefaultArkMethod();
376
- }
377
- else {
378
- parentName = parentName.substring(start + 1);
379
- invokeMethod = arkMethod.getDeclaringArkClass().getMethodWithName(parentName);
380
- }
381
- if (invokeMethod) {
382
- return this.findDeclaredLocal(local, invokeMethod, ++times);
383
- }
384
- return null;
385
- }
386
- static findArkModel(baseName, arkClass) {
387
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
388
- let arkModel = (_c = (_b = (_a = arkClass.getMethodWithName(baseName)) !== null && _a !== void 0 ? _a : arkClass.getStaticMethodWithName(baseName)) !== null && _b !== void 0 ? _b : arkClass.getFieldWithName(baseName)) !== null && _c !== void 0 ? _c : arkClass.getStaticFieldWithName(baseName);
389
- if (arkModel) {
390
- return arkModel;
391
- }
392
- arkModel = (_r = (_m = (_k = (_j = (_h = (_g = (_f = (_e = (_d = ModelUtils.getDefaultClass(arkClass)) === null || _d === void 0 ? void 0 : _d.getDefaultArkMethod()) === null || _e === void 0 ? void 0 : _e.getBody()) === null || _f === void 0 ? void 0 : _f.getLocals()) === null || _g === void 0 ? void 0 : _g.get(baseName)) !== null && _h !== void 0 ? _h : ModelUtils.getClassWithName(baseName, arkClass)) !== null && _j !== void 0 ? _j : ModelUtils.getNamespaceWithName(baseName, arkClass)) !== null && _k !== void 0 ? _k : (_l = ModelUtils.getDefaultClass(arkClass)) === null || _l === void 0 ? void 0 : _l.getMethodWithName(baseName)) !== null && _m !== void 0 ? _m : (_q = (_p = (_o = ModelUtils.getDefaultClass(arkClass)) === null || _o === void 0 ? void 0 : _o.getDefaultArkMethod()) === null || _p === void 0 ? void 0 : _p.getBody()) === null || _q === void 0 ? void 0 : _q.getAliasTypeByName(baseName)) !== null && _r !== void 0 ? _r : ModelUtils.getArkExportInImportInfoWithName(baseName, arkClass.getDeclaringArkFile());
393
- if (!arkModel && !arkClass.getDeclaringArkFile().getImportInfoBy(baseName)) {
394
- arkModel = arkClass.getDeclaringArkFile().getScene().getSdkGlobal(baseName);
395
- }
396
- return arkModel;
397
- }
398
- static findArkModelByRefName(refName, arkClass) {
399
- const singleNames = refName.split('.');
400
- let model = null;
401
- for (let i = 0; i < singleNames.length; i++) {
402
- if (model instanceof Local_1.Local || model instanceof ArkField_1.ArkField) {
403
- const type = model.getType();
404
- if (type instanceof Type_1.ClassType) {
405
- model = arkClass.getDeclaringArkFile().getScene().getClass(type.getClassSignature());
406
- }
407
- else if (type instanceof Type_1.AnnotationNamespaceType) {
408
- model = arkClass.getDeclaringArkFile().getScene().getNamespace(type.getNamespaceSignature());
409
- }
410
- }
411
- const name = singleNames[i].replace(/<(\w+)>/, ValueUtil_1.EMPTY_STRING);
412
- if (i === 0) {
413
- model = this.findArkModel(name, arkClass);
414
- }
415
- else if (model instanceof ArkClass_1.ArkClass) {
416
- model = this.findPropertyInClass(name, model);
417
- }
418
- else if (model instanceof ArkNamespace_1.ArkNamespace) {
419
- model = this.findPropertyInNamespace(name, model);
420
- }
421
- if (!model) {
422
- return null;
423
- }
424
- }
425
- return model;
426
- }
427
- static findArkModelBySignature(signature, scene) {
428
- var _a, _b, _c, _d, _e, _f;
429
- if (signature instanceof ArkSignature_1.ClassSignature) {
430
- return scene.getClass(signature);
431
- }
432
- else if (signature instanceof ArkSignature_1.NamespaceSignature) {
433
- return scene.getNamespace(signature);
434
- }
435
- else if (signature instanceof ArkSignature_1.MethodSignature) {
436
- return scene.getMethod(signature);
437
- }
438
- else if (signature instanceof ArkSignature_1.FieldSignature) {
439
- const declare = this.findArkModelBySignature(signature.getDeclaringSignature(), scene);
440
- if (declare instanceof ArkClass_1.ArkClass) {
441
- return this.findPropertyInClass(signature.getFieldName(), declare);
442
- }
443
- else if (declare instanceof ArkNamespace_1.ArkNamespace) {
444
- return this.findPropertyInNamespace(signature.getFieldName(), declare) || null;
445
- }
446
- return null;
447
- }
448
- else if (signature instanceof ArkSignature_1.LocalSignature) {
449
- const declare = scene.getMethod(signature.getDeclaringMethodSignature());
450
- return (_d = (_b = (_a = declare === null || declare === void 0 ? void 0 : declare.getBody()) === null || _a === void 0 ? void 0 : _a.getLocals().get(signature.getName())) !== null && _b !== void 0 ? _b : (_c = declare === null || declare === void 0 ? void 0 : declare.getBody()) === null || _c === void 0 ? void 0 : _c.getAliasTypeByName(signature.getName())) !== null && _d !== void 0 ? _d : null;
451
- }
452
- else if (signature instanceof ArkSignature_1.AliasTypeSignature) {
453
- const declare = scene.getMethod(signature.getDeclaringMethodSignature());
454
- return (_f = (_e = declare === null || declare === void 0 ? void 0 : declare.getBody()) === null || _e === void 0 ? void 0 : _e.getAliasTypeByName(signature.getName())) !== null && _f !== void 0 ? _f : null;
455
- }
456
- return null;
457
- }
458
- static parseArkBaseModel2Type(arkBaseModel) {
459
- if (arkBaseModel instanceof ArkClass_1.ArkClass) {
460
- return new Type_1.ClassType(arkBaseModel.getSignature(), arkBaseModel.getGenericsTypes());
461
- }
462
- else if (arkBaseModel instanceof ArkNamespace_1.ArkNamespace) {
463
- return Type_1.AnnotationNamespaceType.getInstance(arkBaseModel.getSignature());
464
- }
465
- else if (arkBaseModel instanceof ArkMethod_1.ArkMethod) {
466
- return new Type_1.FunctionType(arkBaseModel.getSignature());
467
- }
468
- else if (arkBaseModel instanceof ArkField_1.ArkField) {
469
- if (arkBaseModel.getType() instanceof Type_1.UnknownType || arkBaseModel.getType() instanceof Type_1.UnclearReferenceType) {
470
- return null;
471
- }
472
- return arkBaseModel.getType();
473
- }
474
- return null;
475
- }
476
- }
477
- exports.ModelUtils = ModelUtils;
478
- ModelUtils.implicitArkUIBuilderMethods = new Set();
479
- const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'ModelUtils');
480
- let moduleMap;
481
- const fileSuffixArray = ['.ets', '.ts', '.d.ets', '.d.ts'];
482
- exports.sdkImportMap = new Map();
483
- /**
484
- * find arkFile by from info
485
- * export xx from '../xx'
486
- * import xx from '@ohos/xx'
487
- * import xx from '@ohos.xx'
488
- * @param im importInfo or exportInfo
489
- */
490
- function getArkFile(im) {
491
- const from = im.getFrom();
492
- if (!from) {
493
- return null;
494
- }
495
- if (/^([^@]*\/)([^\/]*)$/.test(from)) { //relative path
496
- const parentPath = /^\.{1,2}\//.test(from) ? path_1.default.dirname(im.getDeclaringArkFile().getFilePath())
497
- : im.getDeclaringArkFile().getProjectDir();
498
- const originPath = path_1.default.resolve(parentPath, from);
499
- return getArkFileFromScene(im, originPath);
500
- }
501
- else if (/^@[a-z|\-]+?\//.test(from)) { //module path
502
- const arkFile = getArkFileFromOtherModule(im);
503
- if (arkFile) {
504
- return arkFile;
505
- }
506
- }
507
- //sdk path
508
- const file = exports.sdkImportMap.get(from);
509
- if (file) {
510
- return file;
511
- }
512
- const scene = im.getDeclaringArkFile().getScene();
513
- for (const sdk of scene.getProjectSdkMap().values()) {
514
- const arkFile = getArkFileFormMap(sdk.name, processSdkPath(sdk, from), scene);
515
- if (arkFile) {
516
- return arkFile;
517
- }
518
- }
519
- }
520
- exports.getArkFile = getArkFile;
521
- /**
522
- * find from info's export
523
- * @param fromInfo importInfo or exportInfo
524
- */
525
- function findExportInfo(fromInfo) {
526
- var _a, _b;
527
- let file = getArkFile(fromInfo);
528
- if (!file) {
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2024 Huawei Device Co., Ltd.
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ var desc = Object.getOwnPropertyDescriptor(m, k);
19
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
20
+ desc = { enumerable: true, get: function() { return m[k]; } };
21
+ }
22
+ Object.defineProperty(o, k2, desc);
23
+ }) : (function(o, m, k, k2) {
24
+ if (k2 === undefined) k2 = k;
25
+ o[k2] = m[k];
26
+ }));
27
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
28
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
29
+ }) : function(o, v) {
30
+ o["default"] = v;
31
+ });
32
+ var __importStar = (this && this.__importStar) || function (mod) {
33
+ if (mod && mod.__esModule) return mod;
34
+ var result = {};
35
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
36
+ __setModuleDefault(result, mod);
37
+ return result;
38
+ };
39
+ var __importDefault = (this && this.__importDefault) || function (mod) {
40
+ return (mod && mod.__esModule) ? mod : { "default": mod };
41
+ };
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ exports.initModulePathMap = exports.findArkExportInFile = exports.findArkExport = exports.findExportInfo = exports.getArkFile = exports.sdkImportMap = exports.ModelUtils = void 0;
44
+ const Local_1 = require("../base/Local");
45
+ const ArkClass_1 = require("../model/ArkClass");
46
+ const ArkMethod_1 = require("../model/ArkMethod");
47
+ const ArkNamespace_1 = require("../model/ArkNamespace");
48
+ const ArkSignature_1 = require("../model/ArkSignature");
49
+ const ArkExport_1 = require("../model/ArkExport");
50
+ const ArkField_1 = require("../model/ArkField");
51
+ const logger_1 = __importStar(require("../../utils/logger"));
52
+ const FileUtils_1 = require("../../utils/FileUtils");
53
+ const path_1 = __importDefault(require("path"));
54
+ const TSConst_1 = require("./TSConst");
55
+ const ArkExportBuilder_1 = require("../model/builder/ArkExportBuilder");
56
+ const Type_1 = require("../base/Type");
57
+ const Const_1 = require("./Const");
58
+ const ValueUtil_1 = require("./ValueUtil");
59
+ class ModelUtils {
60
+ static getMethodSignatureFromArkClass(arkClass, methodName) {
61
+ for (const arkMethod of arkClass.getMethods()) {
62
+ if (arkMethod.getName() === methodName) {
63
+ return arkMethod.getSignature();
64
+ }
65
+ }
66
+ return null;
67
+ }
68
+ static getClassWithNameInNamespaceRecursively(className, ns) {
69
+ if (className === '') {
70
+ return null;
71
+ }
72
+ let res = null;
73
+ res = ns.getClassWithName(className);
74
+ if (res == null) {
75
+ let declaringNs = ns.getDeclaringArkNamespace();
76
+ if (declaringNs != null) {
77
+ res = this.getClassWithNameInNamespaceRecursively(className, declaringNs);
78
+ }
79
+ else {
80
+ res = this.getClassInFileWithName(className, ns.getDeclaringArkFile());
81
+ }
82
+ }
83
+ return res;
84
+ }
85
+ static getClassWithNameFromClass(className, startFrom) {
86
+ if (!className.includes('.')) {
87
+ let res = null;
88
+ const arkNamespace = startFrom.getDeclaringArkNamespace();
89
+ if (arkNamespace) {
90
+ res = this.getClassWithNameInNamespaceRecursively(className, arkNamespace);
91
+ }
92
+ else {
93
+ res = this.getClassInFileWithName(className, startFrom.getDeclaringArkFile());
94
+ }
95
+ return res;
96
+ }
97
+ else {
98
+ const names = className.split('.');
99
+ let nameSpace = this.getNamespaceWithNameFromClass(names[0], startFrom);
100
+ for (let i = 1; i < names.length - 1; i++) {
101
+ if (nameSpace)
102
+ nameSpace = nameSpace.getNamespaceWithName(names[i]);
103
+ }
104
+ if (nameSpace) {
105
+ return nameSpace.getClassWithName(names[names.length - 1]);
106
+ }
107
+ }
108
+ return null;
109
+ }
110
+ /**
111
+ * search class within the file that contain the given method
112
+ */
113
+ static getClassWithName(className, thisClass) {
114
+ var _a;
115
+ if (thisClass.getName() === className) {
116
+ return thisClass;
117
+ }
118
+ let classSearched = (_a = thisClass.getDeclaringArkNamespace()) === null || _a === void 0 ? void 0 : _a.getClassWithName(className);
119
+ if (!classSearched) {
120
+ classSearched = thisClass.getDeclaringArkFile().getClassWithName(className);
121
+ }
122
+ return classSearched;
123
+ }
124
+ /** search class within the given file */
125
+ static getClassInFileWithName(className, arkFile) {
126
+ let classSearched = arkFile.getClassWithName(className);
127
+ if (classSearched != null) {
128
+ return classSearched;
129
+ }
130
+ return null;
131
+ }
132
+ static getClassInImportInfoWithName(className, arkFile) {
133
+ let arkExport = this.getArkExportInImportInfoWithName(className, arkFile);
134
+ if (arkExport instanceof ArkClass_1.ArkClass) {
135
+ return arkExport;
136
+ }
137
+ return null;
138
+ }
139
+ /** search type within the given file import infos */
140
+ static getArkExportInImportInfoWithName(name, arkFile) {
141
+ var _a, _b, _c;
142
+ return (_c = (_b = (_a = arkFile.getImportInfoBy(name)) === null || _a === void 0 ? void 0 : _a.getLazyExportInfo()) === null || _b === void 0 ? void 0 : _b.getArkExport()) !== null && _c !== void 0 ? _c : null;
143
+ }
144
+ /** search method within the file that contain the given method */
145
+ static getMethodWithName(methodName, startFrom) {
146
+ if (!methodName.includes('.')) {
147
+ if (startFrom.getName() === methodName) {
148
+ return startFrom;
149
+ }
150
+ const thisClass = startFrom.getDeclaringArkClass();
151
+ let methodSearched = thisClass.getMethodWithName(methodName);
152
+ if (!methodSearched) {
153
+ methodSearched = thisClass.getStaticMethodWithName(methodName);
154
+ }
155
+ return methodSearched;
156
+ }
157
+ else {
158
+ const names = methodName.split('.');
159
+ let nameSpace = this.getNamespaceWithName(names[0], startFrom.getDeclaringArkClass());
160
+ for (let i = 1; i < names.length - 1; i++) {
161
+ if (nameSpace) {
162
+ nameSpace = nameSpace.getNamespaceWithName(names[i]);
163
+ }
164
+ }
165
+ if (nameSpace) {
166
+ return nameSpace.getDefaultClass().getMethodWithName(names[names.length - 1]);
167
+ }
168
+ }
169
+ return null;
170
+ }
171
+ static getNamespaceWithNameFromClass(namespaceName, startFrom) {
172
+ const thisNamespace = startFrom.getDeclaringArkNamespace();
173
+ let namespaceSearched = null;
174
+ if (thisNamespace) {
175
+ namespaceSearched = thisNamespace.getNamespaceWithName(namespaceName);
176
+ if (namespaceSearched) {
177
+ return namespaceSearched;
178
+ }
179
+ }
180
+ const thisFile = startFrom.getDeclaringArkFile();
181
+ namespaceSearched = this.getNamespaceInFileWithName(namespaceName, thisFile);
182
+ return namespaceSearched;
183
+ }
184
+ static getNamespaceWithName(namespaceName, thisClass) {
185
+ let thisNamespace = thisClass.getDeclaringArkNamespace();
186
+ let namespaceSearched = null;
187
+ while (!namespaceSearched && thisNamespace) {
188
+ namespaceSearched = thisNamespace.getNamespaceWithName(namespaceName);
189
+ thisNamespace = thisNamespace.getDeclaringArkNamespace();
190
+ }
191
+ if (!namespaceSearched) {
192
+ namespaceSearched = thisClass.getDeclaringArkFile().getNamespaceWithName(namespaceName);
193
+ }
194
+ return namespaceSearched;
195
+ }
196
+ static getNamespaceInFileWithName(namespaceName, arkFile) {
197
+ let namespaceSearched = arkFile.getNamespaceWithName(namespaceName);
198
+ if (namespaceSearched) {
199
+ return namespaceSearched;
200
+ }
201
+ return null;
202
+ }
203
+ static getNamespaceInImportInfoWithName(namespaceName, arkFile) {
204
+ let arkExport = this.getArkExportInImportInfoWithName(namespaceName, arkFile);
205
+ if (arkExport instanceof ArkNamespace_1.ArkNamespace) {
206
+ return arkExport;
207
+ }
208
+ return null;
209
+ }
210
+ static getStaticMethodWithName(methodName, thisClass) {
211
+ const thisNamespace = thisClass.getDeclaringArkNamespace();
212
+ if (thisNamespace) {
213
+ const defaultClass = thisNamespace.getClassWithName(Const_1.DEFAULT_ARK_CLASS_NAME);
214
+ if (defaultClass) {
215
+ const method = defaultClass.getMethodWithName(methodName);
216
+ if (method) {
217
+ return method;
218
+ }
219
+ }
220
+ }
221
+ return this.getStaticMethodInFileWithName(methodName, thisClass.getDeclaringArkFile());
222
+ }
223
+ static getStaticMethodInFileWithName(methodName, arkFile) {
224
+ const defaultClass = arkFile.getClasses().find(cls => cls.getName() === Const_1.DEFAULT_ARK_CLASS_NAME) || null;
225
+ if (defaultClass) {
226
+ let method = defaultClass.getMethodWithName(methodName);
227
+ if (method) {
228
+ return method;
229
+ }
230
+ }
231
+ return null;
232
+ }
233
+ static getStaticMethodInImportInfoWithName(methodName, arkFile) {
234
+ let arkExport = this.getArkExportInImportInfoWithName(methodName, arkFile);
235
+ if (arkExport instanceof ArkMethod_1.ArkMethod) {
236
+ return arkExport;
237
+ }
238
+ return null;
239
+ }
240
+ static getLocalInImportInfoWithName(localName, arkFile) {
241
+ let arkExport = this.getArkExportInImportInfoWithName(localName, arkFile);
242
+ if (arkExport instanceof Local_1.Local) {
243
+ return arkExport;
244
+ }
245
+ return null;
246
+ }
247
+ /* get nested namespaces in a file */
248
+ static getAllNamespacesInFile(arkFile) {
249
+ const arkNamespaces = arkFile.getNamespaces();
250
+ for (const arkNamespace of arkFile.getNamespaces()) {
251
+ this.getAllNamespacesInNamespace(arkNamespace, arkNamespaces);
252
+ }
253
+ return arkNamespaces;
254
+ }
255
+ /* get nested namespaces in a namespace */
256
+ static getAllNamespacesInNamespace(arkNamespace, allNamespaces) {
257
+ allNamespaces.push(...arkNamespace.getNamespaces());
258
+ for (const nestedNamespace of arkNamespace.getNamespaces()) {
259
+ this.getAllNamespacesInNamespace(nestedNamespace, allNamespaces);
260
+ }
261
+ }
262
+ static getAllClassesInFile(arkFile) {
263
+ const allClasses = arkFile.getClasses();
264
+ this.getAllNamespacesInFile(arkFile).forEach((namespace) => {
265
+ allClasses.push(...namespace.getClasses());
266
+ });
267
+ return allClasses;
268
+ }
269
+ static getAllMethodsInFile(arkFile) {
270
+ const allMethods = [];
271
+ this.getAllClassesInFile(arkFile).forEach((cls) => {
272
+ allMethods.push(...cls.getMethods());
273
+ });
274
+ return allMethods;
275
+ }
276
+ static isArkUIBuilderMethod(arkMethod) {
277
+ let isArkUIBuilderMethod = arkMethod.hasBuilderDecorator() || this.implicitArkUIBuilderMethods.has(arkMethod);
278
+ if (!isArkUIBuilderMethod &&
279
+ arkMethod.getName() === 'build' &&
280
+ arkMethod.getDeclaringArkClass().hasComponentDecorator() &&
281
+ !arkMethod.isStatic()) {
282
+ const fileName = arkMethod.getDeclaringArkClass().getDeclaringArkFile().getName();
283
+ if (fileName.endsWith('.ets')) {
284
+ isArkUIBuilderMethod = true;
285
+ }
286
+ }
287
+ return isArkUIBuilderMethod;
288
+ }
289
+ static getArkClassInBuild(scene, classType) {
290
+ var _a;
291
+ const classSignature = classType.getClassSignature();
292
+ const file = scene.getFile(classSignature.getDeclaringFileSignature());
293
+ const namespaceSignature = classSignature.getDeclaringNamespaceSignature();
294
+ if (namespaceSignature) {
295
+ return ((_a = file === null || file === void 0 ? void 0 : file.getNamespace(namespaceSignature)) === null || _a === void 0 ? void 0 : _a.getClass(classSignature)) || null;
296
+ }
297
+ return (file === null || file === void 0 ? void 0 : file.getClassWithName(classSignature.getClassName())) || null;
298
+ }
299
+ static getDefaultClass(arkClass) {
300
+ var _a, _b;
301
+ return (_b = (_a = arkClass.getDeclaringArkNamespace()) === null || _a === void 0 ? void 0 : _a.getDefaultClass()) !== null && _b !== void 0 ? _b : arkClass.getDeclaringArkFile().getDefaultClass();
302
+ }
303
+ static getClass(method, signature) {
304
+ var _a;
305
+ let cls = method.getDeclaringArkFile().getScene().getClass(signature);
306
+ if (cls) {
307
+ return cls;
308
+ }
309
+ let importInfo = method.getDeclaringArkFile().getImportInfoBy(signature.getClassName());
310
+ let exportInfo = importInfo ? findExportInfo(importInfo) : null;
311
+ let arkExport = exportInfo === null || exportInfo === void 0 ? void 0 : exportInfo.getArkExport();
312
+ if (arkExport instanceof ArkClass_1.ArkClass) {
313
+ return arkExport;
314
+ }
315
+ cls = (_a = method.getDeclaringArkClass().getDeclaringArkNamespace()) === null || _a === void 0 ? void 0 : _a.getClassWithName(signature.getClassName());
316
+ if (cls) {
317
+ return cls;
318
+ }
319
+ for (const ns of method.getDeclaringArkFile().getAllNamespacesUnderThisFile()) {
320
+ cls = ns.getClassWithName(signature.getClassName());
321
+ if (cls) {
322
+ return cls;
323
+ }
324
+ }
325
+ return method.getDeclaringArkFile().getClassWithName(signature.getClassName());
326
+ }
327
+ static findPropertyInNamespace(name, namespace) {
328
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
329
+ return (_j = (_e = (_d = (_c = (_b = (_a = namespace.getDefaultClass()) === null || _a === void 0 ? void 0 : _a.getMethodWithName(name)) !== null && _b !== void 0 ? _b : findArkExport(namespace.getExportInfoBy(name))) !== null && _c !== void 0 ? _c : namespace.getClassWithName(name)) !== null && _d !== void 0 ? _d : namespace.getNamespaceWithName(name)) !== null && _e !== void 0 ? _e : (_h = (_g = (_f = namespace.getDefaultClass()) === null || _f === void 0 ? void 0 : _f.getDefaultArkMethod()) === null || _g === void 0 ? void 0 : _g.getBody()) === null || _h === void 0 ? void 0 : _h.getAliasTypeByName(name)) !== null && _j !== void 0 ? _j : (_o = (_m = (_l = (_k = namespace.getDefaultClass()) === null || _k === void 0 ? void 0 : _k.getDefaultArkMethod()) === null || _l === void 0 ? void 0 : _l.getBody()) === null || _m === void 0 ? void 0 : _m.getLocals()) === null || _o === void 0 ? void 0 : _o.get(name);
330
+ }
331
+ static findPropertyInClass(name, arkClass) {
332
+ var _a, _b, _c;
333
+ let property = (_c = (_b = (_a = arkClass.getMethodWithName(name)) !== null && _a !== void 0 ? _a : arkClass.getStaticMethodWithName(name)) !== null && _b !== void 0 ? _b : arkClass.getFieldWithName(name)) !== null && _c !== void 0 ? _c : arkClass.getStaticFieldWithName(name);
334
+ if (property) {
335
+ return property;
336
+ }
337
+ if (arkClass.isDefaultArkClass()) {
338
+ return findArkExport(arkClass.getDeclaringArkFile().getExportInfoBy(name));
339
+ }
340
+ for (const heritage of arkClass.getAllHeritageClasses()) {
341
+ property = this.findPropertyInClass(name, heritage);
342
+ if (property) {
343
+ return property;
344
+ }
345
+ }
346
+ return null;
347
+ }
348
+ static findDeclaredLocal(local, arkMethod, times = 0) {
349
+ var _a, _b, _c;
350
+ if (arkMethod.getDeclaringArkFile().getScene().getOptions().isScanAbc) {
351
+ return null;
352
+ }
353
+ const name = local.getName();
354
+ if (name === TSConst_1.THIS_NAME || name.startsWith(Const_1.TEMP_LOCAL_PREFIX)) {
355
+ return null;
356
+ }
357
+ if (times > 0) {
358
+ const parameter = arkMethod.getParameters().find(p => p.getName() === name);
359
+ if (parameter) {
360
+ return new Local_1.Local(parameter.getName(), parameter.getType());
361
+ }
362
+ const declaredLocal = (_a = arkMethod.getBody()) === null || _a === void 0 ? void 0 : _a.getLocals().get(name);
363
+ if (declaredLocal && declaredLocal.getDeclaringStmt()) {
364
+ return declaredLocal;
365
+ }
366
+ }
367
+ let parentName = arkMethod.getName();
368
+ if (parentName === Const_1.DEFAULT_ARK_METHOD_NAME) {
369
+ return null;
370
+ }
371
+ const start = parentName.indexOf(Const_1.NAME_DELIMITER);
372
+ let invokeMethod;
373
+ if (start < 0) {
374
+ const cls = arkMethod.getDeclaringArkClass();
375
+ invokeMethod = (_b = cls.getDefaultArkMethod()) !== null && _b !== void 0 ? _b : (_c = cls.getDeclaringArkFile().getDefaultClass()) === null || _c === void 0 ? void 0 : _c.getDefaultArkMethod();
376
+ }
377
+ else {
378
+ parentName = parentName.substring(start + 1);
379
+ invokeMethod = arkMethod.getDeclaringArkClass().getMethodWithName(parentName);
380
+ }
381
+ if (invokeMethod) {
382
+ return this.findDeclaredLocal(local, invokeMethod, ++times);
383
+ }
384
+ return null;
385
+ }
386
+ static findArkModel(baseName, arkClass) {
387
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
388
+ let arkModel = (_c = (_b = (_a = arkClass.getMethodWithName(baseName)) !== null && _a !== void 0 ? _a : arkClass.getStaticMethodWithName(baseName)) !== null && _b !== void 0 ? _b : arkClass.getFieldWithName(baseName)) !== null && _c !== void 0 ? _c : arkClass.getStaticFieldWithName(baseName);
389
+ if (arkModel) {
390
+ return arkModel;
391
+ }
392
+ arkModel = (_r = (_m = (_k = (_j = (_h = (_g = (_f = (_e = (_d = ModelUtils.getDefaultClass(arkClass)) === null || _d === void 0 ? void 0 : _d.getDefaultArkMethod()) === null || _e === void 0 ? void 0 : _e.getBody()) === null || _f === void 0 ? void 0 : _f.getLocals()) === null || _g === void 0 ? void 0 : _g.get(baseName)) !== null && _h !== void 0 ? _h : ModelUtils.getClassWithName(baseName, arkClass)) !== null && _j !== void 0 ? _j : ModelUtils.getNamespaceWithName(baseName, arkClass)) !== null && _k !== void 0 ? _k : (_l = ModelUtils.getDefaultClass(arkClass)) === null || _l === void 0 ? void 0 : _l.getMethodWithName(baseName)) !== null && _m !== void 0 ? _m : (_q = (_p = (_o = ModelUtils.getDefaultClass(arkClass)) === null || _o === void 0 ? void 0 : _o.getDefaultArkMethod()) === null || _p === void 0 ? void 0 : _p.getBody()) === null || _q === void 0 ? void 0 : _q.getAliasTypeByName(baseName)) !== null && _r !== void 0 ? _r : ModelUtils.getArkExportInImportInfoWithName(baseName, arkClass.getDeclaringArkFile());
393
+ if (!arkModel && !arkClass.getDeclaringArkFile().getImportInfoBy(baseName)) {
394
+ arkModel = arkClass.getDeclaringArkFile().getScene().getSdkGlobal(baseName);
395
+ }
396
+ return arkModel;
397
+ }
398
+ static findArkModelByRefName(refName, arkClass) {
399
+ const singleNames = refName.split('.');
400
+ let model = null;
401
+ for (let i = 0; i < singleNames.length; i++) {
402
+ if (model instanceof Local_1.Local || model instanceof ArkField_1.ArkField) {
403
+ const type = model.getType();
404
+ if (type instanceof Type_1.ClassType) {
405
+ model = arkClass.getDeclaringArkFile().getScene().getClass(type.getClassSignature());
406
+ }
407
+ else if (type instanceof Type_1.AnnotationNamespaceType) {
408
+ model = arkClass.getDeclaringArkFile().getScene().getNamespace(type.getNamespaceSignature());
409
+ }
410
+ }
411
+ const name = singleNames[i].replace(/<(\w+)>/, ValueUtil_1.EMPTY_STRING);
412
+ if (i === 0) {
413
+ model = this.findArkModel(name, arkClass);
414
+ }
415
+ else if (model instanceof ArkClass_1.ArkClass) {
416
+ model = this.findPropertyInClass(name, model);
417
+ }
418
+ else if (model instanceof ArkNamespace_1.ArkNamespace) {
419
+ model = this.findPropertyInNamespace(name, model);
420
+ }
421
+ if (!model) {
422
+ return null;
423
+ }
424
+ }
425
+ return model;
426
+ }
427
+ static findArkModelBySignature(signature, scene) {
428
+ var _a, _b, _c, _d, _e, _f;
429
+ if (signature instanceof ArkSignature_1.ClassSignature) {
430
+ return scene.getClass(signature);
431
+ }
432
+ else if (signature instanceof ArkSignature_1.NamespaceSignature) {
433
+ return scene.getNamespace(signature);
434
+ }
435
+ else if (signature instanceof ArkSignature_1.MethodSignature) {
436
+ return scene.getMethod(signature);
437
+ }
438
+ else if (signature instanceof ArkSignature_1.FieldSignature) {
439
+ const declare = this.findArkModelBySignature(signature.getDeclaringSignature(), scene);
440
+ if (declare instanceof ArkClass_1.ArkClass) {
441
+ return this.findPropertyInClass(signature.getFieldName(), declare);
442
+ }
443
+ else if (declare instanceof ArkNamespace_1.ArkNamespace) {
444
+ return this.findPropertyInNamespace(signature.getFieldName(), declare) || null;
445
+ }
446
+ return null;
447
+ }
448
+ else if (signature instanceof ArkSignature_1.LocalSignature) {
449
+ const declare = scene.getMethod(signature.getDeclaringMethodSignature());
450
+ return (_d = (_b = (_a = declare === null || declare === void 0 ? void 0 : declare.getBody()) === null || _a === void 0 ? void 0 : _a.getLocals().get(signature.getName())) !== null && _b !== void 0 ? _b : (_c = declare === null || declare === void 0 ? void 0 : declare.getBody()) === null || _c === void 0 ? void 0 : _c.getAliasTypeByName(signature.getName())) !== null && _d !== void 0 ? _d : null;
451
+ }
452
+ else if (signature instanceof ArkSignature_1.AliasTypeSignature) {
453
+ const declare = scene.getMethod(signature.getDeclaringMethodSignature());
454
+ return (_f = (_e = declare === null || declare === void 0 ? void 0 : declare.getBody()) === null || _e === void 0 ? void 0 : _e.getAliasTypeByName(signature.getName())) !== null && _f !== void 0 ? _f : null;
455
+ }
456
+ return null;
457
+ }
458
+ static parseArkBaseModel2Type(arkBaseModel) {
459
+ if (arkBaseModel instanceof ArkClass_1.ArkClass) {
460
+ return new Type_1.ClassType(arkBaseModel.getSignature(), arkBaseModel.getGenericsTypes());
461
+ }
462
+ else if (arkBaseModel instanceof ArkNamespace_1.ArkNamespace) {
463
+ return Type_1.AnnotationNamespaceType.getInstance(arkBaseModel.getSignature());
464
+ }
465
+ else if (arkBaseModel instanceof ArkMethod_1.ArkMethod) {
466
+ return new Type_1.FunctionType(arkBaseModel.getSignature());
467
+ }
468
+ else if (arkBaseModel instanceof ArkField_1.ArkField) {
469
+ if (arkBaseModel.getType() instanceof Type_1.UnknownType || arkBaseModel.getType() instanceof Type_1.UnclearReferenceType) {
470
+ return null;
471
+ }
472
+ return arkBaseModel.getType();
473
+ }
474
+ return null;
475
+ }
476
+ }
477
+ exports.ModelUtils = ModelUtils;
478
+ ModelUtils.implicitArkUIBuilderMethods = new Set();
479
+ const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'ModelUtils');
480
+ let moduleMap;
481
+ const fileSuffixArray = ['.ets', '.ts', '.d.ets', '.d.ts'];
482
+ exports.sdkImportMap = new Map();
483
+ /**
484
+ * find arkFile by from info
485
+ * export xx from '../xx'
486
+ * import xx from '@ohos/xx'
487
+ * import xx from '@ohos.xx'
488
+ * @param im importInfo or exportInfo
489
+ */
490
+ function getArkFile(im) {
491
+ const from = im.getFrom();
492
+ if (!from) {
493
+ return null;
494
+ }
495
+ if (/^([^@]*\/)([^\/]*)$/.test(from)) { //relative path
496
+ const parentPath = /^\.{1,2}\//.test(from) ? path_1.default.dirname(im.getDeclaringArkFile().getFilePath())
497
+ : im.getDeclaringArkFile().getProjectDir();
498
+ const originPath = path_1.default.resolve(parentPath, from);
499
+ return getArkFileFromScene(im, originPath);
500
+ }
501
+ else if (/^@[a-z|\-]+?\//.test(from)) { //module path
502
+ const arkFile = getArkFileFromOtherModule(im);
503
+ if (arkFile) {
504
+ return arkFile;
505
+ }
506
+ }
507
+ //sdk path
508
+ const file = exports.sdkImportMap.get(from);
509
+ if (file) {
510
+ return file;
511
+ }
512
+ const scene = im.getDeclaringArkFile().getScene();
513
+ for (const sdk of scene.getProjectSdkMap().values()) {
514
+ const arkFile = getArkFileFormMap(sdk.name, processSdkPath(sdk, from), scene);
515
+ if (arkFile) {
516
+ return arkFile;
517
+ }
518
+ }
519
+ }
520
+ exports.getArkFile = getArkFile;
521
+ /**
522
+ * find from info's export
523
+ * @param fromInfo importInfo or exportInfo
524
+ */
525
+ function findExportInfo(fromInfo) {
526
+ var _a, _b;
527
+ let file = getArkFile(fromInfo);
528
+ if (!file) {
529
529
  logger.warn(`${fromInfo.getOriginName()} ${fromInfo.getFrom()} file not found:
530
- ${(_b = (_a = fromInfo.getDeclaringArkFile()) === null || _a === void 0 ? void 0 : _a.getFileSignature()) === null || _b === void 0 ? void 0 : _b.toString()}`);
531
- return null;
532
- }
533
- if ((0, ArkSignature_1.fileSignatureCompare)(file.getFileSignature(), fromInfo.getDeclaringArkFile().getFileSignature())) {
534
- for (let exportInfo of file.getExportInfos()) {
535
- if (exportInfo.getOriginName() === fromInfo.getOriginName()) {
536
- exportInfo.setArkExport(file.getDefaultClass());
537
- return exportInfo;
538
- }
539
- }
540
- return null;
541
- }
542
- let exportInfo = findExportInfoInfile(fromInfo, file) || null;
543
- if (exportInfo === null) {
544
- logger.warn('export info not found, ' + fromInfo.getFrom() + ' in file: '
545
- + fromInfo.getDeclaringArkFile().getFileSignature().toString());
546
- return null;
547
- }
548
- const arkExport = findArkExport(exportInfo);
549
- exportInfo.setArkExport(arkExport);
550
- if (arkExport) {
551
- exportInfo.setExportClauseType(arkExport.getExportType());
552
- }
553
- return exportInfo;
554
- }
555
- exports.findExportInfo = findExportInfo;
556
- function findArkExport(exportInfo) {
557
- var _a, _b, _c, _d;
558
- if (!exportInfo) {
559
- return null;
560
- }
561
- let arkExport = exportInfo.getArkExport();
562
- if (arkExport || arkExport === null) {
563
- return arkExport;
564
- }
565
- if (!exportInfo.getFrom()) {
566
- const name = exportInfo.getOriginName();
567
- if (exportInfo.getExportClauseType() === ArkExport_1.ExportType.LOCAL) {
568
- arkExport = ((_b = (_a = exportInfo.getDeclaringArkFile().getDefaultClass().getDefaultArkMethod()) === null || _a === void 0 ? void 0 : _a.getBody()) === null || _b === void 0 ? void 0 : _b.getLocals().get(name)) || null;
569
- }
570
- else if (exportInfo.getExportClauseType() === ArkExport_1.ExportType.TYPE) {
571
- arkExport = ((_d = (_c = exportInfo.getDeclaringArkFile().getDefaultClass().getDefaultArkMethod()) === null || _c === void 0 ? void 0 : _c.getBody()) === null || _d === void 0 ? void 0 : _d.getAliasTypeByName(name)) || null;
572
- }
573
- else {
574
- arkExport = findArkExportInFile(name, exportInfo.getDeclaringArkFile());
575
- }
576
- }
577
- else if (exportInfo.getExportClauseType() === ArkExport_1.ExportType.UNKNOWN) {
578
- const result = findExportInfo(exportInfo);
579
- if (result) {
580
- arkExport = result.getArkExport() || null;
581
- }
582
- }
583
- if (!arkExport) {
530
+ ${(_b = (_a = fromInfo.getDeclaringArkFile()) === null || _a === void 0 ? void 0 : _a.getFileSignature()) === null || _b === void 0 ? void 0 : _b.toString()}`);
531
+ return null;
532
+ }
533
+ if ((0, ArkSignature_1.fileSignatureCompare)(file.getFileSignature(), fromInfo.getDeclaringArkFile().getFileSignature())) {
534
+ for (let exportInfo of file.getExportInfos()) {
535
+ if (exportInfo.getOriginName() === fromInfo.getOriginName()) {
536
+ exportInfo.setArkExport(file.getDefaultClass());
537
+ return exportInfo;
538
+ }
539
+ }
540
+ return null;
541
+ }
542
+ let exportInfo = findExportInfoInfile(fromInfo, file) || null;
543
+ if (exportInfo === null) {
544
+ logger.warn('export info not found, ' + fromInfo.getFrom() + ' in file: '
545
+ + fromInfo.getDeclaringArkFile().getFileSignature().toString());
546
+ return null;
547
+ }
548
+ const arkExport = findArkExport(exportInfo);
549
+ exportInfo.setArkExport(arkExport);
550
+ if (arkExport) {
551
+ exportInfo.setExportClauseType(arkExport.getExportType());
552
+ }
553
+ return exportInfo;
554
+ }
555
+ exports.findExportInfo = findExportInfo;
556
+ function findArkExport(exportInfo) {
557
+ var _a, _b, _c, _d;
558
+ if (!exportInfo) {
559
+ return null;
560
+ }
561
+ let arkExport = exportInfo.getArkExport();
562
+ if (arkExport || arkExport === null) {
563
+ return arkExport;
564
+ }
565
+ if (!exportInfo.getFrom()) {
566
+ const name = exportInfo.getOriginName();
567
+ if (exportInfo.getExportClauseType() === ArkExport_1.ExportType.LOCAL) {
568
+ arkExport = ((_b = (_a = exportInfo.getDeclaringArkFile().getDefaultClass().getDefaultArkMethod()) === null || _a === void 0 ? void 0 : _a.getBody()) === null || _b === void 0 ? void 0 : _b.getLocals().get(name)) || null;
569
+ }
570
+ else if (exportInfo.getExportClauseType() === ArkExport_1.ExportType.TYPE) {
571
+ arkExport = ((_d = (_c = exportInfo.getDeclaringArkFile().getDefaultClass().getDefaultArkMethod()) === null || _c === void 0 ? void 0 : _c.getBody()) === null || _d === void 0 ? void 0 : _d.getAliasTypeByName(name)) || null;
572
+ }
573
+ else {
574
+ arkExport = findArkExportInFile(name, exportInfo.getDeclaringArkFile());
575
+ }
576
+ }
577
+ else if (exportInfo.getExportClauseType() === ArkExport_1.ExportType.UNKNOWN) {
578
+ const result = findExportInfo(exportInfo);
579
+ if (result) {
580
+ arkExport = result.getArkExport() || null;
581
+ }
582
+ }
583
+ if (!arkExport) {
584
584
  logger.warn(`${exportInfo.getExportClauseName()} get arkExport fail from ${exportInfo.getFrom()} at
585
- ${exportInfo.getDeclaringArkFile().getFileSignature().toString()}`);
586
- }
587
- return arkExport || null;
588
- }
589
- exports.findArkExport = findArkExport;
590
- function findArkExportInFile(name, declaringArkFile) {
591
- var _a, _b, _c, _d, _e, _f, _g, _h;
592
- let arkExport = (_f = (_e = (_d = (_a = declaringArkFile.getNamespaceWithName(name)) !== null && _a !== void 0 ? _a : (_c = (_b = declaringArkFile.getDefaultClass().getDefaultArkMethod()) === null || _b === void 0 ? void 0 : _b.getBody()) === null || _c === void 0 ? void 0 : _c.getAliasTypeByName(name)) !== null && _d !== void 0 ? _d : declaringArkFile.getClassWithName(name)) !== null && _e !== void 0 ? _e : declaringArkFile.getDefaultClass().getMethodWithName(name)) !== null && _f !== void 0 ? _f : (_h = (_g = declaringArkFile.getDefaultClass().getDefaultArkMethod()) === null || _g === void 0 ? void 0 : _g.getBody()) === null || _h === void 0 ? void 0 : _h.getLocals().get(name);
593
- if (!arkExport) {
594
- const importInfo = declaringArkFile.getImportInfoBy(name);
595
- if (importInfo) {
596
- const result = findExportInfo(importInfo);
597
- if (result) {
598
- arkExport = result.getArkExport();
599
- }
600
- }
601
- }
602
- return arkExport || null;
603
- }
604
- exports.findArkExportInFile = findArkExportInFile;
605
- function processSdkPath(sdk, formPath) {
606
- let originPath = path_1.default.join(sdk.path, formPath);
607
- if (FileUtils_1.FileUtils.isDirectory(originPath)) {
608
- formPath = path_1.default.join(formPath, FileUtils_1.FileUtils.getIndexFileName(originPath));
609
- }
610
- return `${formPath}`;
611
- }
612
- function getArkFileFromScene(im, originPath) {
613
- if (FileUtils_1.FileUtils.isDirectory(originPath)) {
614
- originPath = path_1.default.join(originPath, FileUtils_1.FileUtils.getIndexFileName(originPath));
615
- }
616
- const fileName = path_1.default.relative(im.getDeclaringArkFile().getProjectDir(), originPath);
617
- const scene = im.getDeclaringArkFile().getScene();
618
- if (/\.e?ts$/.test(originPath)) {
619
- const fromSignature = new ArkSignature_1.FileSignature(im.getDeclaringArkFile().getProjectName(), fileName);
620
- return scene.getFile(fromSignature);
621
- }
622
- const projectName = im.getDeclaringArkFile().getProjectName();
623
- return getArkFileFormMap(projectName, fileName, scene);
624
- }
625
- function getArkFileFormMap(projectName, filePath, scene) {
626
- if (/\.e?ts$/.test(filePath)) {
627
- return scene.getFile(new ArkSignature_1.FileSignature(projectName, filePath));
628
- }
629
- for (const suffix of fileSuffixArray) {
630
- const arkFile = scene.getFile(new ArkSignature_1.FileSignature(projectName, filePath + suffix));
631
- if (arkFile) {
632
- return arkFile;
633
- }
634
- }
635
- return null;
636
- }
637
- function findExportInfoInfile(fromInfo, file) {
638
- const exportName = fromInfo.isDefault() ? TSConst_1.DEFAULT : fromInfo.getOriginName();
639
- let exportInfo = file.getExportInfoBy(exportName);
640
- if (exportInfo) {
641
- return exportInfo;
642
- }
643
- if (exportName === TSConst_1.DEFAULT) {
644
- exportInfo = file.getExportInfos().find(p => p.isDefault());
645
- if (exportInfo) {
646
- file.addExportInfo(exportInfo, TSConst_1.DEFAULT);
647
- return exportInfo;
648
- }
649
- }
650
- if (fromInfo.getOriginName() === TSConst_1.ALL) {
651
- exportInfo = (0, ArkExportBuilder_1.buildDefaultExportInfo)(fromInfo, file);
652
- file.addExportInfo(exportInfo, TSConst_1.ALL);
653
- }
654
- else if (/\.d\.e?ts$/.test(file.getName())) {
655
- let declare = exportName === TSConst_1.DEFAULT ? undefined
656
- : findArkExportInFile(fromInfo.getOriginName(), file) || undefined;
657
- exportInfo = (0, ArkExportBuilder_1.buildDefaultExportInfo)(fromInfo, file, declare);
658
- }
659
- return exportInfo;
660
- }
661
- function initModulePathMap(ohPkgContentMap) {
662
- if (moduleMap) {
663
- moduleMap.clear();
664
- }
665
- moduleMap = FileUtils_1.FileUtils.generateModuleMap(ohPkgContentMap);
666
- }
667
- exports.initModulePathMap = initModulePathMap;
668
- function getArkFileFromOtherModule(fromInfo) {
669
- if (!moduleMap || moduleMap.size === 0) {
670
- return;
671
- }
672
- const from = fromInfo.getFrom();
673
- let index;
674
- let file;
675
- let modulePath;
676
- //find file by given from like '@ohos/module/src/xxx' '@ohos/module/index'
677
- if ((index = from.indexOf('src')) > 0 || (index = from.indexOf('Index')) > 0 || (index = from.indexOf('index')) > 0) {
678
- modulePath = moduleMap.get(from.substring(0, index).replace(/\/*$/, ''));
679
- file = findFileInModule(fromInfo, modulePath, from.substring(index));
680
- }
681
- if (file) {
682
- return file;
683
- }
684
- modulePath = modulePath !== null && modulePath !== void 0 ? modulePath : moduleMap.get(from);
685
- if (!modulePath) {
686
- return file;
687
- }
688
- //find file in module json main path
689
- if (modulePath.main) {
690
- file = getArkFileFromScene(fromInfo, modulePath.main);
691
- }
692
- //find file in module path Index.ts
693
- if (!file && FileUtils_1.FileUtils.isDirectory(modulePath.path)) {
694
- file = findFileInModule(fromInfo, modulePath, FileUtils_1.FileUtils.getIndexFileName(modulePath.path));
695
- }
696
- //find file in module path/src/main/ets/TsIndex.ts
697
- if (!file) {
698
- file = findFileInModule(fromInfo, modulePath, '/src/main/ets/TsIndex.ts');
699
- }
700
- return file;
701
- }
702
- function findFileInModule(fromInfo, modulePath, contentPath) {
703
- if (!modulePath) {
704
- return;
705
- }
706
- const originPath = path_1.default.join(modulePath.path, contentPath);
707
- let file;
708
- if (originPath !== modulePath.main) {
709
- file = getArkFileFromScene(fromInfo, originPath);
710
- }
711
- if (file && findExportInfoInfile(fromInfo, file)) {
712
- return file;
713
- }
714
- }
585
+ ${exportInfo.getDeclaringArkFile().getFileSignature().toString()}`);
586
+ }
587
+ return arkExport || null;
588
+ }
589
+ exports.findArkExport = findArkExport;
590
+ function findArkExportInFile(name, declaringArkFile) {
591
+ var _a, _b, _c, _d, _e, _f, _g, _h;
592
+ let arkExport = (_f = (_e = (_d = (_a = declaringArkFile.getNamespaceWithName(name)) !== null && _a !== void 0 ? _a : (_c = (_b = declaringArkFile.getDefaultClass().getDefaultArkMethod()) === null || _b === void 0 ? void 0 : _b.getBody()) === null || _c === void 0 ? void 0 : _c.getAliasTypeByName(name)) !== null && _d !== void 0 ? _d : declaringArkFile.getClassWithName(name)) !== null && _e !== void 0 ? _e : declaringArkFile.getDefaultClass().getMethodWithName(name)) !== null && _f !== void 0 ? _f : (_h = (_g = declaringArkFile.getDefaultClass().getDefaultArkMethod()) === null || _g === void 0 ? void 0 : _g.getBody()) === null || _h === void 0 ? void 0 : _h.getLocals().get(name);
593
+ if (!arkExport) {
594
+ const importInfo = declaringArkFile.getImportInfoBy(name);
595
+ if (importInfo) {
596
+ const result = findExportInfo(importInfo);
597
+ if (result) {
598
+ arkExport = result.getArkExport();
599
+ }
600
+ }
601
+ }
602
+ return arkExport || null;
603
+ }
604
+ exports.findArkExportInFile = findArkExportInFile;
605
+ function processSdkPath(sdk, formPath) {
606
+ let originPath = path_1.default.join(sdk.path, formPath);
607
+ if (FileUtils_1.FileUtils.isDirectory(originPath)) {
608
+ formPath = path_1.default.join(formPath, FileUtils_1.FileUtils.getIndexFileName(originPath));
609
+ }
610
+ return `${formPath}`;
611
+ }
612
+ function getArkFileFromScene(im, originPath) {
613
+ if (FileUtils_1.FileUtils.isDirectory(originPath)) {
614
+ originPath = path_1.default.join(originPath, FileUtils_1.FileUtils.getIndexFileName(originPath));
615
+ }
616
+ const fileName = path_1.default.relative(im.getDeclaringArkFile().getProjectDir(), originPath);
617
+ const scene = im.getDeclaringArkFile().getScene();
618
+ if (/\.e?ts$/.test(originPath)) {
619
+ const fromSignature = new ArkSignature_1.FileSignature(im.getDeclaringArkFile().getProjectName(), fileName);
620
+ return scene.getFile(fromSignature);
621
+ }
622
+ const projectName = im.getDeclaringArkFile().getProjectName();
623
+ return getArkFileFormMap(projectName, fileName, scene);
624
+ }
625
+ function getArkFileFormMap(projectName, filePath, scene) {
626
+ if (/\.e?ts$/.test(filePath)) {
627
+ return scene.getFile(new ArkSignature_1.FileSignature(projectName, filePath));
628
+ }
629
+ for (const suffix of fileSuffixArray) {
630
+ const arkFile = scene.getFile(new ArkSignature_1.FileSignature(projectName, filePath + suffix));
631
+ if (arkFile) {
632
+ return arkFile;
633
+ }
634
+ }
635
+ return null;
636
+ }
637
+ function findExportInfoInfile(fromInfo, file) {
638
+ const exportName = fromInfo.isDefault() ? TSConst_1.DEFAULT : fromInfo.getOriginName();
639
+ let exportInfo = file.getExportInfoBy(exportName);
640
+ if (exportInfo) {
641
+ return exportInfo;
642
+ }
643
+ if (exportName === TSConst_1.DEFAULT) {
644
+ exportInfo = file.getExportInfos().find(p => p.isDefault());
645
+ if (exportInfo) {
646
+ file.addExportInfo(exportInfo, TSConst_1.DEFAULT);
647
+ return exportInfo;
648
+ }
649
+ }
650
+ if (fromInfo.getOriginName() === TSConst_1.ALL) {
651
+ exportInfo = (0, ArkExportBuilder_1.buildDefaultExportInfo)(fromInfo, file);
652
+ file.addExportInfo(exportInfo, TSConst_1.ALL);
653
+ }
654
+ else if (/\.d\.e?ts$/.test(file.getName())) {
655
+ let declare = exportName === TSConst_1.DEFAULT ? undefined
656
+ : findArkExportInFile(fromInfo.getOriginName(), file) || undefined;
657
+ exportInfo = (0, ArkExportBuilder_1.buildDefaultExportInfo)(fromInfo, file, declare);
658
+ }
659
+ return exportInfo;
660
+ }
661
+ function initModulePathMap(ohPkgContentMap) {
662
+ if (moduleMap) {
663
+ moduleMap.clear();
664
+ }
665
+ moduleMap = FileUtils_1.FileUtils.generateModuleMap(ohPkgContentMap);
666
+ }
667
+ exports.initModulePathMap = initModulePathMap;
668
+ function getArkFileFromOtherModule(fromInfo) {
669
+ if (!moduleMap || moduleMap.size === 0) {
670
+ return;
671
+ }
672
+ const from = fromInfo.getFrom();
673
+ let index;
674
+ let file;
675
+ let modulePath;
676
+ //find file by given from like '@ohos/module/src/xxx' '@ohos/module/index'
677
+ if ((index = from.indexOf('src')) > 0 || (index = from.indexOf('Index')) > 0 || (index = from.indexOf('index')) > 0) {
678
+ modulePath = moduleMap.get(from.substring(0, index).replace(/\/*$/, ''));
679
+ file = findFileInModule(fromInfo, modulePath, from.substring(index));
680
+ }
681
+ if (file) {
682
+ return file;
683
+ }
684
+ modulePath = modulePath !== null && modulePath !== void 0 ? modulePath : moduleMap.get(from);
685
+ if (!modulePath) {
686
+ return file;
687
+ }
688
+ //find file in module json main path
689
+ if (modulePath.main) {
690
+ file = getArkFileFromScene(fromInfo, modulePath.main);
691
+ }
692
+ //find file in module path Index.ts
693
+ if (!file && FileUtils_1.FileUtils.isDirectory(modulePath.path)) {
694
+ file = findFileInModule(fromInfo, modulePath, FileUtils_1.FileUtils.getIndexFileName(modulePath.path));
695
+ }
696
+ //find file in module path/src/main/ets/TsIndex.ts
697
+ if (!file) {
698
+ file = findFileInModule(fromInfo, modulePath, '/src/main/ets/TsIndex.ts');
699
+ }
700
+ return file;
701
+ }
702
+ function findFileInModule(fromInfo, modulePath, contentPath) {
703
+ if (!modulePath) {
704
+ return;
705
+ }
706
+ const originPath = path_1.default.join(modulePath.path, contentPath);
707
+ let file;
708
+ if (originPath !== modulePath.main) {
709
+ file = getArkFileFromScene(fromInfo, originPath);
710
+ }
711
+ if (file && findExportInfoInfile(fromInfo, file)) {
712
+ return file;
713
+ }
714
+ }