mirror of
https://gitee.com/openharmony/interface_sdk-js
synced 2024-10-07 14:13:45 +00:00
适配interface和class中的属性,添加typename
Signed-off-by: wangcaoyu <wangcaoyu@huawei.com>
This commit is contained in:
parent
958e5cb450
commit
3143c398cc
@ -441,6 +441,7 @@ function detectionApi(options: OptionObjType): ToolNameValueType {
|
||||
const error = exception as Error;
|
||||
LogUtil.e(`error collect`, error.stack ? error.stack : error.message);
|
||||
} finally {
|
||||
LogUtil.i(`detection run over`, buffer.toString());
|
||||
}
|
||||
return {
|
||||
data: [],
|
||||
|
@ -49,6 +49,7 @@ import {
|
||||
ParserParam,
|
||||
FileTag,
|
||||
TypeParamInfo,
|
||||
TypeLocationInfo,
|
||||
} from '../../typedef/parser/ApiInfoDefination';
|
||||
import { Comment } from '../../typedef/parser/Comment';
|
||||
import { StringUtils } from '../../utils/StringUtils';
|
||||
@ -578,6 +579,14 @@ export class NodeProcessorHelper {
|
||||
ModifierHelper.processModifiers(propertyNode.modifiers, propertyInfo);
|
||||
propertyInfo.setIsRequired(!propertyNode.questionToken ? true : false);
|
||||
propertyInfo.addType(NodeProcessorHelper.processDataType(propertyNode.type));
|
||||
if (Boolean(process.env.NEED_DETECTION) && propertyNode.type) {
|
||||
NodeProcessorHelper.processFunctionTypeNode(
|
||||
propertyNode.type,
|
||||
propertyInfo,
|
||||
new ParamInfo(ApiType.PARAM),
|
||||
false
|
||||
);
|
||||
}
|
||||
propertyInfo.setTypeKind(propertyNode.type ? propertyNode.type.kind : -1);
|
||||
return propertyInfo;
|
||||
}
|
||||
@ -744,7 +753,7 @@ export class NodeProcessorHelper {
|
||||
*/
|
||||
static processFunctionTypeNode(
|
||||
typeNode: ts.TypeNode,
|
||||
methodInfo: MethodInfo,
|
||||
methodInfo: MethodInfo | PropertyInfo,
|
||||
paramInfo: ParamInfo,
|
||||
isParam: boolean = true
|
||||
): void {
|
||||
@ -780,7 +789,7 @@ export class NodeProcessorHelper {
|
||||
*/
|
||||
static processFunctionTypeReference(
|
||||
typeNode: ts.TypeReferenceNode,
|
||||
methodInfo: MethodInfo,
|
||||
methodInfo: MethodInfo | PropertyInfo,
|
||||
paramInfo: ParamInfo,
|
||||
isParam: boolean = true
|
||||
): void {
|
||||
@ -821,12 +830,13 @@ export class NodeProcessorHelper {
|
||||
if (jsDocInfos.length === 0) {
|
||||
return;
|
||||
}
|
||||
const jsDoc: Comment.JsDocInfo = jsDocInfos[jsDocInfos.length - 1];
|
||||
jsDoc.removeTags();
|
||||
const typeLocationInfo: TypeLocationInfo = jsDocInfos[jsDocInfos.length - 1] as TypeLocationInfo;
|
||||
typeLocationInfo.removeTags();
|
||||
new TypeLocationInfo().setTypeName.apply(typeLocationInfo, [typeNode.getFullText().trim()]);
|
||||
if (isParam) {
|
||||
paramInfo.addTypeLocations(jsDoc);
|
||||
paramInfo.addTypeLocations(typeLocationInfo);
|
||||
} else {
|
||||
methodInfo.addTypeLocations(jsDoc);
|
||||
methodInfo.addTypeLocations(typeLocationInfo);
|
||||
}
|
||||
} catch (error) {
|
||||
} finally {
|
||||
@ -846,7 +856,7 @@ export class NodeProcessorHelper {
|
||||
*/
|
||||
static processFunctionTypeObject(
|
||||
typeObject: ts.TypeLiteralNode,
|
||||
methodInfo: MethodInfo,
|
||||
methodInfo: MethodInfo | PropertyInfo,
|
||||
paramInfo: ParamInfo,
|
||||
isParam: boolean = true
|
||||
): void {
|
||||
@ -861,12 +871,11 @@ export class NodeProcessorHelper {
|
||||
if (jsDocInfos.length === 0) {
|
||||
return;
|
||||
}
|
||||
const jsDoc: Comment.JsDocInfo = jsDocInfos[jsDocInfos.length - 1];
|
||||
jsDoc.removeTags();
|
||||
const typeLocationInfo: TypeLocationInfo = jsDocInfos[jsDocInfos.length - 1] as TypeLocationInfo;
|
||||
if (isParam) {
|
||||
paramInfo.addObjLocations(jsDoc);
|
||||
paramInfo.addObjLocations(typeLocationInfo);
|
||||
} else {
|
||||
methodInfo.addObjLocations(jsDoc);
|
||||
methodInfo.addObjLocations(typeLocationInfo);
|
||||
}
|
||||
if (ts.isPropertySignature(member) && member.type) {
|
||||
NodeProcessorHelper.processFunctionTypeNode(member.type, methodInfo, paramInfo, isParam);
|
||||
|
@ -468,6 +468,8 @@ export class PropertyInfo extends ApiInfo {
|
||||
isRequired: boolean = false; // 属性是否为必选
|
||||
isStatic: boolean = false; // 属性是否为静态
|
||||
typeKind: ts.SyntaxKind = -1; //type类型的kind值
|
||||
typeLocations: TypeLocationInfo[] = []; // 参数、返回值的JsDoc信息
|
||||
objLocations: TypeLocationInfo[] = []; // 匿名类型的JsDoc信息
|
||||
|
||||
addType(type: string[]): void {
|
||||
this.type.push(...type);
|
||||
@ -508,6 +510,22 @@ export class PropertyInfo extends ApiInfo {
|
||||
getTypeKind(): ts.SyntaxKind {
|
||||
return this.typeKind;
|
||||
}
|
||||
|
||||
addTypeLocations(typeLocation: TypeLocationInfo): void {
|
||||
this.typeLocations.push(typeLocation);
|
||||
}
|
||||
|
||||
getTypeLocations(): TypeLocationInfo[] {
|
||||
return this.typeLocations;
|
||||
}
|
||||
|
||||
addObjLocations(ObjLocation: TypeLocationInfo): void {
|
||||
this.objLocations.push(ObjLocation);
|
||||
}
|
||||
|
||||
getObjLocations(): TypeLocationInfo[] {
|
||||
return this.objLocations;
|
||||
}
|
||||
}
|
||||
|
||||
export class ConstantInfo extends ApiInfo {
|
||||
@ -626,8 +644,8 @@ export class MethodInfo extends ApiInfo {
|
||||
isStatic: boolean = false; // 方法是否是静态
|
||||
sync: string = ''; //同步函数标志
|
||||
returnValueType: ts.SyntaxKind = -1;
|
||||
typeLocations: Comment.JsDocInfo[] = []; // 参数、返回值的JsDoc信息
|
||||
objLocations: Comment.JsDocInfo[] = []; // 匿名类型的JsDoc信息
|
||||
typeLocations: TypeLocationInfo[] = []; // 参数、返回值的JsDoc信息
|
||||
objLocations: TypeLocationInfo[] = []; // 匿名类型的JsDoc信息
|
||||
|
||||
setCallForm(callForm: string): void {
|
||||
this.callForm = callForm;
|
||||
@ -669,19 +687,19 @@ export class MethodInfo extends ApiInfo {
|
||||
return this.isStatic;
|
||||
}
|
||||
|
||||
addTypeLocations(typeLocation: Comment.JsDocInfo): void {
|
||||
addTypeLocations(typeLocation: TypeLocationInfo): void {
|
||||
this.typeLocations.push(typeLocation);
|
||||
}
|
||||
|
||||
getTypeLocations(): Comment.JsDocInfo[] {
|
||||
getTypeLocations(): TypeLocationInfo[] {
|
||||
return this.typeLocations;
|
||||
}
|
||||
|
||||
addObjLocations(ObjLocation: Comment.JsDocInfo): void {
|
||||
addObjLocations(ObjLocation: TypeLocationInfo): void {
|
||||
this.objLocations.push(ObjLocation);
|
||||
}
|
||||
|
||||
getObjLocations(): Comment.JsDocInfo[] {
|
||||
getObjLocations(): TypeLocationInfo[] {
|
||||
return this.objLocations;
|
||||
}
|
||||
|
||||
@ -694,6 +712,18 @@ export class MethodInfo extends ApiInfo {
|
||||
}
|
||||
}
|
||||
|
||||
export class TypeLocationInfo extends Comment.JsDocInfo {
|
||||
typeName: string = '';//当前类型名称
|
||||
|
||||
getTypeName(): string {
|
||||
return this.typeName;
|
||||
}
|
||||
|
||||
setTypeName(typeName: string): void {
|
||||
this.typeName = typeName;
|
||||
}
|
||||
}
|
||||
|
||||
export class ParamInfo {
|
||||
apiType: string = ''; // api的类型为方法参数
|
||||
apiName: string = ''; // 参数名
|
||||
@ -701,8 +731,8 @@ export class ParamInfo {
|
||||
type: string[] = []; // 参数的类型
|
||||
isRequired: boolean = false; // 参数是否必选
|
||||
definedText: string = '';
|
||||
typeLocations: Comment.JsDocInfo[] = []; // 参数、返回值的JsDoc信息
|
||||
objLocations: Comment.JsDocInfo[] = []; // 匿名类型的JsDoc信息
|
||||
typeLocations: TypeLocationInfo[] = []; // 参数、返回值的JsDoc信息
|
||||
objLocations: TypeLocationInfo[] = []; // 匿名类型的JsDoc信息
|
||||
|
||||
constructor(apiType: string) {
|
||||
this.apiType = apiType;
|
||||
@ -752,19 +782,19 @@ export class ParamInfo {
|
||||
return this.definedText;
|
||||
}
|
||||
|
||||
addTypeLocations(typeLocation: Comment.JsDocInfo): void {
|
||||
addTypeLocations(typeLocation: TypeLocationInfo): void {
|
||||
this.typeLocations.push(typeLocation);
|
||||
}
|
||||
|
||||
getTypeLocations(): Comment.JsDocInfo[] {
|
||||
getTypeLocations(): TypeLocationInfo[] {
|
||||
return this.typeLocations;
|
||||
}
|
||||
|
||||
addObjLocations(ObjLocation: Comment.JsDocInfo): void {
|
||||
addObjLocations(ObjLocation: TypeLocationInfo): void {
|
||||
this.objLocations.push(ObjLocation);
|
||||
}
|
||||
|
||||
getObjLocations(): Comment.JsDocInfo[] {
|
||||
getObjLocations(): TypeLocationInfo[] {
|
||||
return this.objLocations;
|
||||
}
|
||||
}
|
||||
@ -881,7 +911,7 @@ export class ParserParam {
|
||||
compilerHost.resolveModuleNames = (moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ts.ResolvedProjectReference | undefined, compilerOptions: ts.CompilerOptions) => {
|
||||
return moduleNames.map(moduleName => {
|
||||
if (process.env.IS_OH === 'true') {
|
||||
return undefined;
|
||||
return ts.resolveModuleName(moduleName, containingFile, compilerOptions, compilerHost).resolvedModule;
|
||||
}
|
||||
const value: ts.ResolvedModule = {
|
||||
resolvedFileName: '',
|
||||
|
Loading…
Reference in New Issue
Block a user