Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

过滤private field不翻译 #151

Merged
merged 2 commits into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/interpret-cli/src/transfer/bean/to-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function toField(
fieldProps: IJFieldPropers,
intepretHandle: IntepretHandle,
): Promise<PropertySignatureStructure> {
log('转换 为属性:%o', fieldProps);
log('转换 %s 为属性:%o', fieldName, fieldProps);

let type = await jType2Ts(fieldProps, intepretHandle);
return {
Expand Down
39 changes: 25 additions & 14 deletions packages/interpret-cli/src/transfer/bean/to-vo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export async function toBeanClass(

if (typeDef.typeParams) {
typeDef.typeParams.forEach(typeParamsItem => {
typeParameters.push({name: typeParamsItem.name+" extends { __fields2java?(): any } = any",});
typeParameters.push({
name: typeParamsItem.name + ' extends { __fields2java?(): any } = any',
});
});
}
//获取 方法定义; 或者获取属性定义
Expand All @@ -62,21 +64,30 @@ export async function toBeanClass(
if (typeDef.fields[fieldName].isArray) {
filedType = typeDef.fields[fieldName].elementType.name;
}
const regex = new RegExp(
`^(get|set)${fieldName[0].toUpperCase()}${fieldName.slice(1)}$`,
);
if (
typeDef.privateFields.indexOf(fieldName) !== -1 && // 在privateField中
Object.keys(typeDef.methods || {}).findIndex(n => regex.test(n)) === -1 // 并且没有getter和setter
) {
continue; // 跳过不翻译
}

let field = await toField(
fieldName,
typeDef.fields[fieldName],
intepretHandle,
);
properties.push(field);
ctorParams.push({name: field.name, type: field.type});
let field = await toField(
fieldName,
typeDef.fields[fieldName],
intepretHandle,
);
properties.push(field);
ctorParams.push({name: field.name, type: field.type});

let filedItem = typeDef.fields[fieldName];
fileds.push({
name: fieldName,
type: await jType2Ts(filedItem, intepretHandle),
filedAst: filedItem,
});
let filedItem = typeDef.fields[fieldName];
fileds.push({
name: fieldName,
type: await jType2Ts(filedItem, intepretHandle),
filedAst: filedItem,
});
}
//添加构造函数入参interface
//1.2 生成方法;;
Expand Down