Private ServerMethodDefinition constructor; avoid create() in codegen
There is no need to use ServerMethodDefinition in codegen. The create()
method itself could be helpful to a dynamic HandlerRegistry
implementation, so we won't remove it.
diff --git a/compiler/src/java_plugin/cpp/java_generator.cpp b/compiler/src/java_plugin/cpp/java_generator.cpp
index 0c33201..e8f3e7c 100644
--- a/compiler/src/java_plugin/cpp/java_generator.cpp
+++ b/compiler/src/java_plugin/cpp/java_generator.cpp
@@ -452,8 +452,7 @@
"io.grpc.stub.ServerCalls.UnaryMethod";
}
}
- p->Print(*vars, ".addMethod($ServerMethodDefinition$.create(\n");
- p->Indent();
+ p->Print(*vars, ".addMethod(\n");
p->Indent();
p->Print(
*vars,
@@ -486,14 +485,13 @@
"}\n");
}
p->Outdent();
- p->Print("})))");
+ p->Print("}))");
if (i == service->method_count() - 1) {
p->Print(".build();");
}
p->Print("\n");
p->Outdent();
p->Outdent();
- p->Outdent();
}
p->Outdent();
p->Outdent();
diff --git a/compiler/src/test/golden/TestService.java.txt b/compiler/src/test/golden/TestService.java.txt
index 66021a7..e263f67 100644
--- a/compiler/src/test/golden/TestService.java.txt
+++ b/compiler/src/test/golden/TestService.java.txt
@@ -225,67 +225,67 @@
public static io.grpc.ServerServiceDefinition bindService(
final TestService serviceImpl) {
return io.grpc.ServerServiceDefinition.builder(SERVICE_NAME)
- .addMethod(io.grpc.ServerMethodDefinition.create(
- METHOD_UNARY_CALL,
- asyncUnaryCall(
- new io.grpc.stub.ServerCalls.UnaryMethod<
- io.grpc.testing.integration.Test.SimpleRequest,
- io.grpc.testing.integration.Test.SimpleResponse>() {
- @java.lang.Override
- public void invoke(
- io.grpc.testing.integration.Test.SimpleRequest request,
- io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.SimpleResponse> responseObserver) {
- serviceImpl.unaryCall(request, responseObserver);
- }
- })))
- .addMethod(io.grpc.ServerMethodDefinition.create(
- METHOD_STREAMING_OUTPUT_CALL,
- asyncServerStreamingCall(
- new io.grpc.stub.ServerCalls.ServerStreamingMethod<
- io.grpc.testing.integration.Test.StreamingOutputCallRequest,
- io.grpc.testing.integration.Test.StreamingOutputCallResponse>() {
- @java.lang.Override
- public void invoke(
- io.grpc.testing.integration.Test.StreamingOutputCallRequest request,
- io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingOutputCallResponse> responseObserver) {
- serviceImpl.streamingOutputCall(request, responseObserver);
- }
- })))
- .addMethod(io.grpc.ServerMethodDefinition.create(
- METHOD_STREAMING_INPUT_CALL,
- asyncClientStreamingCall(
- new io.grpc.stub.ServerCalls.ClientStreamingMethod<
- io.grpc.testing.integration.Test.StreamingInputCallRequest,
- io.grpc.testing.integration.Test.StreamingInputCallResponse>() {
- @java.lang.Override
- public io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingInputCallRequest> invoke(
- io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingInputCallResponse> responseObserver) {
- return serviceImpl.streamingInputCall(responseObserver);
- }
- })))
- .addMethod(io.grpc.ServerMethodDefinition.create(
- METHOD_FULL_BIDI_CALL,
- asyncBidiStreamingCall(
- new io.grpc.stub.ServerCalls.BidiStreamingMethod<
- io.grpc.testing.integration.Test.StreamingOutputCallRequest,
- io.grpc.testing.integration.Test.StreamingOutputCallResponse>() {
- @java.lang.Override
- public io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingOutputCallRequest> invoke(
- io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingOutputCallResponse> responseObserver) {
- return serviceImpl.fullBidiCall(responseObserver);
- }
- })))
- .addMethod(io.grpc.ServerMethodDefinition.create(
- METHOD_HALF_BIDI_CALL,
- asyncBidiStreamingCall(
- new io.grpc.stub.ServerCalls.BidiStreamingMethod<
- io.grpc.testing.integration.Test.StreamingOutputCallRequest,
- io.grpc.testing.integration.Test.StreamingOutputCallResponse>() {
- @java.lang.Override
- public io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingOutputCallRequest> invoke(
- io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingOutputCallResponse> responseObserver) {
- return serviceImpl.halfBidiCall(responseObserver);
- }
- }))).build();
+ .addMethod(
+ METHOD_UNARY_CALL,
+ asyncUnaryCall(
+ new io.grpc.stub.ServerCalls.UnaryMethod<
+ io.grpc.testing.integration.Test.SimpleRequest,
+ io.grpc.testing.integration.Test.SimpleResponse>() {
+ @java.lang.Override
+ public void invoke(
+ io.grpc.testing.integration.Test.SimpleRequest request,
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.SimpleResponse> responseObserver) {
+ serviceImpl.unaryCall(request, responseObserver);
+ }
+ }))
+ .addMethod(
+ METHOD_STREAMING_OUTPUT_CALL,
+ asyncServerStreamingCall(
+ new io.grpc.stub.ServerCalls.ServerStreamingMethod<
+ io.grpc.testing.integration.Test.StreamingOutputCallRequest,
+ io.grpc.testing.integration.Test.StreamingOutputCallResponse>() {
+ @java.lang.Override
+ public void invoke(
+ io.grpc.testing.integration.Test.StreamingOutputCallRequest request,
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingOutputCallResponse> responseObserver) {
+ serviceImpl.streamingOutputCall(request, responseObserver);
+ }
+ }))
+ .addMethod(
+ METHOD_STREAMING_INPUT_CALL,
+ asyncClientStreamingCall(
+ new io.grpc.stub.ServerCalls.ClientStreamingMethod<
+ io.grpc.testing.integration.Test.StreamingInputCallRequest,
+ io.grpc.testing.integration.Test.StreamingInputCallResponse>() {
+ @java.lang.Override
+ public io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingInputCallRequest> invoke(
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingInputCallResponse> responseObserver) {
+ return serviceImpl.streamingInputCall(responseObserver);
+ }
+ }))
+ .addMethod(
+ METHOD_FULL_BIDI_CALL,
+ asyncBidiStreamingCall(
+ new io.grpc.stub.ServerCalls.BidiStreamingMethod<
+ io.grpc.testing.integration.Test.StreamingOutputCallRequest,
+ io.grpc.testing.integration.Test.StreamingOutputCallResponse>() {
+ @java.lang.Override
+ public io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingOutputCallRequest> invoke(
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingOutputCallResponse> responseObserver) {
+ return serviceImpl.fullBidiCall(responseObserver);
+ }
+ }))
+ .addMethod(
+ METHOD_HALF_BIDI_CALL,
+ asyncBidiStreamingCall(
+ new io.grpc.stub.ServerCalls.BidiStreamingMethod<
+ io.grpc.testing.integration.Test.StreamingOutputCallRequest,
+ io.grpc.testing.integration.Test.StreamingOutputCallResponse>() {
+ @java.lang.Override
+ public io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingOutputCallRequest> invoke(
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.Test.StreamingOutputCallResponse> responseObserver) {
+ return serviceImpl.halfBidiCall(responseObserver);
+ }
+ })).build();
}
}
diff --git a/compiler/src/test/golden/TestServiceNano.java.txt b/compiler/src/test/golden/TestServiceNano.java.txt
index ea6df13..4012e40 100644
--- a/compiler/src/test/golden/TestServiceNano.java.txt
+++ b/compiler/src/test/golden/TestServiceNano.java.txt
@@ -287,67 +287,67 @@
public static io.grpc.ServerServiceDefinition bindService(
final TestService serviceImpl) {
return io.grpc.ServerServiceDefinition.builder(SERVICE_NAME)
- .addMethod(io.grpc.ServerMethodDefinition.create(
- METHOD_UNARY_CALL,
- asyncUnaryCall(
- new io.grpc.stub.ServerCalls.UnaryMethod<
- io.grpc.testing.integration.nano.Test.SimpleRequest,
- io.grpc.testing.integration.nano.Test.SimpleResponse>() {
- @java.lang.Override
- public void invoke(
- io.grpc.testing.integration.nano.Test.SimpleRequest request,
- io.grpc.stub.StreamObserver<io.grpc.testing.integration.nano.Test.SimpleResponse> responseObserver) {
- serviceImpl.unaryCall(request, responseObserver);
- }
- })))
- .addMethod(io.grpc.ServerMethodDefinition.create(
- METHOD_STREAMING_OUTPUT_CALL,
- asyncServerStreamingCall(
- new io.grpc.stub.ServerCalls.ServerStreamingMethod<
- io.grpc.testing.integration.nano.Test.StreamingOutputCallRequest,
- io.grpc.testing.integration.nano.Test.StreamingOutputCallResponse>() {
- @java.lang.Override
- public void invoke(
- io.grpc.testing.integration.nano.Test.StreamingOutputCallRequest request,
- io.grpc.stub.StreamObserver<io.grpc.testing.integration.nano.Test.StreamingOutputCallResponse> responseObserver) {
- serviceImpl.streamingOutputCall(request, responseObserver);
- }
- })))
- .addMethod(io.grpc.ServerMethodDefinition.create(
- METHOD_STREAMING_INPUT_CALL,
- asyncClientStreamingCall(
- new io.grpc.stub.ServerCalls.ClientStreamingMethod<
- io.grpc.testing.integration.nano.Test.StreamingInputCallRequest,
- io.grpc.testing.integration.nano.Test.StreamingInputCallResponse>() {
- @java.lang.Override
- public io.grpc.stub.StreamObserver<io.grpc.testing.integration.nano.Test.StreamingInputCallRequest> invoke(
- io.grpc.stub.StreamObserver<io.grpc.testing.integration.nano.Test.StreamingInputCallResponse> responseObserver) {
- return serviceImpl.streamingInputCall(responseObserver);
- }
- })))
- .addMethod(io.grpc.ServerMethodDefinition.create(
- METHOD_FULL_BIDI_CALL,
- asyncBidiStreamingCall(
- new io.grpc.stub.ServerCalls.BidiStreamingMethod<
- io.grpc.testing.integration.nano.Test.StreamingOutputCallRequest,
- io.grpc.testing.integration.nano.Test.StreamingOutputCallResponse>() {
- @java.lang.Override
- public io.grpc.stub.StreamObserver<io.grpc.testing.integration.nano.Test.StreamingOutputCallRequest> invoke(
- io.grpc.stub.StreamObserver<io.grpc.testing.integration.nano.Test.StreamingOutputCallResponse> responseObserver) {
- return serviceImpl.fullBidiCall(responseObserver);
- }
- })))
- .addMethod(io.grpc.ServerMethodDefinition.create(
- METHOD_HALF_BIDI_CALL,
- asyncBidiStreamingCall(
- new io.grpc.stub.ServerCalls.BidiStreamingMethod<
- io.grpc.testing.integration.nano.Test.StreamingOutputCallRequest,
- io.grpc.testing.integration.nano.Test.StreamingOutputCallResponse>() {
- @java.lang.Override
- public io.grpc.stub.StreamObserver<io.grpc.testing.integration.nano.Test.StreamingOutputCallRequest> invoke(
- io.grpc.stub.StreamObserver<io.grpc.testing.integration.nano.Test.StreamingOutputCallResponse> responseObserver) {
- return serviceImpl.halfBidiCall(responseObserver);
- }
- }))).build();
+ .addMethod(
+ METHOD_UNARY_CALL,
+ asyncUnaryCall(
+ new io.grpc.stub.ServerCalls.UnaryMethod<
+ io.grpc.testing.integration.nano.Test.SimpleRequest,
+ io.grpc.testing.integration.nano.Test.SimpleResponse>() {
+ @java.lang.Override
+ public void invoke(
+ io.grpc.testing.integration.nano.Test.SimpleRequest request,
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.nano.Test.SimpleResponse> responseObserver) {
+ serviceImpl.unaryCall(request, responseObserver);
+ }
+ }))
+ .addMethod(
+ METHOD_STREAMING_OUTPUT_CALL,
+ asyncServerStreamingCall(
+ new io.grpc.stub.ServerCalls.ServerStreamingMethod<
+ io.grpc.testing.integration.nano.Test.StreamingOutputCallRequest,
+ io.grpc.testing.integration.nano.Test.StreamingOutputCallResponse>() {
+ @java.lang.Override
+ public void invoke(
+ io.grpc.testing.integration.nano.Test.StreamingOutputCallRequest request,
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.nano.Test.StreamingOutputCallResponse> responseObserver) {
+ serviceImpl.streamingOutputCall(request, responseObserver);
+ }
+ }))
+ .addMethod(
+ METHOD_STREAMING_INPUT_CALL,
+ asyncClientStreamingCall(
+ new io.grpc.stub.ServerCalls.ClientStreamingMethod<
+ io.grpc.testing.integration.nano.Test.StreamingInputCallRequest,
+ io.grpc.testing.integration.nano.Test.StreamingInputCallResponse>() {
+ @java.lang.Override
+ public io.grpc.stub.StreamObserver<io.grpc.testing.integration.nano.Test.StreamingInputCallRequest> invoke(
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.nano.Test.StreamingInputCallResponse> responseObserver) {
+ return serviceImpl.streamingInputCall(responseObserver);
+ }
+ }))
+ .addMethod(
+ METHOD_FULL_BIDI_CALL,
+ asyncBidiStreamingCall(
+ new io.grpc.stub.ServerCalls.BidiStreamingMethod<
+ io.grpc.testing.integration.nano.Test.StreamingOutputCallRequest,
+ io.grpc.testing.integration.nano.Test.StreamingOutputCallResponse>() {
+ @java.lang.Override
+ public io.grpc.stub.StreamObserver<io.grpc.testing.integration.nano.Test.StreamingOutputCallRequest> invoke(
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.nano.Test.StreamingOutputCallResponse> responseObserver) {
+ return serviceImpl.fullBidiCall(responseObserver);
+ }
+ }))
+ .addMethod(
+ METHOD_HALF_BIDI_CALL,
+ asyncBidiStreamingCall(
+ new io.grpc.stub.ServerCalls.BidiStreamingMethod<
+ io.grpc.testing.integration.nano.Test.StreamingOutputCallRequest,
+ io.grpc.testing.integration.nano.Test.StreamingOutputCallResponse>() {
+ @java.lang.Override
+ public io.grpc.stub.StreamObserver<io.grpc.testing.integration.nano.Test.StreamingOutputCallRequest> invoke(
+ io.grpc.stub.StreamObserver<io.grpc.testing.integration.nano.Test.StreamingOutputCallResponse> responseObserver) {
+ return serviceImpl.halfBidiCall(responseObserver);
+ }
+ })).build();
}
}