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, ParentClass } 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 this.isFaModelOnly = jsDocInfo.getModelLimitation().toLowerCase() === StringConstant.FA_MODEL_ONLY; 52 this.deprecatedVersion = jsDocInfo.getDeprecatedVersion(); 53 this.useinstead = jsDocInfo.getUseinstead(); 54 return this; 55 } 56 57 getSince(): string { 58 return this.since; 59 } 60 61 setName(name: string | undefined): ApiInfo { 62 if (!name) { 63 return this; 64 } 65 this.name = name; 66 return this; 67 } 68} 69 70export class DeclareConstInfo extends ApiInfo { 71 type: string = ''; 72 73 setType(type: string): DeclareConstInfo { 74 this.type = type; 75 return this; 76 } 77} 78 79export class PropertyInfo extends ApiInfo { 80 type: string = ''; 81 isReadOnly: boolean = false; 82 isRequired: boolean = false; 83 isStatic: boolean = false; 84 permission: string = ''; 85 86 constructor(apiType: string, jsDocInfo: Comment.JsDocInfo) { 87 super(apiType, jsDocInfo); 88 this.setPermission(jsDocInfo.getPermission()); 89 } 90 91 setType(type: string): PropertyInfo { 92 this.type = type; 93 return this; 94 } 95 96 setIsReadOnly(isReadOnly: boolean): PropertyInfo { 97 this.isReadOnly = isReadOnly; 98 return this; 99 } 100 101 setIsRequired(isRequired: boolean): PropertyInfo { 102 this.isRequired = isRequired; 103 return this; 104 } 105 106 setIsStatic(isStatic: boolean): PropertyInfo { 107 this.isStatic = isStatic; 108 return this; 109 } 110 111 setPermission(permission: string): PropertyInfo { 112 this.permission = permission; 113 return this; 114 } 115} 116 117export class ConstantInfo extends ApiInfo { 118 type: string = ''; 119 value: string = ''; 120 121 setType(type: string): ConstantInfo { 122 this.type = type; 123 return this; 124 } 125 126 setValue(value: string): ConstantInfo { 127 this.value = value; 128 return this; 129 } 130} 131 132export class UnionTypeInfo extends ApiInfo { 133 valueRange: string[] = []; 134 135 addValueRange(value: string): UnionTypeInfo { 136 this.valueRange.push(value); 137 return this; 138 } 139 140 addValueRanges(valueRange: string[]): UnionTypeInfo { 141 this.valueRange.push(...valueRange); 142 return this; 143 } 144} 145 146export class EnumValueInfo extends ApiInfo { 147 value: string = ''; 148 149 setValue(value: string): EnumValueInfo { 150 this.value = value; 151 return this; 152 } 153} 154 155export class TypeAliasInfo extends ApiInfo { 156 type: string = ''; 157 158 setType(type: string): TypeAliasInfo { 159 this.type = type; 160 return this; 161 } 162} 163 164export class MethodInfo extends ApiInfo { 165 callForm: string = ''; 166 params: ParamInfo[] = []; 167 returnValue: string = ''; 168 isStatic: boolean = false; 169 permission: string = ''; 170 errorCodes: number[] = []; 171 172 constructor(apiType: string, jsDocInfo: Comment.JsDocInfo) { 173 super(apiType, jsDocInfo); 174 this.setPermission(jsDocInfo.getPermission()); 175 this.setErrorCodes(jsDocInfo.getErrorCode()); 176 } 177 178 setCallForm(callForm: string): MethodInfo { 179 this.callForm = callForm; 180 return this; 181 } 182 183 addParam(paramInfo: ParamInfo): MethodInfo { 184 this.params.push(paramInfo); 185 return this; 186 } 187 188 setReturnValue(returnValue: string): MethodInfo { 189 this.returnValue = returnValue; 190 return this; 191 } 192 193 setIsStatic(isStatic: boolean): MethodInfo { 194 this.isStatic = isStatic; 195 return this; 196 } 197 198 setPermission(permission: string): MethodInfo { 199 this.permission = permission; 200 return this; 201 } 202 203 setErrorCodes(errorCodes: number[]): MethodInfo { 204 this.errorCodes.push(...errorCodes); 205 return this; 206 } 207} 208 209export class ParamInfo extends ApiInfo { 210 type: string = ''; 211 isRequired: boolean = false; 212 213 setType(type: string | undefined): void { 214 if (!type) { 215 return; 216 } 217 this.type = type; 218 } 219 220 setIsRequired(isRequired: boolean): void { 221 this.isRequired = isRequired; 222 } 223} 224 225export class NamespaceEnumInfo extends ApiInfo { 226 childApis: BasicApiInfo[] = []; 227 228 addChildApi(childApis: BasicApiInfo[]): NamespaceEnumInfo { 229 this.childApis.push(...childApis); 230 return this; 231 } 232} 233 234export class ClassInterfaceInfo extends NamespaceEnumInfo { 235 parentClasses: ParentClass[] = []; 236 237 setParentClasses(parentClasses: ParentClass[]): ClassInterfaceInfo { 238 this.parentClasses.push(...parentClasses); 239 return this; 240 } 241} 242 243export class ExportDefaultInfo extends BasicApiInfo { 244 name: string = ''; 245 246 createObject(): ExportDefaultInfo { 247 return new ExportDefaultInfo(this.apiType); 248 } 249 250 setName(name: string): ExportDefaultInfo { 251 this.name = name; 252 return this; 253 } 254} 255 256export class ImportInfo extends BasicApiInfo { 257 importValues: Array<ExportImportValue> = []; 258 259 addImportValue(name: string, type: string): ImportInfo { 260 this.importValues.push({ key: name, value: type || name }); 261 return this; 262 } 263} 264 265export interface NodeProcessorInterface { 266 (baseApiInfo: nodeBaseApiInfo): BasicApiInfo[]; 267} 268