• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 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 */
15import { BasicApiInfo as nodeBaseApiInfo, ExportImportValue } from '../../typedef/parser/ApiInfoDefination';
16
17import { StringConstant } from '../../utils/Constant';
18import { Comment } from './Comment';
19
20export class BasicApiInfo {
21  apiType: string = ''; // api 类型
22  constructor(apiType: string) {
23    this.apiType = apiType;
24  }
25}
26
27export class ApiInfo extends BasicApiInfo {
28  name: string = ''; // api的名称
29  syscap: string = ''; // api的系统能力
30  since: string = '-1'; // api的起始版本
31  isForm: boolean = false; // api是否支持卡片应用
32  isCrossPlatForm: boolean = false; // api是否支持跨平台
33  isSystemApi: boolean = false; // api是否是系统api
34  isStageModelOnly: boolean = false; // api是否仅Stage模型可用
35  isFaModelOnly: boolean = false; // api是否仅FA模型可用
36  deprecatedVersion: string = '-1'; // api的废弃版本
37  useinstead: string = ''; // api的替换接口
38
39  constructor(apiType: string, jsDocInfo: Comment.JsDocInfo) {
40    super(apiType);
41    this.setJsDocInfo(jsDocInfo);
42  }
43
44  setJsDocInfo(jsDocInfo: Comment.JsDocInfo): ApiInfo {
45    this.syscap = jsDocInfo.getSyscap();
46    this.since = jsDocInfo.getSince();
47    this.isForm = jsDocInfo.getIsForm();
48    this.isCrossPlatForm = jsDocInfo.getIsCrossPlatForm();
49    this.isSystemApi = jsDocInfo.getIsSystemApi();
50    this.isStageModelOnly = jsDocInfo.getModelLimitation().toLowerCase() === StringConstant.STAGE_MODEL_ONLY;
51    // jsDocInfo.getIsStageModelOnly();
52    this.isFaModelOnly = jsDocInfo.getModelLimitation().toLowerCase() === StringConstant.FA_MODEL_ONLY;
53    this.deprecatedVersion = jsDocInfo.getDeprecatedVersion();
54    this.useinstead = jsDocInfo.getUseinstead();
55    return this;
56  }
57
58  getSince(): string {
59    return this.since;
60  }
61
62  setName(name: string | undefined): ApiInfo {
63    if (!name) {
64      return this;
65    }
66    this.name = name;
67    return this;
68  }
69}
70
71export class DeclareConstInfo extends ApiInfo {
72  type: string = '';
73
74  setType(type: string): DeclareConstInfo {
75    this.type = type;
76    return this;
77  }
78}
79
80export class PropertyInfo extends ApiInfo {
81  type: string = '';
82  isReadOnly: boolean = false;
83  isRequired: boolean = false;
84  isStatic: boolean = false;
85  permission: string = '';
86
87  constructor(apiType: string, jsDocInfo: Comment.JsDocInfo) {
88    super(apiType, jsDocInfo);
89    this.setPermission(jsDocInfo.getPermission());
90  }
91
92  setType(type: string): PropertyInfo {
93    this.type = type;
94    return this;
95  }
96
97  setIsReadOnly(isReadOnly: boolean): PropertyInfo {
98    this.isReadOnly = isReadOnly;
99    return this;
100  }
101
102  setIsRequired(isRequired: boolean): PropertyInfo {
103    this.isRequired = isRequired;
104    return this;
105  }
106
107  setIsStatic(isStatic: boolean): PropertyInfo {
108    this.isStatic = isStatic;
109    return this;
110  }
111
112  setPermission(permission: string): PropertyInfo {
113    this.permission = permission;
114    return this;
115  }
116}
117
118export class ConstantInfo extends ApiInfo {
119  type: string = '';
120  value: string = '';
121
122  setType(type: string): ConstantInfo {
123    this.type = type;
124    return this;
125  }
126
127  setValue(value: string): ConstantInfo {
128    this.value = value;
129    return this;
130  }
131}
132
133export class UnionTypeInfo extends ApiInfo {
134  valueRange: string[] = [];
135
136  addValueRange(value: string): UnionTypeInfo {
137    this.valueRange.push(value);
138    return this;
139  }
140
141  addValueRanges(valueRange: string[]): UnionTypeInfo {
142    this.valueRange.push(...valueRange);
143    return this;
144  }
145}
146
147export class EnumValueInfo extends ApiInfo {
148  value: string = '';
149
150  setValue(value: string): EnumValueInfo {
151    this.value = value;
152    return this;
153  }
154}
155
156export class TypeAliasInfo extends ApiInfo {
157  type: string = '';
158
159  setType(type: string): TypeAliasInfo {
160    this.type = type;
161    return this;
162  }
163}
164
165export class MethodInfo extends ApiInfo {
166  callForm: string = '';
167  params: ParamInfo[] = [];
168  returnValue: string = '';
169  isStatic: boolean = false;
170  permission: string = '';
171  errorCodes: number[] = [];
172
173  constructor(apiType: string, jsDocInfo: Comment.JsDocInfo) {
174    super(apiType, jsDocInfo);
175    this.setPermission(jsDocInfo.getPermission());
176    this.setErrorCodes(jsDocInfo.getErrorCode());
177  }
178
179  setCallForm(callForm: string): MethodInfo {
180    this.callForm = callForm;
181    return this;
182  }
183
184  addParam(paramInfo: ParamInfo): MethodInfo {
185    this.params.push(paramInfo);
186    return this;
187  }
188
189  setReturnValue(returnValue: string): MethodInfo {
190    this.returnValue = returnValue;
191    return this;
192  }
193
194  setIsStatic(isStatic: boolean): MethodInfo {
195    this.isStatic = isStatic;
196    return this;
197  }
198
199  setPermission(permission: string): MethodInfo {
200    this.permission = permission;
201    return this;
202  }
203
204  setErrorCodes(errorCodes: number[]): MethodInfo {
205    this.errorCodes.push(...errorCodes);
206    return this;
207  }
208}
209
210export class ParamInfo extends ApiInfo {
211  type: string = '';
212  isRequired: boolean = false;
213
214  setType(type: string | undefined): void {
215    if (!type) {
216      return;
217    }
218    this.type = type;
219  }
220
221  setIsRequired(isRequired: boolean): void {
222    this.isRequired = isRequired;
223  }
224}
225
226export class NamespaceEnumInfo extends ApiInfo {
227  childApis: BasicApiInfo[] = [];
228
229  addChildApi(childApis: BasicApiInfo[]): NamespaceEnumInfo {
230    this.childApis.push(...childApis);
231    return this;
232  }
233}
234
235export class ClassInterfaceInfo extends NamespaceEnumInfo {
236  parentClasses: string[] = [];
237
238  setParentClasses(parentClasses: string[]): ClassInterfaceInfo {
239    this.parentClasses.push(...parentClasses);
240    return this;
241  }
242}
243
244export class ExportDefaultInfo extends BasicApiInfo {
245  name: string = '';
246
247  createObject(): ExportDefaultInfo {
248    return new ExportDefaultInfo(this.apiType);
249  }
250
251  setName(name: string): ExportDefaultInfo {
252    this.name = name;
253    return this;
254  }
255}
256
257export class ImportInfo extends BasicApiInfo {
258  importValues: Array<ExportImportValue> = [];
259
260  addImportValue(name: string, type: string): ImportInfo {
261    this.importValues.push({ key: name, value: type || name });
262    return this;
263  }
264}
265
266export interface NodeProcessorInterface {
267  (baseApiInfo: nodeBaseApiInfo): BasicApiInfo[];
268}
269