Add Abstract{ServiceName} class in compiled service class
diff --git a/compiler/src/java_plugin/cpp/java_generator.cpp b/compiler/src/java_plugin/cpp/java_generator.cpp
index cf8cdbe..fc8f472 100644
--- a/compiler/src/java_plugin/cpp/java_generator.cpp
+++ b/compiler/src/java_plugin/cpp/java_generator.cpp
@@ -642,6 +642,27 @@
p->Print("}\n");
}
+static void PrintAbstractServiceClass(const ServiceDescriptor* service,
+ map<string, string>* vars,
+ Printer* p) {
+ p->Print(
+ *vars,
+ "public static abstract class Abstract$service_name$"
+ " implements $service_name$, $BindableService$ {\n");
+ p->Indent();
+ p->Print(*vars,
+ "@Override public $ServerServiceDefinition$ bindService() {\n"
+ );
+ p->Indent();
+ p->Print(*vars,
+ "return $service_class_name$.bindService(this);\n"
+ );
+ p->Outdent();
+ p->Print("}\n");
+ p->Outdent();
+ p->Print("}\n\n");
+}
+
static void PrintService(const ServiceDescriptor* service,
map<string, string>* vars,
Printer* p,
@@ -704,6 +725,7 @@
PrintStub(service, vars, p, ASYNC_CLIENT_IMPL, generate_nano);
PrintStub(service, vars, p, BLOCKING_CLIENT_IMPL, generate_nano);
PrintStub(service, vars, p, FUTURE_CLIENT_IMPL, generate_nano);
+ PrintAbstractServiceClass(service, vars, p);
PrintMethodHandlerClass(service, vars, p, generate_nano);
PrintBindServiceMethod(service, vars, p, generate_nano);
p->Outdent();
@@ -754,6 +776,7 @@
vars["MethodType"] = "io.grpc.MethodDescriptor.MethodType";
vars["ServerMethodDefinition"] =
"io.grpc.ServerMethodDefinition";
+ vars["BindableService"] = "io.grpc.stub.BindableService";
vars["ServerServiceDefinition"] =
"io.grpc.ServerServiceDefinition";
vars["AbstractStub"] = "io.grpc.stub.AbstractStub";
diff --git a/compiler/src/test/golden/TestService.java.txt b/compiler/src/test/golden/TestService.java.txt
index e025d21..4f19fde 100644
--- a/compiler/src/test/golden/TestService.java.txt
+++ b/compiler/src/test/golden/TestService.java.txt
@@ -224,6 +224,12 @@
}
}
+ public static abstract class AbstractTestService implements TestService, io.grpc.stub.BindableService {
+ @Override public io.grpc.ServerServiceDefinition bindService() {
+ return TestServiceGrpc.bindService(this);
+ }
+ }
+
private static final int METHODID_UNARY_CALL = 0;
private static final int METHODID_STREAMING_OUTPUT_CALL = 1;
private static final int METHODID_STREAMING_INPUT_CALL = 2;
diff --git a/compiler/src/testLite/golden/TestService.java.txt b/compiler/src/testLite/golden/TestService.java.txt
index c46ee56..da72d6f 100644
--- a/compiler/src/testLite/golden/TestService.java.txt
+++ b/compiler/src/testLite/golden/TestService.java.txt
@@ -224,6 +224,12 @@
}
}
+ public static abstract class AbstractTestService implements TestService, io.grpc.stub.BindableService {
+ @Override public io.grpc.ServerServiceDefinition bindService() {
+ return TestServiceGrpc.bindService(this);
+ }
+ }
+
private static final int METHODID_UNARY_CALL = 0;
private static final int METHODID_STREAMING_OUTPUT_CALL = 1;
private static final int METHODID_STREAMING_INPUT_CALL = 2;
diff --git a/compiler/src/testNano/golden/TestService.java.txt b/compiler/src/testNano/golden/TestService.java.txt
index 5c37877..3aacbf8 100644
--- a/compiler/src/testNano/golden/TestService.java.txt
+++ b/compiler/src/testNano/golden/TestService.java.txt
@@ -302,6 +302,12 @@
}
}
+ public static abstract class AbstractTestService implements TestService, io.grpc.stub.BindableService {
+ @Override public io.grpc.ServerServiceDefinition bindService() {
+ return TestServiceGrpc.bindService(this);
+ }
+ }
+
private static final int METHODID_UNARY_CALL = 0;
private static final int METHODID_STREAMING_OUTPUT_CALL = 1;
private static final int METHODID_STREAMING_INPUT_CALL = 2;