From 370b1f588db916edfe811e8514f02aafcc0fbbc1 Mon Sep 17 00:00:00 2001 From: godotg Date: Thu, 1 Feb 2024 10:50:54 +0800 Subject: [PATCH] fix[note]: the first line of a multi-line note is not indented --- .../generate/GenerateProtocolNote.java | 24 +++++++++++-------- .../serializer/cpp/GenerateCppUtils.java | 6 ++--- .../serializer/csharp/GenerateCsUtils.java | 4 ++-- .../serializer/gdscript/GenerateGdUtils.java | 4 ++-- .../serializer/go/GenerateGoUtils.java | 6 ++--- .../javascript/GenerateJsUtils.java | 4 ++-- .../serializer/lua/GenerateLuaUtils.java | 4 ++-- .../serializer/python/GeneratePyUtils.java | 4 ++-- .../typescript/GenerateTsUtils.java | 4 ++-- 9 files changed, 32 insertions(+), 28 deletions(-) diff --git a/protocol/src/main/java/com/zfoo/protocol/generate/GenerateProtocolNote.java b/protocol/src/main/java/com/zfoo/protocol/generate/GenerateProtocolNote.java index 84686ac5c..368ea959f 100644 --- a/protocol/src/main/java/com/zfoo/protocol/generate/GenerateProtocolNote.java +++ b/protocol/src/main/java/com/zfoo/protocol/generate/GenerateProtocolNote.java @@ -21,11 +21,10 @@ import com.zfoo.protocol.registration.ProtocolRegistration; import com.zfoo.protocol.serializer.CodeLanguage; import com.zfoo.protocol.util.AssertionUtils; +import com.zfoo.protocol.util.FileUtils; import com.zfoo.protocol.util.StringUtils; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * EN: When generating the protocol, the document comments and field comments of the protocol will use this class @@ -68,15 +67,20 @@ public static String classNote(short protocolId, CodeLanguage language) { return classNote; } - public static String fieldNote(short protocolId, String fieldName, CodeLanguage language) { + public static List fieldNote(short protocolId, String fieldName, CodeLanguage language) { var protocolNote = protocolNoteMap.get(protocolId); var fieldNoteMap = protocolNote.getValue(); var fieldNote = fieldNoteMap.get(fieldName); if (StringUtils.isBlank(fieldNote)) { - return StringUtils.EMPTY; + return Collections.emptyList(); } - fieldNote = formatNote(language, fieldNote); - return fieldNote; + var multipleLineNotes = fieldNote.split(FileUtils.LS_REGEX); + var notes = new ArrayList(); + for(var oneLineNote : multipleLineNotes) { + var formatFieldNote = formatNote(language, oneLineNote); + notes.add(formatFieldNote); + } + return notes; } private static String formatNote(CodeLanguage language, String fieldNote) { @@ -87,14 +91,14 @@ private static String formatNote(CodeLanguage language, String fieldNote) { case TypeScript: case CSharp: case Protobuf: - fieldNote = StringUtils.format("// {}", fieldNote).replace("\n", "\n// "); + fieldNote = StringUtils.format("// {}", fieldNote); break; case Lua: - fieldNote = StringUtils.format("-- {}", fieldNote).replace("\n", "\n-- "); + fieldNote = StringUtils.format("-- {}", fieldNote); break; case Python: case GdScript: - fieldNote = StringUtils.format("# {}", fieldNote).replace("\n", "\n# "); + fieldNote = StringUtils.format("# {}", fieldNote); break; case Enhance: default: diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/cpp/GenerateCppUtils.java b/protocol/src/main/java/com/zfoo/protocol/serializer/cpp/GenerateCppUtils.java index fd7a447ce..c080c3ad3 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/cpp/GenerateCppUtils.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/cpp/GenerateCppUtils.java @@ -189,9 +189,9 @@ private static String fieldDefinition(ProtocolRegistration registration) { var propertyFullName = StringUtils.format("{} {};", propertyType, propertyName); // 生成注释 - var filedNote = GenerateProtocolNote.fieldNote(protocolId, fieldName, CodeLanguage.Cpp); - if (StringUtils.isNotBlank(filedNote)) { - cppBuilder.append(TAB + TAB).append(filedNote).append(LS); + var fieldNotes = GenerateProtocolNote.fieldNote(protocolId, fieldName, CodeLanguage.Cpp); + for(var fieldNote : fieldNotes) { + cppBuilder.append(TAB + TAB).append(fieldNote).append(LS); } cppBuilder.append(TAB + TAB).append(propertyFullName).append(LS); } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/csharp/GenerateCsUtils.java b/protocol/src/main/java/com/zfoo/protocol/serializer/csharp/GenerateCsUtils.java index 7a3469a66..9e3a3e732 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/csharp/GenerateCsUtils.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/csharp/GenerateCsUtils.java @@ -157,8 +157,8 @@ private static String fieldDefinition(ProtocolRegistration registration) { var propertyType = toCsClassName(field.getGenericType().getTypeName()); var propertyFullName = StringUtils.format("public {} {};", propertyType, fieldName); // 生成注释 - var fieldNote = GenerateProtocolNote.fieldNote(protocolId, fieldName, CodeLanguage.CSharp); - if (StringUtils.isNotBlank(fieldNote)) { + var fieldNotes = GenerateProtocolNote.fieldNote(protocolId, fieldName, CodeLanguage.CSharp); + for(var fieldNote : fieldNotes) { csBuilder.append(TAB + TAB).append(fieldNote).append(LS); } csBuilder.append(TAB + TAB).append(propertyFullName).append(LS); diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/gdscript/GenerateGdUtils.java b/protocol/src/main/java/com/zfoo/protocol/serializer/gdscript/GenerateGdUtils.java index 51df366f3..42f5f6d4c 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/gdscript/GenerateGdUtils.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/gdscript/GenerateGdUtils.java @@ -162,8 +162,8 @@ private static String fieldDefinition(ProtocolRegistration registration) { IFieldRegistration fieldRegistration = fieldRegistrations[GenerateProtocolFile.indexOf(fields, field)]; var fieldName = field.getName(); // 生成注释 - var fieldNote = GenerateProtocolNote.fieldNote(protocolId, fieldName, CodeLanguage.GdScript); - if (StringUtils.isNotBlank(fieldNote)) { + var fieldNotes = GenerateProtocolNote.fieldNote(protocolId, fieldName, CodeLanguage.GdScript); + for(var fieldNote : fieldNotes) { gdBuilder.append(fieldNote).append(LS); } var fieldType = gdSerializer(fieldRegistration.serializer()).fieldType(field, fieldRegistration); diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/go/GenerateGoUtils.java b/protocol/src/main/java/com/zfoo/protocol/serializer/go/GenerateGoUtils.java index 5e906468d..105ea5ba9 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/go/GenerateGoUtils.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/go/GenerateGoUtils.java @@ -151,9 +151,9 @@ private static String fieldDefinition(ProtocolRegistration registration) { var propertyFullName = StringUtils.format("{} {}", fieldName, fieldType); // 生成注释 - var filedNote = GenerateProtocolNote.fieldNote(protocolId, fieldName, CodeLanguage.Go); - if (StringUtils.isNotBlank(filedNote)) { - goBuilder.append(TAB).append(filedNote).append(LS); + var fieldNotes = GenerateProtocolNote.fieldNote(protocolId, fieldName, CodeLanguage.Go); + for(var fieldNote : fieldNotes) { + goBuilder.append(TAB).append(fieldNote).append(LS); } goBuilder.append(TAB).append(propertyFullName).append(LS); } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/javascript/GenerateJsUtils.java b/protocol/src/main/java/com/zfoo/protocol/serializer/javascript/GenerateJsUtils.java index 2e064a24d..e21864f04 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/javascript/GenerateJsUtils.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/javascript/GenerateJsUtils.java @@ -143,8 +143,8 @@ private static String fieldDefinition(ProtocolRegistration registration) { var fieldRegistration = fieldRegistrations[GenerateProtocolFile.indexOf(fields, field)]; var fieldName = field.getName(); // 生成注释 - var fieldNote = GenerateProtocolNote.fieldNote(protocolId, fieldName, CodeLanguage.JavaScript); - if (StringUtils.isNotBlank(fieldNote)) { + var fieldNotes = GenerateProtocolNote.fieldNote(protocolId, fieldName, CodeLanguage.JavaScript); + for(var fieldNote : fieldNotes) { fieldDefinitionBuilder.append(TAB).append(fieldNote).append(LS); } var triple = jsSerializer(fieldRegistration.serializer()).field(field, fieldRegistration); diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/lua/GenerateLuaUtils.java b/protocol/src/main/java/com/zfoo/protocol/serializer/lua/GenerateLuaUtils.java index d50373ad0..4f0b7f300 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/lua/GenerateLuaUtils.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/lua/GenerateLuaUtils.java @@ -238,8 +238,8 @@ private static String valueOfMethod(ProtocolRegistration registration) { var fieldRegistration = fieldRegistrations[i]; var fieldName = field.getName(); // 生成注释 - var fieldNote = GenerateProtocolNote.fieldNote(protocolId, fieldName, CodeLanguage.Lua); - if (StringUtils.isNotBlank(fieldNote)) { + var fieldNotes = GenerateProtocolNote.fieldNote(protocolId, fieldName, CodeLanguage.Lua); + for(var fieldNote : fieldNotes) { luaBuilder.append(TAB + TAB).append(fieldNote).append(LS); } var fieldDefaultValue = luaSerializer(fieldRegistration.serializer()).fieldDefaultValue(field, fieldRegistration); diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/python/GeneratePyUtils.java b/protocol/src/main/java/com/zfoo/protocol/serializer/python/GeneratePyUtils.java index 79315adb4..0231b577f 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/python/GeneratePyUtils.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/python/GeneratePyUtils.java @@ -143,8 +143,8 @@ private static String fieldDefinition(ProtocolRegistration registration) { var fieldRegistration = fieldRegistrations[GenerateProtocolFile.indexOf(fields, field)]; var fieldName = field.getName(); // 生成注释 - var fieldNote = GenerateProtocolNote.fieldNote(protocolId, fieldName, CodeLanguage.Python); - if (StringUtils.isNotBlank(fieldNote)) { + var fieldNotes = GenerateProtocolNote.fieldNote(protocolId, fieldName, CodeLanguage.Python); + for(var fieldNote : fieldNotes) { pyBuilder.append(TAB).append(fieldNote).append(LS); } var fieldDefaultValue = pySerializer(fieldRegistration.serializer()).fieldDefaultValue(field, fieldRegistration); diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/typescript/GenerateTsUtils.java b/protocol/src/main/java/com/zfoo/protocol/serializer/typescript/GenerateTsUtils.java index 4eb35ab9e..0ca7b1b43 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/typescript/GenerateTsUtils.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/typescript/GenerateTsUtils.java @@ -174,8 +174,8 @@ private static String fieldDefinition(ProtocolRegistration registration) { var fieldRegistration = fieldRegistrations[GenerateProtocolFile.indexOf(fields, field)]; var fieldName = field.getName(); // 生成注释 - var fieldNote = GenerateProtocolNote.fieldNote(protocolId, fieldName, CodeLanguage.TypeScript); - if (StringUtils.isNotBlank(fieldNote)) { + var fieldNotes = GenerateProtocolNote.fieldNote(protocolId, fieldName, CodeLanguage.TypeScript); + for(var fieldNote : fieldNotes) { fieldDefinitionBuilder.append(TAB).append(fieldNote).append(LS); } var triple = tsSerializer(fieldRegistration.serializer()).field(field, fieldRegistration);