Skip to content

Commit d3e6279

Browse files
committed
allow empty java package and proto package
1 parent 02162e8 commit d3e6279

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

protoc-gen-java-optional-test/src/test/resources/no-package-type.proto renamed to protoc-gen-java-optional-test/src/test/resources/no-packages-type.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ syntax = "proto3";
33
option java_multiple_files = true;
44
option java_package = "org.test.datatypes";
55

6-
message NoPackageTestMessage {
6+
message NoProtoPackageTestMessage {
77
message NestedTestMessage {
88
string string = 1;
99
optional string optional_string = 2;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
syntax = "proto3";
2+
3+
option java_multiple_files = true;
4+
5+
message NoPackagesTestMessage {
6+
message NestedTestMessage {
7+
string string = 1;
8+
optional string optional_string = 2;
9+
}
10+
}
11+

protoc-gen-java-optional/src/main/java/org/grpcmock/protoc/plugin/OptionalGenerator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ private Stream<File> handleMessage(
103103
String protoPackage,
104104
String javaPackage
105105
) {
106-
String filePath = javaPackage.replace(".", DIR_SEPARATOR) + DIR_SEPARATOR + fileName + JAVA_EXTENSION;
107-
String fullMethodName = (protoPackage.isEmpty() ? "" : (protoPackage + ".")) + messageDescriptor.getName();
106+
String javaPackagePath = javaPackage.isEmpty() ? "" : javaPackage.replace(".", DIR_SEPARATOR) + DIR_SEPARATOR;
107+
String protoPackagePath = protoPackage.isEmpty() ? "" : protoPackage + ".";
108+
String filePath = javaPackagePath + fileName + JAVA_EXTENSION;
109+
String fullMethodName = protoPackagePath + messageDescriptor.getName();
108110

109111
return Stream.concat(
110112
handleSingleMessage(messageDescriptor, filePath, fullMethodName),

0 commit comments

Comments
 (0)