@hadss/turbo-trans-json-plugin 1.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +177 -0
- package/README.md +253 -0
- package/dist/core/Types.d.ts +196 -0
- package/dist/core/Types.js +47 -0
- package/dist/core/analyzers/ClassAnalyzer.d.ts +23 -0
- package/dist/core/analyzers/ClassAnalyzer.js +480 -0
- package/dist/core/analyzers/CustomTypeAnalyzer.d.ts +21 -0
- package/dist/core/analyzers/CustomTypeAnalyzer.js +243 -0
- package/dist/core/analyzers/SendableMergeChecker.d.ts +9 -0
- package/dist/core/analyzers/SendableMergeChecker.js +100 -0
- package/dist/core/analyzers/SendableMergeabilityRegistry.d.ts +7 -0
- package/dist/core/analyzers/SendableMergeabilityRegistry.js +23 -0
- package/dist/core/constants/DecoratorConstants.d.ts +7 -0
- package/dist/core/constants/DecoratorConstants.js +13 -0
- package/dist/core/constants/PathConstants.d.ts +6 -0
- package/dist/core/constants/PathConstants.js +10 -0
- package/dist/core/constants/StringConstants.d.ts +83 -0
- package/dist/core/constants/StringConstants.js +87 -0
- package/dist/core/constants/index.d.ts +3 -0
- package/dist/core/constants/index.js +19 -0
- package/dist/core/handlers/BaseTypeHandler.d.ts +23 -0
- package/dist/core/handlers/BaseTypeHandler.js +57 -0
- package/dist/core/handlers/CustomClassHandler.d.ts +21 -0
- package/dist/core/handlers/CustomClassHandler.js +191 -0
- package/dist/core/handlers/DateHandler.d.ts +2 -0
- package/dist/core/handlers/DateHandler.js +60 -0
- package/dist/core/handlers/DecimalHandler.d.ts +2 -0
- package/dist/core/handlers/DecimalHandler.js +60 -0
- package/dist/core/handlers/EnumHandler.d.ts +2 -0
- package/dist/core/handlers/EnumHandler.js +89 -0
- package/dist/core/handlers/GenericContainerHandler.d.ts +2 -0
- package/dist/core/handlers/GenericContainerHandler.js +440 -0
- package/dist/core/handlers/GenericHandler.d.ts +18 -0
- package/dist/core/handlers/GenericHandler.js +92 -0
- package/dist/core/handlers/HandlerBootstrap.d.ts +2 -0
- package/dist/core/handlers/HandlerBootstrap.js +28 -0
- package/dist/core/handlers/ITypeHandler.d.ts +23 -0
- package/dist/core/handlers/ITypeHandler.js +8 -0
- package/dist/core/handlers/PrimitiveHandler.d.ts +2 -0
- package/dist/core/handlers/PrimitiveHandler.js +127 -0
- package/dist/core/handlers/TupleHandler.d.ts +2 -0
- package/dist/core/handlers/TupleHandler.js +98 -0
- package/dist/core/handlers/TypeHandlerRegistry.d.ts +20 -0
- package/dist/core/handlers/TypeHandlerRegistry.js +113 -0
- package/dist/core/handlers/UnionTypeHandler.d.ts +2 -0
- package/dist/core/handlers/UnionTypeHandler.js +263 -0
- package/dist/core/handlers/index.d.ts +2 -0
- package/dist/core/handlers/index.js +5 -0
- package/dist/core/import-rewrite/services/BuildProfileUpdater.d.ts +8 -0
- package/dist/core/import-rewrite/services/BuildProfileUpdater.js +92 -0
- package/dist/core/import-rewrite/services/ImportRewriteService.d.ts +9 -0
- package/dist/core/import-rewrite/services/ImportRewriteService.js +61 -0
- package/dist/core/import-rewrite/services/ImportTransformService.d.ts +15 -0
- package/dist/core/import-rewrite/services/ImportTransformService.js +109 -0
- package/dist/core/import-rewrite/strategies/ImportScanStrategy.d.ts +17 -0
- package/dist/core/import-rewrite/strategies/ImportScanStrategy.js +137 -0
- package/dist/core/import-rewrite/types/ImportRewriteTypes.d.ts +17 -0
- package/dist/core/import-rewrite/types/ImportRewriteTypes.js +2 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.js +27 -0
- package/dist/core/interfaces/ITask.d.ts +7 -0
- package/dist/core/interfaces/ITask.js +2 -0
- package/dist/core/interfaces/ITaskContext.d.ts +11 -0
- package/dist/core/interfaces/ITaskContext.js +2 -0
- package/dist/core/interfaces/index.d.ts +2 -0
- package/dist/core/interfaces/index.js +2 -0
- package/dist/core/logger/Logger.d.ts +13 -0
- package/dist/core/logger/Logger.js +78 -0
- package/dist/core/services/CodeAnalysisService.d.ts +7 -0
- package/dist/core/services/CodeAnalysisService.js +43 -0
- package/dist/core/services/CodeGenerationEngine.d.ts +12 -0
- package/dist/core/services/CodeGenerationEngine.js +102 -0
- package/dist/core/services/CodeGenerationService/CodeGenerationService.d.ts +13 -0
- package/dist/core/services/CodeGenerationService/CodeGenerationService.js +110 -0
- package/dist/core/services/CodeGenerationService/generators/MergedSendableClassGenerator.d.ts +13 -0
- package/dist/core/services/CodeGenerationService/generators/MergedSendableClassGenerator.js +119 -0
- package/dist/core/services/CodeGenerationService/generators/OriginalClassGenerator.d.ts +21 -0
- package/dist/core/services/CodeGenerationService/generators/OriginalClassGenerator.js +224 -0
- package/dist/core/services/CodeGenerationService/generators/SendableClassGenerator.d.ts +24 -0
- package/dist/core/services/CodeGenerationService/generators/SendableClassGenerator.js +307 -0
- package/dist/core/services/CodeGenerationService/generators/SerializerGenerator.d.ts +28 -0
- package/dist/core/services/CodeGenerationService/generators/SerializerGenerator.js +259 -0
- package/dist/core/services/CodeGenerationService/generators/TempSerializerGenerator.d.ts +19 -0
- package/dist/core/services/CodeGenerationService/generators/TempSerializerGenerator.js +178 -0
- package/dist/core/services/CodeGenerationService/index.d.ts +1 -0
- package/dist/core/services/CodeGenerationService/index.js +5 -0
- package/dist/core/services/CodeGenerationService/shared/ImportManager.d.ts +27 -0
- package/dist/core/services/CodeGenerationService/shared/ImportManager.js +127 -0
- package/dist/core/template/HandlebarsTemplateEngine.d.ts +26 -0
- package/dist/core/template/HandlebarsTemplateEngine.js +226 -0
- package/dist/core/utils/ConfigManager.d.ts +10 -0
- package/dist/core/utils/ConfigManager.js +32 -0
- package/dist/core/utils/CustomError.d.ts +30 -0
- package/dist/core/utils/CustomError.js +37 -0
- package/dist/core/utils/DeepCopyUtil.d.ts +15 -0
- package/dist/core/utils/DeepCopyUtil.js +138 -0
- package/dist/core/utils/GenericTypeSubstitutionUtil.d.ts +9 -0
- package/dist/core/utils/GenericTypeSubstitutionUtil.js +68 -0
- package/dist/core/utils/SerializationPathUtil.d.ts +18 -0
- package/dist/core/utils/SerializationPathUtil.js +107 -0
- package/dist/core/utils/TsMorphUtil.d.ts +8 -0
- package/dist/core/utils/TsMorphUtil.js +34 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +57 -0
- package/dist/json-plugin/JSONExecuteController.d.ts +13 -0
- package/dist/json-plugin/JSONExecuteController.js +103 -0
- package/dist/json-plugin/constants/TaskConstants.d.ts +7 -0
- package/dist/json-plugin/constants/TaskConstants.js +11 -0
- package/dist/json-plugin/interfaces/IModuleContext.d.ts +10 -0
- package/dist/json-plugin/interfaces/IModuleContext.js +2 -0
- package/dist/json-plugin/interfaces/ITargetContext.d.ts +8 -0
- package/dist/json-plugin/interfaces/ITargetContext.js +2 -0
- package/dist/json-plugin/interfaces/impl/ModuleContext.d.ts +12 -0
- package/dist/json-plugin/interfaces/impl/ModuleContext.js +24 -0
- package/dist/json-plugin/interfaces/impl/TargetContext.d.ts +23 -0
- package/dist/json-plugin/interfaces/impl/TargetContext.js +113 -0
- package/dist/json-plugin/tasks/BaseTask.d.ts +14 -0
- package/dist/json-plugin/tasks/BaseTask.js +53 -0
- package/dist/json-plugin/tasks/CleanTask.d.ts +8 -0
- package/dist/json-plugin/tasks/CleanTask.js +25 -0
- package/dist/json-plugin/tasks/CodeProcessingTask.d.ts +8 -0
- package/dist/json-plugin/tasks/CodeProcessingTask.js +26 -0
- package/dist/json-plugin/tasks/SyncTask.d.ts +8 -0
- package/dist/json-plugin/tasks/SyncTask.js +21 -0
- package/dist/json-plugin/tasks/WatchTask.d.ts +11 -0
- package/dist/json-plugin/tasks/WatchTask.js +102 -0
- package/package.json +46 -0
- package/src/core/Types.ts +356 -0
- package/src/core/analyzers/ClassAnalyzer.ts +824 -0
- package/src/core/analyzers/CustomTypeAnalyzer.ts +337 -0
- package/src/core/analyzers/SendableMergeChecker.ts +195 -0
- package/src/core/analyzers/SendableMergeabilityRegistry.ts +72 -0
- package/src/core/constants/DecoratorConstants.ts +27 -0
- package/src/core/constants/PathConstants.ts +31 -0
- package/src/core/constants/StringConstants.ts +152 -0
- package/src/core/constants/index.ts +21 -0
- package/src/core/handlers/BaseTypeHandler.ts +121 -0
- package/src/core/handlers/CustomClassHandler.ts +278 -0
- package/src/core/handlers/DateHandler.ts +75 -0
- package/src/core/handlers/DecimalHandler.ts +75 -0
- package/src/core/handlers/EnumHandler.ts +142 -0
- package/src/core/handlers/GenericContainerHandler.ts +621 -0
- package/src/core/handlers/GenericHandler.ts +130 -0
- package/src/core/handlers/HandlerBootstrap.ts +64 -0
- package/src/core/handlers/ITypeHandler.ts +133 -0
- package/src/core/handlers/PrimitiveHandler.ts +159 -0
- package/src/core/handlers/TupleHandler.ts +145 -0
- package/src/core/handlers/TypeHandlerRegistry.ts +236 -0
- package/src/core/handlers/UnionTypeHandler.ts +400 -0
- package/src/core/handlers/index.ts +18 -0
- package/src/core/import-rewrite/services/BuildProfileUpdater.ts +145 -0
- package/src/core/import-rewrite/services/ImportRewriteService.ts +129 -0
- package/src/core/import-rewrite/services/ImportTransformService.ts +200 -0
- package/src/core/import-rewrite/strategies/ImportScanStrategy.ts +303 -0
- package/src/core/import-rewrite/types/ImportRewriteTypes.ts +100 -0
- package/src/core/index.ts +31 -0
- package/src/core/interfaces/ITask.ts +23 -0
- package/src/core/interfaces/ITaskContext.ts +94 -0
- package/src/core/interfaces/index.ts +17 -0
- package/src/core/logger/Logger.ts +149 -0
- package/src/core/services/CodeAnalysisService.ts +67 -0
- package/src/core/services/CodeGenerationEngine.ts +181 -0
- package/src/core/services/CodeGenerationService/CodeGenerationService.ts +159 -0
- package/src/core/services/CodeGenerationService/generators/MergedSendableClassGenerator.ts +189 -0
- package/src/core/services/CodeGenerationService/generators/OriginalClassGenerator.ts +314 -0
- package/src/core/services/CodeGenerationService/generators/SendableClassGenerator.ts +421 -0
- package/src/core/services/CodeGenerationService/generators/SerializerGenerator.ts +392 -0
- package/src/core/services/CodeGenerationService/generators/TempSerializerGenerator.ts +277 -0
- package/src/core/services/CodeGenerationService/index.ts +16 -0
- package/src/core/services/CodeGenerationService/shared/ImportManager.ts +191 -0
- package/src/core/template/HandlebarsTemplateEngine.ts +282 -0
- package/src/core/utils/ConfigManager.ts +49 -0
- package/src/core/utils/CustomError.ts +51 -0
- package/src/core/utils/DeepCopyUtil.ts +185 -0
- package/src/core/utils/GenericTypeSubstitutionUtil.ts +136 -0
- package/src/core/utils/SerializationPathUtil.ts +142 -0
- package/src/core/utils/TsMorphUtil.ts +50 -0
- package/src/index.ts +81 -0
- package/src/json-plugin/JSONExecuteController.ts +134 -0
- package/src/json-plugin/constants/TaskConstants.ts +22 -0
- package/src/json-plugin/interfaces/IModuleContext.ts +27 -0
- package/src/json-plugin/interfaces/ITargetContext.ts +25 -0
- package/src/json-plugin/interfaces/impl/ModuleContext.ts +45 -0
- package/src/json-plugin/interfaces/impl/TargetContext.ts +196 -0
- package/src/json-plugin/tasks/BaseTask.ts +94 -0
- package/src/json-plugin/tasks/CleanTask.ts +36 -0
- package/src/json-plugin/tasks/CodeProcessingTask.ts +41 -0
- package/src/json-plugin/tasks/SyncTask.ts +33 -0
- package/src/json-plugin/tasks/WatchTask.ts +99 -0
- package/template/SerializerPerformanceTemplate.hbs +35 -0
- package/template/SerializerRegisterTemplate.hbs +10 -0
- package/template/SerializerStrictTemplate.hbs +89 -0
- package/template/SerializerTemplate.hbs +176 -0
- package/tsconfig.json +17 -0
- package/tslint.json +3 -0
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Huawei Device Co., Ltd.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
ClassDeclaration,
|
|
18
|
+
EnumDeclaration,
|
|
19
|
+
InterfaceDeclaration,
|
|
20
|
+
Project,
|
|
21
|
+
SourceFile,
|
|
22
|
+
TypeAliasDeclaration
|
|
23
|
+
} from 'ts-morph';
|
|
24
|
+
import {
|
|
25
|
+
ClassDetails,
|
|
26
|
+
EnumDetails,
|
|
27
|
+
EnumMemberInfo,
|
|
28
|
+
InterfaceDetails,
|
|
29
|
+
TypeAliasDetails,
|
|
30
|
+
TypeDependency,
|
|
31
|
+
TypeDetails,
|
|
32
|
+
TypeKind
|
|
33
|
+
} from '..';
|
|
34
|
+
import SerializationPathUtil from '../utils/SerializationPathUtil';
|
|
35
|
+
import { TsMorphUtil } from '../utils/TsMorphUtil';
|
|
36
|
+
|
|
37
|
+
export class CustomTypeAnalyzer {
|
|
38
|
+
private static readonly INSTANCE: CustomTypeAnalyzer = new CustomTypeAnalyzer();
|
|
39
|
+
/** 类型查找缓存 <名称+路径,依赖地址> */
|
|
40
|
+
private searchCache = new Map<string, TypeDependency | null>();
|
|
41
|
+
|
|
42
|
+
private constructor() { }
|
|
43
|
+
|
|
44
|
+
public static getInstance(): CustomTypeAnalyzer {
|
|
45
|
+
return this.INSTANCE;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 类型查找方法-实现本文件-->本模块-->跨模块三步走查找逻辑
|
|
50
|
+
*
|
|
51
|
+
* @param targetName 目标类型名称
|
|
52
|
+
* @param sourceFile 起始源文件
|
|
53
|
+
* @returns 查找结果,未找到时返回 null
|
|
54
|
+
*/
|
|
55
|
+
public findDefinition(targetName: string, sourceFile: SourceFile): TypeDependency | null {
|
|
56
|
+
const cacheKey = `${sourceFile.getFilePath()}:${targetName}`;
|
|
57
|
+
|
|
58
|
+
// 检查缓存
|
|
59
|
+
if (cacheKey && this.searchCache.has(cacheKey)) {
|
|
60
|
+
const cached = this.searchCache.get(cacheKey);
|
|
61
|
+
return cached !== undefined ? cached : null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let result: TypeDependency | null;
|
|
65
|
+
|
|
66
|
+
// 步骤1:在当前文件中查找
|
|
67
|
+
result = this.findInCurrentFile(targetName, sourceFile);
|
|
68
|
+
if (result) {
|
|
69
|
+
if (cacheKey) {
|
|
70
|
+
this.searchCache.set(cacheKey, result);
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 步骤2:根据导入语句查找本模块内的类型定义
|
|
76
|
+
result = this.findInImports(targetName, sourceFile);
|
|
77
|
+
if (result) {
|
|
78
|
+
if (cacheKey) {
|
|
79
|
+
this.searchCache.set(cacheKey, result);
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 步骤3:查找oh_modules中的跨模块类型定义
|
|
85
|
+
result = this.findInCrossModule(targetName, sourceFile);
|
|
86
|
+
if (result) {
|
|
87
|
+
if (cacheKey) {
|
|
88
|
+
this.searchCache.set(cacheKey, result);
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 缓存未找到的结果
|
|
94
|
+
if (cacheKey) {
|
|
95
|
+
this.searchCache.set(cacheKey, null);
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public findClassDeclFromClassName(className: string, sourceFile: SourceFile): ClassDeclaration | InterfaceDeclaration | null {
|
|
101
|
+
const res = this.findDefinition(className, sourceFile);
|
|
102
|
+
if (res && res.typeKind === TypeKind.CLASS) {
|
|
103
|
+
return (res.details as ClassDetails).classDecl;
|
|
104
|
+
}
|
|
105
|
+
if (res && res.typeKind === TypeKind.INTERFACE) {
|
|
106
|
+
return (res.details as InterfaceDetails).interfaceDecl;
|
|
107
|
+
}
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public clearCache(): void {
|
|
112
|
+
this.searchCache.clear();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private findInCurrentFile(targetName: string, sourceFile: SourceFile): TypeDependency | null {
|
|
116
|
+
const typeDetail = this.searchInSourceFile(targetName, sourceFile);
|
|
117
|
+
if (typeDetail) {
|
|
118
|
+
return {
|
|
119
|
+
typeName: targetName,
|
|
120
|
+
typeKind: typeDetail.kind,
|
|
121
|
+
importPath: '',
|
|
122
|
+
source: {
|
|
123
|
+
type: 'local',
|
|
124
|
+
sourceFilePath: sourceFile.getFilePath()
|
|
125
|
+
},
|
|
126
|
+
details: typeDetail
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private findInImports(targetName: string, sourceFile: SourceFile): TypeDependency | null {
|
|
133
|
+
const imports = sourceFile.getImportDeclarations();
|
|
134
|
+
|
|
135
|
+
for (const importDecl of imports) {
|
|
136
|
+
// TODO:当前实现只处理命名导入,default导入和命名空间导入暂未支持
|
|
137
|
+
const namedImports = importDecl.getNamedImports();
|
|
138
|
+
const specifierValue = importDecl.getModuleSpecifierValue();
|
|
139
|
+
|
|
140
|
+
// 检查是否在命名导入中找到了目标类型
|
|
141
|
+
for (const namedImport of namedImports) {
|
|
142
|
+
const importName = namedImport.getName();
|
|
143
|
+
if (importName === targetName) {
|
|
144
|
+
// 找到了导入的类型,现在需要解析文件路径
|
|
145
|
+
const moduleSpecifier = importDecl.getModuleSpecifierValue();
|
|
146
|
+
const resolvedPath = this.resolveImportPath(moduleSpecifier, sourceFile);
|
|
147
|
+
|
|
148
|
+
if (resolvedPath && SerializationPathUtil.exist(resolvedPath)) {
|
|
149
|
+
// 加载外部文件并查找类型定义
|
|
150
|
+
const externalSourceFile = this.getOrLoadSourceFile(resolvedPath);
|
|
151
|
+
if (externalSourceFile) {
|
|
152
|
+
const typeDetail = this.searchInSourceFile(targetName, externalSourceFile);
|
|
153
|
+
if (typeDetail) {
|
|
154
|
+
return {
|
|
155
|
+
typeName: targetName,
|
|
156
|
+
typeKind: typeDetail.kind,
|
|
157
|
+
importPath: specifierValue,
|
|
158
|
+
source: {
|
|
159
|
+
type: 'imported',
|
|
160
|
+
sourceFilePath: externalSourceFile.getFilePath(),
|
|
161
|
+
originalImport: specifierValue
|
|
162
|
+
},
|
|
163
|
+
details: typeDetail
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
private findInCrossModule(targetName: string, sourceFile: SourceFile): TypeDependency | null {
|
|
176
|
+
// TODO: 跨模块暂未实现
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private searchInSourceFile(targetName: string, sourceFile: SourceFile): TypeDetails | null {
|
|
181
|
+
// 查找类定义
|
|
182
|
+
const classes = sourceFile.getClasses();
|
|
183
|
+
for (const classDecl of classes) {
|
|
184
|
+
if (classDecl.getName() === targetName) {
|
|
185
|
+
return this.parseClassDetails(classDecl);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// 查找接口定义
|
|
190
|
+
const interfaces = sourceFile.getInterfaces();
|
|
191
|
+
for (const interfaceDecl of interfaces) {
|
|
192
|
+
if (interfaceDecl.getName() === targetName) {
|
|
193
|
+
return this.parseInterfaceDetails(interfaceDecl);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// 查找枚举定义
|
|
198
|
+
const enums = sourceFile.getEnums();
|
|
199
|
+
for (const enumDecl of enums) {
|
|
200
|
+
if (enumDecl.getName() === targetName) {
|
|
201
|
+
return this.parseEnumDetails(enumDecl);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// 查找类型定义
|
|
206
|
+
const types = sourceFile.getTypeAliases();
|
|
207
|
+
for (const typeAliasDecl of types) {
|
|
208
|
+
if (typeAliasDecl.getName() === targetName) {
|
|
209
|
+
return this.parseTypeAliasDetails(typeAliasDecl);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private parseEnumDetails(enumDecl: EnumDeclaration): EnumDetails {
|
|
217
|
+
const members: EnumMemberInfo[] = [];
|
|
218
|
+
let valueType: 'string' | 'number' = 'number'; // 默认为数值类型
|
|
219
|
+
let numericValue = 0; // 用于自动递增的数值
|
|
220
|
+
|
|
221
|
+
const enumMembers = enumDecl.getMembers();
|
|
222
|
+
for (const member of enumMembers) {
|
|
223
|
+
const memberName = member.getName();
|
|
224
|
+
let memberValue: string | number;
|
|
225
|
+
let literalValue: string;
|
|
226
|
+
|
|
227
|
+
const initializer = member.getInitializer();
|
|
228
|
+
if (initializer) {
|
|
229
|
+
// 有显式初始值
|
|
230
|
+
const initText = initializer.getText().trim();
|
|
231
|
+
|
|
232
|
+
// 判断是字符串还是数值
|
|
233
|
+
if (initText.startsWith('"') && initText.endsWith('"')) {
|
|
234
|
+
// 字符串枚举
|
|
235
|
+
memberValue = initText.slice(1, -1); // 去掉引号
|
|
236
|
+
literalValue = initText; // 保留引号
|
|
237
|
+
valueType = 'string';
|
|
238
|
+
} else if (initText.startsWith("'") && initText.endsWith("'")) {
|
|
239
|
+
// 字符串枚举(单引号)
|
|
240
|
+
memberValue = initText.slice(1, -1); // 去掉引号
|
|
241
|
+
literalValue = `"${memberValue}"`; // 统一使用双引号
|
|
242
|
+
valueType = 'string';
|
|
243
|
+
} else {
|
|
244
|
+
// 数值枚举
|
|
245
|
+
const numValue = parseInt(initText, 10);
|
|
246
|
+
if (!isNaN(numValue)) {
|
|
247
|
+
memberValue = numValue;
|
|
248
|
+
literalValue = numValue.toString();
|
|
249
|
+
numericValue = numValue + 1; // 更新下一个自动值
|
|
250
|
+
} else {
|
|
251
|
+
// 复杂表达式,暂时当作字符串处理
|
|
252
|
+
memberValue = initText;
|
|
253
|
+
literalValue = `"${initText}"`;
|
|
254
|
+
valueType = 'string';
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
} else {
|
|
258
|
+
// 没有显式初始值,使用自动递增的数值
|
|
259
|
+
memberValue = numericValue;
|
|
260
|
+
literalValue = numericValue.toString();
|
|
261
|
+
numericValue++;
|
|
262
|
+
}
|
|
263
|
+
members.push({
|
|
264
|
+
name: memberName,
|
|
265
|
+
value: memberValue,
|
|
266
|
+
literalValue
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
return { kind: TypeKind.ENUM, valueType, members };
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
private parseClassDetails(classDecl: ClassDeclaration): ClassDetails {
|
|
273
|
+
return {
|
|
274
|
+
kind: TypeKind.CLASS,
|
|
275
|
+
classDecl,
|
|
276
|
+
isGeneric: classDecl.getTypeParameters().length > 0
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
private parseInterfaceDetails(interfaceDecl: InterfaceDeclaration): InterfaceDetails {
|
|
281
|
+
return {
|
|
282
|
+
kind: TypeKind.INTERFACE,
|
|
283
|
+
interfaceDecl,
|
|
284
|
+
isGeneric: interfaceDecl.getTypeParameters().length > 0
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
private parseTypeAliasDetails(typeAliasDecl: TypeAliasDeclaration): TypeAliasDetails {
|
|
289
|
+
const aliasedType = typeAliasDecl.getTypeNodeOrThrow().getText();
|
|
290
|
+
|
|
291
|
+
// 解析实际类型节点,填充 resolvedType
|
|
292
|
+
const actualTypeNode = typeAliasDecl.getTypeNodeOrThrow();
|
|
293
|
+
const { TypeHandlerRegistry } = require('../handlers/TypeHandlerRegistry');
|
|
294
|
+
|
|
295
|
+
// 递归解析实际类型结构
|
|
296
|
+
const resolvedType = TypeHandlerRegistry.getInstance().parseType(actualTypeNode, {
|
|
297
|
+
depth: 0,
|
|
298
|
+
genericParams: []
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
return { kind: TypeKind.TYPE, aliasedType, resolvedType };
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
private resolveImportPath(moduleSpecifier: string, sourceFile: SourceFile): string | null {
|
|
305
|
+
const currentFilePath = sourceFile.getFilePath();
|
|
306
|
+
const currentDir = SerializationPathUtil.dirname(currentFilePath);
|
|
307
|
+
|
|
308
|
+
// 处理相对路径导入
|
|
309
|
+
if (moduleSpecifier.startsWith('./') || moduleSpecifier.startsWith('../')) {
|
|
310
|
+
const resolvedPath = SerializationPathUtil.pathResolve(currentDir, moduleSpecifier);
|
|
311
|
+
|
|
312
|
+
// 尝试不同的文件扩展名
|
|
313
|
+
const extensions = ['.ets', '.d.ets'];
|
|
314
|
+
for (const ext of extensions) {
|
|
315
|
+
const fullPath = resolvedPath + ext;
|
|
316
|
+
if (SerializationPathUtil.exist(fullPath)) {
|
|
317
|
+
return fullPath;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
private getOrLoadSourceFile(filePath: string): SourceFile | null {
|
|
326
|
+
const existingFile = TsMorphUtil.getProject().getSourceFile(filePath);
|
|
327
|
+
if (existingFile) {
|
|
328
|
+
return existingFile;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (SerializationPathUtil.exist(filePath)) {
|
|
332
|
+
return TsMorphUtil.getProject().addSourceFileAtPath(filePath);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return null;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Huawei Device Co., Ltd.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { Decorator } from 'ts-morph';
|
|
17
|
+
import { ClassAnalysis, PropertyKind, TypeStructure } from '../Types';
|
|
18
|
+
import { DecoratorConstants } from '../constants';
|
|
19
|
+
import { Logger } from '../logger/Logger';
|
|
20
|
+
import { SendableMergeabilityRegistry } from './SendableMergeabilityRegistry';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Sendable类合并性检查器
|
|
24
|
+
*
|
|
25
|
+
* 检查是否可以将原始类和Sendable类合并为单一Sendable类。
|
|
26
|
+
*
|
|
27
|
+
* 合并条件:
|
|
28
|
+
* 1. 类层级无非TurboTrans装饰器
|
|
29
|
+
* 2. 类无泛型参数
|
|
30
|
+
* 3. 每个属性无非TurboTrans装饰器
|
|
31
|
+
* 4. 每个属性是Sendable允许类型或可合并的@Serializable类
|
|
32
|
+
* 5. 父类也必须可合并
|
|
33
|
+
*
|
|
34
|
+
* 合并后的类:
|
|
35
|
+
* - 移除所有TurboTrans装饰器
|
|
36
|
+
* - 添加 @Sendable 装饰器
|
|
37
|
+
* - 类名保持不变
|
|
38
|
+
*/
|
|
39
|
+
export class SendableMergeChecker {
|
|
40
|
+
// TurboTrans装饰器集合(用于快速查找)
|
|
41
|
+
private static readonly TURBO_TRANS_DECORATORS = new Set(DecoratorConstants.SERIAL_DECORATORS);
|
|
42
|
+
|
|
43
|
+
// Sendable允许的基础类型(根据官方文档)
|
|
44
|
+
private static readonly SENDABLE_PRIMITIVE_KINDS = new Set<PropertyKind>([
|
|
45
|
+
PropertyKind.STRING,
|
|
46
|
+
PropertyKind.NUMBER,
|
|
47
|
+
PropertyKind.BOOLEAN,
|
|
48
|
+
PropertyKind.BIGINT,
|
|
49
|
+
PropertyKind.NULL,
|
|
50
|
+
PropertyKind.UNDEFINED,
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
// TODO: 这里的白名单暂时还没写全
|
|
54
|
+
// Sendable允许的Collections容器类型
|
|
55
|
+
private static readonly SENDABLE_COLLECTION_KINDS = new Set<PropertyKind>([
|
|
56
|
+
PropertyKind.COLLECTIONS_ARRAY,
|
|
57
|
+
PropertyKind.COLLECTIONS_SET,
|
|
58
|
+
PropertyKind.COLLECTIONS_MAP,
|
|
59
|
+
]);
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 检查类的Sendable合并性
|
|
63
|
+
* @param classAnalysis 类分析结果
|
|
64
|
+
* @returns 合并性分析结果
|
|
65
|
+
*/
|
|
66
|
+
public static check(classAnalysis: ClassAnalysis): boolean {
|
|
67
|
+
// 条件1: 检查类级别装饰器
|
|
68
|
+
const classDecorators = classAnalysis.originalClass?.getDecorators() || [];
|
|
69
|
+
const nonTurboTransDecorators = this.getNonTurboTransDecorators(classDecorators);
|
|
70
|
+
if (nonTurboTransDecorators.length > 0) {
|
|
71
|
+
// TODO: 完善debug日志
|
|
72
|
+
Logger.debug(`${classAnalysis.className}类有其他装饰器`);
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 条件2: 检查泛型参数
|
|
77
|
+
if (classAnalysis.generics.isGeneric) {
|
|
78
|
+
// TODO: 完善debug日志
|
|
79
|
+
Logger.debug(`${classAnalysis.className}类有泛型参数`);
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 条件3 & 4: 检查属性装饰器和类型
|
|
84
|
+
const invalidProperties: string[] = [];
|
|
85
|
+
for (const property of classAnalysis.properties) {
|
|
86
|
+
// 条件3: 检查属性装饰器
|
|
87
|
+
const propertyNode = classAnalysis.originalClass?.getProperty(property.name);
|
|
88
|
+
if (propertyNode) {
|
|
89
|
+
const propDecorators = propertyNode.getDecorators();
|
|
90
|
+
const nonTurboPropDecorators = this.getNonTurboTransDecorators(propDecorators);
|
|
91
|
+
if (nonTurboPropDecorators.length > 0) {
|
|
92
|
+
// TODO: 完善debug日志
|
|
93
|
+
invalidProperties.push(`${property.name} (装饰器: ${nonTurboPropDecorators.join(', ')})`);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 条件4: 检查属性类型是否为Sendable允许类型
|
|
99
|
+
if (!this.isSendableType(property.type, classAnalysis)) {
|
|
100
|
+
// TODO: 完善debug日志
|
|
101
|
+
invalidProperties.push(`${property.name} (类型: ${property.type.sourceText})`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (classAnalysis.originalClass) {
|
|
106
|
+
for (const method of classAnalysis.originalClass.getMethods()) {
|
|
107
|
+
// 条件3: 检查方法装饰器
|
|
108
|
+
const methodDecorators = method.getDecorators();
|
|
109
|
+
const nonTurboPropDecorators = this.getNonTurboTransDecorators(methodDecorators);
|
|
110
|
+
if (nonTurboPropDecorators.length > 0) {
|
|
111
|
+
invalidProperties.push(`${method.getName()} (装饰器: ${nonTurboPropDecorators.join(', ')})`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (invalidProperties.length > 0) {
|
|
117
|
+
// TODO: 完善debug日志
|
|
118
|
+
Logger.debug(invalidProperties.join('\n'));
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// 条件5: 递归检查父类
|
|
123
|
+
if (classAnalysis.inheritance.isInherited && classAnalysis.inheritance.baseClassAnalysis) {
|
|
124
|
+
// TODO: 完善debug日志
|
|
125
|
+
Logger.debug(`${classAnalysis.className}的父类不可合并`);
|
|
126
|
+
return this.check(classAnalysis.inheritance.baseClassAnalysis as ClassAnalysis);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// 所有条件满足,可以合并
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* 获取非TurboTrans装饰器列表
|
|
135
|
+
* @param decorators 装饰器数组
|
|
136
|
+
* @returns 非TurboTrans装饰器名称列表
|
|
137
|
+
*/
|
|
138
|
+
private static getNonTurboTransDecorators(decorators: Decorator[]): string[] {
|
|
139
|
+
return decorators
|
|
140
|
+
.map(d => d.getName())
|
|
141
|
+
.filter(name => !this.TURBO_TRANS_DECORATORS.has(name));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* 检查类型是否为Sendable允许类型
|
|
146
|
+
* @param typeStructure 类型结构
|
|
147
|
+
* @param contextClass 当前类分析上下文(用于查找自定义类型)
|
|
148
|
+
* @returns 是否为Sendable允许类型
|
|
149
|
+
*/
|
|
150
|
+
private static isSendableType(typeStructure: TypeStructure, contextClass: ClassAnalysis): boolean {
|
|
151
|
+
const { kind } = typeStructure;
|
|
152
|
+
|
|
153
|
+
// 基础类型
|
|
154
|
+
if (this.SENDABLE_PRIMITIVE_KINDS.has(kind)) {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Collections容器类型
|
|
159
|
+
if (this.SENDABLE_COLLECTION_KINDS.has(kind)) {
|
|
160
|
+
// 递归检查泛型参数类型
|
|
161
|
+
return typeStructure.args.every(arg => this.isSendableType(arg, contextClass));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// 自定义类类型(OBJECT类型)
|
|
165
|
+
if (kind === PropertyKind.OBJECT && typeStructure.classDetails) {
|
|
166
|
+
// 检查是否为可合并的@Serializable类
|
|
167
|
+
const classDetails = typeStructure.classDetails;
|
|
168
|
+
if (classDetails.classDecl.getDecorator('Sendable')) {
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const className = classDetails.classDecl.getNameOrThrow();
|
|
173
|
+
// 从全局注册表查询合并性
|
|
174
|
+
const canMerge = SendableMergeabilityRegistry.canMerge(className);
|
|
175
|
+
|
|
176
|
+
if (canMerge === undefined) {
|
|
177
|
+
// 类还未分析(可能在其他文件中,或循环引用)
|
|
178
|
+
// 保守处理:假设不可合并
|
|
179
|
+
// 注意:在双阶段分析架构下,这种情况应该很少发生
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return canMerge;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Optional/Nullable/Union类型:所有成员都必须是Sendable类型
|
|
187
|
+
if ((kind === PropertyKind.UNION || kind === PropertyKind.OPTIONAL || kind === PropertyKind.NULLABLE) &&
|
|
188
|
+
typeStructure.unionDetails) {
|
|
189
|
+
return typeStructure.unionDetails.every(member => this.isSendableType(member, contextClass));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// 其他类型(Array, Set, Map, Record等)不是Sendable类型
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Huawei Device Co., Ltd.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { Logger } from '..';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Sendable合并性全局注册表
|
|
20
|
+
*
|
|
21
|
+
* 用于存储所有类的合并性分析结果,避免循环依赖和重复分析。
|
|
22
|
+
*
|
|
23
|
+
* 使用场景:
|
|
24
|
+
* 1. 在 ClassAnalyzer 分析完所有类后,注册每个类的合并性
|
|
25
|
+
* 2. 在 SendableMergeChecker.isSendableType() 中查询依赖类的合并性
|
|
26
|
+
*
|
|
27
|
+
* 生命周期:
|
|
28
|
+
* - 每次代码生成开始前清空
|
|
29
|
+
* - 分析阶段填充
|
|
30
|
+
* - 生成阶段查询
|
|
31
|
+
*/
|
|
32
|
+
export class SendableMergeabilityRegistry {
|
|
33
|
+
// 合并性映射:类名 -> 是否可合并
|
|
34
|
+
private static mergeabilityMap = new Map<string, boolean>();
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 注册类的合并性
|
|
38
|
+
* @param className 类名
|
|
39
|
+
* @param canMerge 是否可以合并
|
|
40
|
+
*/
|
|
41
|
+
static register(className: string, canMerge: boolean): void {
|
|
42
|
+
this.mergeabilityMap.set(className, canMerge);
|
|
43
|
+
Logger.debug(`[SendableMergeabilityRegistry] 注册类合并性: ${className} -> ${canMerge}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 查询类的合并性
|
|
48
|
+
* @param className 类名
|
|
49
|
+
* @returns 是否可合并,undefined 表示类还未分析
|
|
50
|
+
*/
|
|
51
|
+
static canMerge(className: string): boolean | undefined {
|
|
52
|
+
return this.mergeabilityMap.get(className);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 检查类是否已注册
|
|
57
|
+
* @param className 类名
|
|
58
|
+
* @returns 是否已注册
|
|
59
|
+
*/
|
|
60
|
+
static hasClass(className: string): boolean {
|
|
61
|
+
return this.mergeabilityMap.has(className);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 清空所有注册信息(每次代码生成前调用)
|
|
66
|
+
*/
|
|
67
|
+
static clear(): void {
|
|
68
|
+
const count = this.mergeabilityMap.size;
|
|
69
|
+
this.mergeabilityMap.clear();
|
|
70
|
+
Logger.debug(`[SendableMergeabilityRegistry] 清空注册表,已移除 ${count} 个类的合并性信息`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Huawei Device Co., Ltd.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 装饰器常量定义
|
|
18
|
+
*/
|
|
19
|
+
export class DecoratorConstants {
|
|
20
|
+
// TSerialization装饰器
|
|
21
|
+
static readonly SERIALIZABLE = 'Serializable'
|
|
22
|
+
static readonly SERIAL_NAME = 'SerialName'
|
|
23
|
+
static readonly REQUIRED = 'Required'
|
|
24
|
+
static readonly TRANSIENT = 'Transient'
|
|
25
|
+
|
|
26
|
+
static readonly SERIAL_DECORATORS = [this.SERIALIZABLE, this.SERIAL_NAME, this.REQUIRED, this.TRANSIENT];
|
|
27
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Huawei Device Co., Ltd.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 路径相关常量定义
|
|
18
|
+
*/
|
|
19
|
+
export class PathConstants {
|
|
20
|
+
/** 默认源代码根目录 */
|
|
21
|
+
static readonly DEFAULT_SOURCE_ROOT = './src/main'
|
|
22
|
+
|
|
23
|
+
/** 生成代码根目录 */
|
|
24
|
+
static readonly GENERATED_ROOT = './src/generated'
|
|
25
|
+
|
|
26
|
+
/** 支持的文件扩展名 */
|
|
27
|
+
static readonly ETS_EXTENSIONS = '.ets'
|
|
28
|
+
|
|
29
|
+
/** 默认扫描目录 */
|
|
30
|
+
static readonly DEFAULT_SCAN_DIRS = ['src/main/ets']
|
|
31
|
+
}
|