Skip to content

Commit

Permalink
🐳 refactor(GenerateDoc): Simplify doc
Browse files Browse the repository at this point in the history
  • Loading branch information
iohao committed Nov 5, 2024
1 parent 4adfe94 commit 7fbebd6
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,14 @@ public final class ActionMethodDocument {
String bizDataName;
/** 方法参数的 */
String bizDataType;
String bizDataTypeSimple;
/** 方法参数的注释 */
String bizDataComment;
/** true 表示参数是 List 类型 */
boolean bizDataTypeIsList;
/** true 表示协议碎片,false 表示开发者自定义的协议 */
boolean bizDataTypeIsInternal;
boolean internalBizDataType;
/** 参数类型(原始的,即使参数是 List,也会取泛型) */
String actualTypeName;
String actualTypeNameSimple;

/** 使用的路由成员变量名 */
String memberCmdName;
Expand All @@ -71,10 +69,8 @@ public final class ActionMethodDocument {
/** 方法返回值的注释 */
String returnComment;
String returnDataName;
String returnDataNameSimple;
/** 返回值类型(原始的,即使参数是 List,也会取泛型) */
String returnDataActualTypeName;
String returnDataActualTypeNameSimple;

boolean returnDataIsList;
/** true 表示协议碎片,false 表示开发者自定义的协议 */
Expand Down Expand Up @@ -121,35 +117,31 @@ private void extractedReturnInfo(ActionCommand actionCommand) {
Class<?> returnTypeClazz = returnInfo.getActualTypeArgumentClazz();
var typeMappingRecord = typeMappingDocument.getTypeMappingRecord(returnTypeClazz);
this.returnDataName = typeMappingRecord.getParamTypeName();
this.returnDataNameSimple = typeMappingRecord.getParamTypeNameSimple();
this.returnDataTypeIsInternal = typeMappingRecord.isInternalType();
this.resultMethodTypeName = typeMappingRecord.getResultMethodTypeName();
this.resultMethodListTypeName = typeMappingRecord.getResultMethodListTypeName();

this.returnDataActualTypeName = typeMappingRecord.getParamTypeName();
this.returnDataActualTypeNameSimple = typeMappingRecord.getParamTypeNameSimple();
}

private void extractedParamInfo(ActionCommand.ParamInfo paramInfo, ActionCommandDoc actionCommandDoc) {
Class<?> actualTypeArgumentClazz = paramInfo.getActualTypeArgumentClazz();
// 方法参数类型
var typeMappingRecord = this.typeMappingDocument.getTypeMappingRecord(actualTypeArgumentClazz);
this.bizDataTypeIsList = paramInfo.isList();
this.bizDataTypeIsInternal = typeMappingRecord.isInternalType();
this.internalBizDataType = typeMappingRecord.isInternalType();

// sdk 方法名
this.sdkMethodName = typeMappingRecord.getOfMethodTypeName(this.bizDataTypeIsList);

this.bizDataType = typeMappingRecord.getParamTypeName(this.bizDataTypeIsList);
this.bizDataTypeSimple = typeMappingRecord.getParamTypeNameSimple(this.bizDataTypeIsList);
this.bizDataName = paramInfo.getName();
this.bizDataComment = actionCommandDoc.getMethodParamComment();

this.actualTypeName = typeMappingRecord.getParamTypeName();
this.actualTypeNameSimple = typeMappingRecord.getParamTypeNameSimple();
}

ActionCommand.ParamInfo getBizParam(ActionCommand actionCommand) {
private ActionCommand.ParamInfo getBizParam(ActionCommand actionCommand) {
return actionCommand.streamParamInfo()
// 只处理业务参数
.filter(ActionCommand.ParamInfo::isBizData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,13 @@ public final class BroadcastDocument {
boolean dataIsList;

String bizDataType;
String bizDataTypeSimple;

/** sdk result get 方法名 */
String resultMethodTypeName;
/** sdk result get list 方法名 */
String resultMethodListTypeName;

String dataActualTypeName;
String dataActualTypeNameSimple;

String exampleCode;
String exampleCodeAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,7 @@
public interface TypeMappingDocument {
Map<Class<?>, TypeMappingRecord> getMap();

default TypeMappingRecord getTypeMappingRecord(Class<?> protoTypeClazz) {
var map = getMap();
if (map.containsKey(protoTypeClazz)) {
return map.get(protoTypeClazz);
}

String simpleName = protoTypeClazz.getSimpleName();

return new TypeMappingRecord()
.setInternalType(false)
.setParamTypeName(simpleName).setListParamTypeName("List<%s>".formatted(simpleName))
.setOfMethodTypeName("").setOfMethodListTypeName("ValueList");
}
TypeMappingRecord getTypeMappingRecord(Class<?> protoTypeClazz);

default void mapping(TypeMappingRecord record, List<Class<?>> clazzList) {
for (Class<?> clazz : clazzList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,8 @@
public final class TypeMappingRecord {
@Getter
String paramTypeName;
@Getter
String paramTypeNameSimple;

/** list 参数类型名 */
String listParamTypeName;
String listParamTypeNameSimple;

/** sdk 方法名 */
String ofMethodTypeName;
/** sdk list 参数的方法名 */
Expand All @@ -63,10 +58,6 @@ public String getParamTypeName(boolean isList) {
return isList ? listParamTypeName : paramTypeName;
}

public String getParamTypeNameSimple(boolean isList) {
return isList ? listParamTypeNameSimple : paramTypeNameSimple;
}

public String getOfMethodTypeName(boolean isList) {
return isList ? ofMethodListTypeName : ofMethodTypeName;
}
Expand Down

0 comments on commit 7fbebd6

Please sign in to comment.