Skip to content

Commit

Permalink
perf(doc): GameCode Support single parameter construction method
Browse files Browse the repository at this point in the history
  • Loading branch information
iohao committed Dec 14, 2024
1 parent 13cc3d7 commit 233bc98
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.io.File;
import java.net.URL;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;

/**
Expand Down Expand Up @@ -122,19 +123,28 @@ record AnalyseJavaClassRecord(boolean exists, JavaClass javaClass) {
: path.replace("build/classes", "src/main/java");
};

private final AtomicInteger gameCodeOrdinal = new AtomicInteger(0);

private List<ErrorCodeDocument> analyseErrorCodeDocument(JavaClass javaClass) {
return javaClass.getFields().stream().map(field -> {
String name = field.getName();
List<Expression> enumConstantArguments = field.getEnumConstantArguments();
if (CollKit.isEmpty(enumConstantArguments) || enumConstantArguments.size() != 2) {
if (CollKit.isEmpty(enumConstantArguments)) {
return null;
}

int gameCode = 0;
if (enumConstantArguments.size() == 1) {
gameCode = gameCodeOrdinal.getAndIncrement();
} else if (enumConstantArguments.size() == 2) {
Object enumValue = enumConstantArguments.getFirst().getParameterValue();
gameCode = Integer.parseInt(enumValue.toString());
}

String name = field.getName();

ErrorCodeDocument errorCodeDocument = new ErrorCodeDocument();
errorCodeDocument.setName(name);

Object enumValue = enumConstantArguments.getFirst().getParameterValue();
errorCodeDocument.setValue(Integer.parseInt(enumValue.toString()));
errorCodeDocument.setValue(gameCode);

String description = enumConstantArguments.getLast().getParameterValue().toString();
description = description.substring(1, description.length() - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ public void addBroadcastDocument(BroadcastDocument broadcastDocument) {
IoGameDocumentHelper.broadcastDocumentList.add(broadcastDocument);
}

/**
* 添加广播文档
*
* @param broadcastDocumentBuilder broadcastDocumentBuilder
*/
public void addBroadcastDocument(BroadcastDocumentBuilder broadcastDocumentBuilder) {
addBroadcastDocument(broadcastDocumentBuilder.build());
}

/**
* 获取 ActionDoc,如果 ActionDoc 不存在则创建
*
Expand Down

0 comments on commit 233bc98

Please sign in to comment.