compiler: deprecate interfaces and add ImplBase in codegen
first step to address issue #1469:
- leave and deprecate interfaces in codegen
- introduce `ServiceImplBase`,
- `AbstractService` is deprecated and extends `ServiceImplBase`
- static `bindService()` is deprecated
diff --git a/compiler/src/java_plugin/cpp/java_generator.cpp b/compiler/src/java_plugin/cpp/java_generator.cpp
index 292a6cf..a992c34 100644
--- a/compiler/src/java_plugin/cpp/java_generator.cpp
+++ b/compiler/src/java_plugin/cpp/java_generator.cpp
@@ -433,7 +433,7 @@
map<string, string>* vars,
Printer* p, StubType type, bool generate_nano) {
(*vars)["service_name"] = service->name();
- (*vars)["abstract_name"] = "Abstract" + service->name();
+ (*vars)["abstract_name"] = service->name() + "ImplBase";
string interface_name = service->name();
string impl_name = service->name();
bool abstract = false;
@@ -510,7 +510,7 @@
GrpcWriteServiceDocComment(p, service);
p->Print(
*vars,
- "public static interface $interface_name$ {\n");
+ "@$Deprecated$ public static interface $interface_name$ {\n");
} else {
p->Print(
*vars,
@@ -883,7 +883,7 @@
(*vars)["service_name"] = service->name();
p->Print(
*vars,
- "public static $ServerServiceDefinition$ bindService(\n"
+ "@$Deprecated$ public static $ServerServiceDefinition$ bindService(\n"
" final $service_name$ serviceImpl) {\n");
p->Indent();
p->Print(*vars,
@@ -1018,6 +1018,9 @@
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);
+ p->Print(*vars,
+ "@$Deprecated$ public static abstract class Abstract$service_name$"
+ " extends $service_name$ImplBase {}\n\n");
PrintMethodHandlerClass(service, vars, p, generate_nano);
PrintGetServiceDescriptorMethod(service, vars, p, generate_nano);
PrintBindServiceMethod(service, vars, p, generate_nano);
@@ -1068,6 +1071,7 @@
map<string, string> vars;
vars["String"] = "java.lang.String";
vars["Override"] = "java.lang.Override";
+ vars["Deprecated"] = "java.lang.Deprecated";
vars["Channel"] = "io.grpc.Channel";
vars["CallOptions"] = "io.grpc.CallOptions";
vars["MethodType"] = "io.grpc.MethodDescriptor.MethodType";
diff --git a/compiler/src/test/golden/TestService.java.txt b/compiler/src/test/golden/TestService.java.txt
index d2db52d..58a0399 100644
--- a/compiler/src/test/golden/TestService.java.txt
+++ b/compiler/src/test/golden/TestService.java.txt
@@ -104,7 +104,7 @@
* Test service that supports all call types.
* </pre>
*/
- public static interface TestService {
+ @java.lang.Deprecated public static interface TestService {
/**
* <pre>
@@ -156,7 +156,7 @@
}
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1469")
- public static abstract class AbstractTestService implements TestService, io.grpc.BindableService {
+ public static abstract class TestServiceImplBase implements TestService, io.grpc.BindableService {
@java.lang.Override
public void unaryCall(io.grpc.testing.integration.Test.SimpleRequest request,
@@ -198,7 +198,7 @@
* Test service that supports all call types.
* </pre>
*/
- public static interface TestServiceBlockingClient {
+ @java.lang.Deprecated public static interface TestServiceBlockingClient {
/**
* <pre>
@@ -223,7 +223,7 @@
* Test service that supports all call types.
* </pre>
*/
- public static interface TestServiceFutureClient {
+ @java.lang.Deprecated public static interface TestServiceFutureClient {
/**
* <pre>
@@ -344,6 +344,8 @@
}
}
+ @java.lang.Deprecated public static abstract class AbstractTestService extends TestServiceImplBase {}
+
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;
@@ -409,7 +411,7 @@
METHOD_HALF_BIDI_CALL);
}
- public static io.grpc.ServerServiceDefinition bindService(
+ @java.lang.Deprecated public static io.grpc.ServerServiceDefinition bindService(
final TestService serviceImpl) {
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
.addMethod(
diff --git a/compiler/src/testLite/golden/TestService.java.txt b/compiler/src/testLite/golden/TestService.java.txt
index 7eb5472..f47dcc5 100644
--- a/compiler/src/testLite/golden/TestService.java.txt
+++ b/compiler/src/testLite/golden/TestService.java.txt
@@ -104,7 +104,7 @@
* Test service that supports all call types.
* </pre>
*/
- public static interface TestService {
+ @java.lang.Deprecated public static interface TestService {
/**
* <pre>
@@ -156,7 +156,7 @@
}
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1469")
- public static abstract class AbstractTestService implements TestService, io.grpc.BindableService {
+ public static abstract class TestServiceImplBase implements TestService, io.grpc.BindableService {
@java.lang.Override
public void unaryCall(io.grpc.testing.integration.Test.SimpleRequest request,
@@ -198,7 +198,7 @@
* Test service that supports all call types.
* </pre>
*/
- public static interface TestServiceBlockingClient {
+ @java.lang.Deprecated public static interface TestServiceBlockingClient {
/**
* <pre>
@@ -223,7 +223,7 @@
* Test service that supports all call types.
* </pre>
*/
- public static interface TestServiceFutureClient {
+ @java.lang.Deprecated public static interface TestServiceFutureClient {
/**
* <pre>
@@ -344,6 +344,8 @@
}
}
+ @java.lang.Deprecated public static abstract class AbstractTestService extends TestServiceImplBase {}
+
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;
@@ -409,7 +411,7 @@
METHOD_HALF_BIDI_CALL);
}
- public static io.grpc.ServerServiceDefinition bindService(
+ @java.lang.Deprecated public static io.grpc.ServerServiceDefinition bindService(
final TestService serviceImpl) {
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
.addMethod(
diff --git a/compiler/src/testNano/golden/TestService.java.txt b/compiler/src/testNano/golden/TestService.java.txt
index 95462db..b66a3be 100644
--- a/compiler/src/testNano/golden/TestService.java.txt
+++ b/compiler/src/testNano/golden/TestService.java.txt
@@ -182,7 +182,7 @@
* Test service that supports all call types.
* </pre>
*/
- public static interface TestService {
+ @java.lang.Deprecated public static interface TestService {
/**
* <pre>
@@ -234,7 +234,7 @@
}
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1469")
- public static abstract class AbstractTestService implements TestService, io.grpc.BindableService {
+ public static abstract class TestServiceImplBase implements TestService, io.grpc.BindableService {
@java.lang.Override
public void unaryCall(io.grpc.testing.integration.nano.Test.SimpleRequest request,
@@ -276,7 +276,7 @@
* Test service that supports all call types.
* </pre>
*/
- public static interface TestServiceBlockingClient {
+ @java.lang.Deprecated public static interface TestServiceBlockingClient {
/**
* <pre>
@@ -301,7 +301,7 @@
* Test service that supports all call types.
* </pre>
*/
- public static interface TestServiceFutureClient {
+ @java.lang.Deprecated public static interface TestServiceFutureClient {
/**
* <pre>
@@ -422,6 +422,8 @@
}
}
+ @java.lang.Deprecated public static abstract class AbstractTestService extends TestServiceImplBase {}
+
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;
@@ -487,7 +489,7 @@
METHOD_HALF_BIDI_CALL);
}
- public static io.grpc.ServerServiceDefinition bindService(
+ @java.lang.Deprecated public static io.grpc.ServerServiceDefinition bindService(
final TestService serviceImpl) {
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
.addMethod(