From ec17790ed911dbe203ab754d45d77f7ae446d21e Mon Sep 17 00:00:00 2001 From: godotg Date: Sun, 3 Dec 2023 11:03:26 +0800 Subject: [PATCH] perf[protobuf]: generate pojo from proto --- .../protobuf/builder/JavaBuilder.java | 16 ++++----- .../serializer/protobuf/wire/Field.java | 36 ------------------- 2 files changed, 7 insertions(+), 45 deletions(-) diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/builder/JavaBuilder.java b/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/builder/JavaBuilder.java index 66637f863..062cfef7e 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/builder/JavaBuilder.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/builder/JavaBuilder.java @@ -33,12 +33,11 @@ public class JavaBuilder { } - public String getJavaType(Field field, List imps) { + public String getJavaType(Field field) { String type = field.getTypeString(); if (field instanceof MapField) { MapField mf = (MapField) field; - type = "Map<" + getJavaType(mf.getKey().value()) + ", " - + getJavaType(mf.getValue()) + ">"; + type = "Map<" + getJavaType(mf.getKey().value()) + ", " + getJavaType(mf.getValue()) + ">"; return type; } if (!BASE_TYPES.contains(type.toLowerCase(Locale.ENGLISH))) { @@ -78,17 +77,16 @@ private void buildMsgImps(ProtoMessage msg, List tmp, List imps) var fields = msg.getFields(); if (CollectionUtils.isNotEmpty(fields)) { for (var field : fields) { - getJavaType(field, imps); + getJavaType(field); tmp.add(field); } } for (int i = 0; i < tmp.size(); i++) { if (tmp.get(i) instanceof MapField) { - addImport(imps, "java.util.Map"); + addImport(imps, Map.class.getName()); } else if (tmp.get(i).getCardinality() == Field.Cardinality.REPEATED) { - addImport(imps, "java.util.List"); - addImport(imps, "java.util.ArrayList"); + addImport(imps, List.class.getName()); } } } @@ -155,7 +153,7 @@ public String buildMessage(Proto proto, ProtoMessage msg, int indent, Map