Skip to content

Commit e397c4a

Browse files
committed
fix(protobuf): handle same package proto type reference
The change improves the field proto type string generation logic by checking if the field's proto class is in the same package as the parent proto class. When they share the same package, only the class name is used instead of the full qualified name (package.className), making the generated proto files cleaner and more idiomatic.
1 parent d74db38 commit e397c4a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

widget/light-jprotobuf/src/main/java/com/iohao/game/widget/light/protobuf/ProtoJavaAnalyse.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,13 @@ private String fieldProtoTypeToString(ProtoJavaField protoJavaField, Class<?> fi
209209
ProtoJavaRegionKey regionKey = protoJavaParent.getProtoJavaRegionKey();
210210
ProtoJavaRegion protoJavaRegion = this.getProtoJavaRegion(regionKey);
211211
protoJavaRegion.addOtherProtoFile(protoJavaFieldType);
212-
// 不在同一个文件中
213-
fieldProtoType = StrKit.format("{}.{}", filePackage, className);
212+
if (Objects.equals(protoJavaParent.getFilePackage(), filePackage)) {
213+
// 不在同一个文件夹,但是在同一个包下
214+
fieldProtoType = className;
215+
} else {
216+
// 不在同一个文件中
217+
fieldProtoType = StrKit.format("{}.{}", filePackage, className);
218+
}
214219
}
215220

216221
return fieldProtoType;

0 commit comments

Comments
 (0)