mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-08-23 18:25:50 +00:00
fix[note]: class note indented
This commit is contained in:
@@ -25,6 +25,8 @@ import com.zfoo.protocol.util.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.zfoo.protocol.util.StringUtils.TAB;
|
||||
|
||||
/**
|
||||
* EN: When generating the protocol, the document comments and field comments of the protocol will use this class
|
||||
* CN: 生成协议的时候,协议的文档注释和字段注释会使用这个类
|
||||
@@ -55,15 +57,19 @@ public abstract class GenerateProtocolNote {
|
||||
protocolNoteMap = null;
|
||||
}
|
||||
|
||||
public static String classNote(short protocolId, CodeLanguage language) {
|
||||
public static String classNote(short protocolId, CodeLanguage language, String tab, int deep) {
|
||||
var protocolNote = protocolNoteMap.get(protocolId);
|
||||
var classNote = protocolNote.getKey();
|
||||
if (StringUtils.isBlank(classNote)) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
classNote = formatNote(language, classNote);
|
||||
return classNote;
|
||||
var multipleLineNotes = classNote.split(FileUtils.LS_REGEX);
|
||||
var notes = new ArrayList<String>();
|
||||
for(var oneLineNote : multipleLineNotes) {
|
||||
var formatFieldNote = formatNote(language, oneLineNote);
|
||||
notes.add(tab.repeat(Math.max(0, deep)) + formatFieldNote);
|
||||
}
|
||||
return StringUtils.joinWith(FileUtils.LS, notes.toArray());
|
||||
}
|
||||
|
||||
public static List<String> fieldNotes(short protocolId, String fieldName, CodeLanguage language) {
|
||||
|
||||
@@ -129,7 +129,7 @@ public abstract class GenerateCppUtils {
|
||||
// protocol object
|
||||
var defineProtocolName = protocolClazzName.toUpperCase();
|
||||
var includeHeaders = includeSubProtocol(registration);
|
||||
var classNote = GenerateProtocolNote.classNote(protocolId, CodeLanguage.Cpp);
|
||||
var classNote = GenerateProtocolNote.classNote(protocolId, CodeLanguage.Cpp, TAB, 1);
|
||||
var fieldDefinition = fieldDefinition(registration);
|
||||
var valueOfMethod = valueOfMethod(registration);
|
||||
var operator = operator(registration);
|
||||
|
||||
@@ -118,7 +118,7 @@ public abstract class GenerateCsUtils {
|
||||
/**
|
||||
* 生成协议类
|
||||
*/
|
||||
public static void createCsProtocolFile(ProtocolRegistration registration) throws IOException {
|
||||
public static void createCsProtocolFile(ProtocolRegistration registration) {
|
||||
GenerateProtocolFile.index.set(0);
|
||||
|
||||
var protocolId = registration.protocolId();
|
||||
@@ -127,7 +127,7 @@ public abstract class GenerateCsUtils {
|
||||
|
||||
var protocolTemplate = ClassUtils.getFileFromClassPathToString("csharp/ProtocolTemplate.cs");
|
||||
|
||||
var classNote = GenerateProtocolNote.classNote(protocolId, CodeLanguage.CSharp);
|
||||
var classNote = GenerateProtocolNote.classNote(protocolId, CodeLanguage.CSharp, TAB, 1);
|
||||
var fieldDefinition = fieldDefinition(registration);
|
||||
var writeObject = writeObject(registration);
|
||||
var readObject = readObject(registration);
|
||||
|
||||
@@ -117,7 +117,7 @@ public abstract class GenerateGdUtils {
|
||||
var protocolClazzName = registrationConstructor.getDeclaringClass().getSimpleName();
|
||||
|
||||
var includeSubProtocol = includeSubProtocol(registration);
|
||||
var classNote = GenerateProtocolNote.classNote(protocolId, CodeLanguage.GdScript);
|
||||
var classNote = GenerateProtocolNote.classNote(protocolId, CodeLanguage.GdScript, TAB_ASCII, 0);
|
||||
var fieldDefinition = fieldDefinition(registration);
|
||||
var toStringJsonTemplate = toStringJsonTemplate(registration);
|
||||
var toStringParams = toStringParams(registration);
|
||||
|
||||
@@ -117,7 +117,7 @@ public abstract class GenerateGoUtils {
|
||||
: ClassUtils.getFileFromClassPathToString("go/ProtocolTemplate.go");
|
||||
|
||||
|
||||
var classNote = GenerateProtocolNote.classNote(protocolId, CodeLanguage.Go);
|
||||
var classNote = GenerateProtocolNote.classNote(protocolId, CodeLanguage.Go, TAB, 0);
|
||||
var fieldDefinition = fieldDefinition(registration);
|
||||
var writeObject = writeObject(registration);
|
||||
var readObject = readObject(registration);
|
||||
|
||||
@@ -118,7 +118,7 @@ public abstract class GenerateJsUtils {
|
||||
|
||||
var protocolTemplate = ClassUtils.getFileFromClassPathToString("javascript/ProtocolTemplate.js");
|
||||
|
||||
var classNote = GenerateProtocolNote.classNote(protocolId, CodeLanguage.JavaScript);
|
||||
var classNote = GenerateProtocolNote.classNote(protocolId, CodeLanguage.JavaScript, TAB, 0);
|
||||
var fieldDefinition = fieldDefinition(registration);
|
||||
var writeObject = writeObject(registration);
|
||||
var readObject = readObject(registration);
|
||||
|
||||
@@ -124,7 +124,7 @@ public abstract class GenerateLuaUtils {
|
||||
var protocolClazzName = registrationConstructor.getDeclaringClass().getSimpleName();
|
||||
GenerateProtocolFile.index.set(0);
|
||||
|
||||
var classNote = GenerateProtocolNote.classNote(protocolId, CodeLanguage.Lua);
|
||||
var classNote = GenerateProtocolNote.classNote(protocolId, CodeLanguage.Lua, TAB, 0);
|
||||
var valueOfMethod = valueOfMethod(registration);
|
||||
var writePacket = writePacket(registration);
|
||||
var readPacket = readPacket(registration);
|
||||
@@ -211,7 +211,7 @@ public abstract class GenerateLuaUtils {
|
||||
var protocolClazzName = registrationConstructor.getDeclaringClass().getSimpleName();
|
||||
var protocolTemplate = ClassUtils.getFileFromClassPathToString("lua/ProtocolTemplate.lua");
|
||||
|
||||
var classNote = GenerateProtocolNote.classNote(protocolId, CodeLanguage.Lua);
|
||||
var classNote = GenerateProtocolNote.classNote(protocolId, CodeLanguage.Lua, TAB, 0);
|
||||
var valueOfMethod = valueOfMethod(registration);
|
||||
var writePacket = writePacket(registration);
|
||||
var readPacket = readPacket(registration);
|
||||
|
||||
@@ -119,7 +119,7 @@ public abstract class GeneratePyUtils {
|
||||
|
||||
var protocolTemplate = ClassUtils.getFileFromClassPathToString("python/ProtocolTemplate.py");
|
||||
|
||||
var classNote = GenerateProtocolNote.classNote(protocolId, CodeLanguage.Python);
|
||||
var classNote = GenerateProtocolNote.classNote(protocolId, CodeLanguage.Python, TAB, 0);
|
||||
var fieldDefinition = fieldDefinition(registration);
|
||||
var writeObject = writeObject(registration);
|
||||
var readObject = readObject(registration);
|
||||
|
||||
@@ -122,7 +122,7 @@ public abstract class GenerateTsUtils {
|
||||
var protocolTemplate = ClassUtils.getFileFromClassPathToString("typescript/ProtocolTemplate.ts");
|
||||
|
||||
var importSubProtocol = importSubProtocol(registration);
|
||||
var classNote = GenerateProtocolNote.classNote(protocolId, CodeLanguage.TypeScript);
|
||||
var classNote = GenerateProtocolNote.classNote(protocolId, CodeLanguage.TypeScript, TAB, 0);
|
||||
var fieldDefinition = fieldDefinition(registration);
|
||||
var writeObject = writeObject(registration);
|
||||
var readObject = readObject(registration);
|
||||
@@ -141,7 +141,7 @@ public abstract class GenerateTsUtils {
|
||||
// import IByteBuffer first
|
||||
var importBuilder = new StringBuilder();
|
||||
var protocolPath = GenerateProtocolPath.getProtocolPath(protocolId);
|
||||
if (StringUtils.isEmpty(protocolPath) ) {
|
||||
if (StringUtils.isEmpty(protocolPath)) {
|
||||
importBuilder.append(StringUtils.format("import IByteBuffer from './IByteBuffer';")).append(LS);
|
||||
} else {
|
||||
var splits = protocolPath.split(StringUtils.PERIOD_REGEX);
|
||||
@@ -175,7 +175,7 @@ public abstract class GenerateTsUtils {
|
||||
var fieldName = field.getName();
|
||||
// 生成注释
|
||||
var fieldNotes = GenerateProtocolNote.fieldNotes(protocolId, fieldName, CodeLanguage.TypeScript);
|
||||
for(var fieldNote : fieldNotes) {
|
||||
for (var fieldNote : fieldNotes) {
|
||||
fieldDefinitionBuilder.append(TAB).append(fieldNote).append(LS);
|
||||
}
|
||||
var triple = tsSerializer(fieldRegistration.serializer()).field(field, fieldRegistration);
|
||||
@@ -215,7 +215,7 @@ public abstract class GenerateTsUtils {
|
||||
if (field.isAnnotationPresent(Compatible.class)) {
|
||||
tsBuilder.append(TAB + TAB).append("if (buffer.compatibleRead(beforeReadIndex, length)) {").append(LS);
|
||||
var compatibleReadObject = tsSerializer(fieldRegistration.serializer()).readObject(tsBuilder, 3, field, fieldRegistration);
|
||||
tsBuilder.append(TAB + TAB+ TAB).append(StringUtils.format("packet.{} = {};", field.getName(), compatibleReadObject)).append(LS);
|
||||
tsBuilder.append(TAB + TAB + TAB).append(StringUtils.format("packet.{} = {};", field.getName(), compatibleReadObject)).append(LS);
|
||||
tsBuilder.append(TAB + TAB).append("}").append(LS);
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user