Skip to content

Commit

Permalink
🐳 refactor(GenerateDoc): Improved generated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
iohao committed Oct 31, 2024
1 parent 708000e commit c563cc5
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 57 deletions.
8 changes: 4 additions & 4 deletions BACKERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

| 称号 | 名单 |
| ------------- | -------------------------------- |
| 2个小星星 | 刘先生、wells974 |
| 2个小星星 | 刘先生、wells974、404 Not Found(342644552) |
| 1个小星星 | 金银花、子在川上(captainl1993@126.com|




##### 感谢支持

Alan、Y-g、angelhappyboy
Alan、Y-g、angelhappyboy、黑天小飞侠



Expand All @@ -41,7 +41,7 @@ Alan、Y-g、angelhappyboy

##### 感谢支持

butxx、玩皮猫、v-v、b-e、M-a、j-s、、森、葱花蛋炒饭
butxx、玩皮猫、v-v、b-e、M-a、j-s、漫步、森、葱花蛋炒饭、小许



Expand All @@ -52,7 +52,7 @@ butxx、玩皮猫、v-v、b-e、M-a、j-s、步、森、葱花蛋炒饭

| 称号 | 名单 |
| ------------- | -------------------------------- |
| 2个小星星 | 米斯特姚、WX768925736、猿、M-l |
| 2个小星星 | 米斯特姚、WX768925736、猿、Micheal |
| 1个小星星 | -称 |


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public final class ActionMethodDocument {
String bizDataName;
/** 方法参数的 */
String bizDataType;
String bizDataTypeSimple;
/** 方法参数的注释 */
String bizDataComment;
/** true 表示参数是 List 类型 */
Expand All @@ -59,6 +60,7 @@ public final class ActionMethodDocument {
boolean bizDataTypeIsInternal;
/** 参数类型(原始的,即使参数是 List,也会取泛型) */
String actualTypeName;
String actualTypeNameSimple;

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

boolean returnDataIsList;
/** true 表示协议碎片,false 表示开发者自定义的协议 */
Expand Down Expand Up @@ -117,11 +121,13 @@ 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) {
Expand All @@ -135,10 +141,12 @@ private void extractedParamInfo(ActionCommand.ParamInfo paramInfo, ActionCommand
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ 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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@
public final class TypeMappingRecord {
@Getter
String paramTypeName;
@Getter
String paramTypeNameSimple;

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

/** sdk 方法名 */
String ofMethodTypeName;
Expand All @@ -59,6 +63,10 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import lombok.ToString;

/**
* boolean 包装类
* boolean value
*
* @author 渔民小镇
* @date 2023-02-07
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.List;

/**
* boolean list 包装类
* boolean list
*
* @author 渔民小镇
* @date 2023-02-07
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import java.util.List;

/**
* 对象类型的包装类
* object
*
* @author 渔民小镇
* @date 2023-04-17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import lombok.ToString;

/**
* int 包装类
* int value
*
* @author 渔民小镇
* @date 2023-02-10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.List;

/**
* int list 包装类
* int list
*
* @author 渔民小镇
* @date 2023-02-10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import lombok.experimental.FieldDefaults;

/**
* long 包装类
* long value
*
* @author 渔民小镇
* @date 2023-02-10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.util.List;

/**
* long list 包装类
* long list
*
* @author 渔民小镇
* @date 2023-02-10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import lombok.ToString;

/**
* string 包装类
* string value
*
* @author 渔民小镇
* @date 2023-02-05
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.List;

/**
* string list 包装类
* string list
*
* @author 渔民小镇
* @date 2023-02-05
Expand Down
12 changes: 0 additions & 12 deletions widget/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
### 小部件

每个小部件解决业务中的一类问题;

```text
├── light-all
├── light-domain-event 领域事件
├── light-jprotobuf 生成 .proto 源文件
├── light-profile 多环境切换
└── light-timer-task 任务延时器
```


**内置多种可选模块,可按需选择,以方便应用开发:**

- [领域事件](https://www.yuque.com/iohao/game/gmfy1k)[disruptor](https://www.yuque.com/iohao/game/gmfy1k) 实现类似Spring事件驱动模型 ApplicationEvent)
- [任务延时器](https://www.yuque.com/iohao/game/niflk0) (将来某个时间可对任务进行执行、暂停、取消等操作,并不是类似 Quartz 的任务调度)
- [多环境切换](https://www.yuque.com/iohao/game/ekx6ve) (不同运行环境下的配置支持)
- [light-jprotobuf ](https://www.yuque.com/iohao/game/vpe2t6) (补足 jprotobuf 不能让多个对象在单个 .proto 源文件中生成的需求,并简化jprotobuf对源文件的注释)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* ioGame
* Copyright (C) 2021 - present 渔民小镇 (262610965@qq.com、luoyizhu@gmail.com) . All Rights Reserved.
* # iohao.com . 渔民小镇
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.iohao.game.widget.light.protobuf;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.UtilityClass;

import java.util.function.Function;

/**
* @author 渔民小镇
* @date 2024-10-31
* @since 21.20
*/
@UtilityClass
public final class ProtoGenerateSetting {
@Setter
@Getter
Function<FieldNameGenerate, String> fieldNameFunction = fieldNameGenerate -> {
if (fieldNameGenerate.isEnum()) {
return fieldNameGenerate.getFieldName();
}

// default UnderScoreCase
StringBuilder result = new StringBuilder();
String fieldName = fieldNameGenerate.getFieldName();

for (int i = 0; i < fieldName.length(); i++) {
char c = fieldName.charAt(i);
if (Character.isUpperCase(c)) {
if (i > 0) {
result.append('_');
}

result.append(Character.toLowerCase(c));
} else {
result.append(c);
}
}

return result.toString();
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private Map<String, String> createParam() {
FieldNameGenerate fieldNameGenerate = new FieldNameGenerate();
fieldNameGenerate.setEnumType(this.protoJavaParent.getClazz().isEnum());
fieldNameGenerate.setFieldName(this.fieldName);
messageMap.put("fieldName", GenerateFileKit.getFieldNameFunction().apply(fieldNameGenerate));
messageMap.put("fieldName", ProtoGenerateSetting.getFieldNameFunction().apply(fieldNameGenerate));

if (this.repeated) {
messageMap.put("repeated", "repeated ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@
package com.iohao.game.widget.light.protobuf.kit;

import com.iohao.game.common.kit.ArrayKit;
import com.iohao.game.widget.light.protobuf.FieldNameGenerate;
import com.iohao.game.widget.light.protobuf.ProtoGenerateFile;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.UtilityClass;

import java.io.File;
import java.util.function.Function;

/**
* proto 文件生成工具
Expand Down Expand Up @@ -82,31 +78,4 @@ public void generate(String protoPackagePath) {

generate(protoPackagePath, generateFolder);
}

@Setter
@Getter
Function<FieldNameGenerate, String> fieldNameFunction = fieldNameGenerate -> {
if (fieldNameGenerate.isEnum()) {
return fieldNameGenerate.getFieldName();
}

// default UnderScoreCase
StringBuilder result = new StringBuilder();
String fieldName = fieldNameGenerate.getFieldName();

for (int i = 0; i < fieldName.length(); i++) {
char c = fieldName.charAt(i);
if (Character.isUpperCase(c)) {
if (i > 0) {
result.append('_');
}

result.append(Character.toLowerCase(c));
} else {
result.append(c);
}
}

return result.toString();
};
}

0 comments on commit c563cc5

Please sign in to comment.