diff options
Diffstat (limited to 'src/google/protobuf/compiler/java/java_service.cc')
-rw-r--r-- | src/google/protobuf/compiler/java/java_service.cc | 74 |
1 files changed, 47 insertions, 27 deletions
diff --git a/src/google/protobuf/compiler/java/java_service.cc b/src/google/protobuf/compiler/java/java_service.cc index bcd80359..aa5c5231 100644 --- a/src/google/protobuf/compiler/java/java_service.cc +++ b/src/google/protobuf/compiler/java/java_service.cc @@ -33,8 +33,11 @@ // Sanjay Ghemawat, Jeff Dean, and others. #include <google/protobuf/compiler/java/java_service.h> + +#include <google/protobuf/compiler/java/java_context.h> #include <google/protobuf/compiler/java/java_doc_comment.h> #include <google/protobuf/compiler/java/java_helpers.h> +#include <google/protobuf/compiler/java/java_name_resolver.h> #include <google/protobuf/io/printer.h> #include <google/protobuf/descriptor.pb.h> #include <google/protobuf/stubs/strutil.h> @@ -49,8 +52,17 @@ ServiceGenerator::ServiceGenerator(const ServiceDescriptor* descriptor) ServiceGenerator::~ServiceGenerator() {} -void ServiceGenerator::Generate(io::Printer* printer) { - bool is_own_file = descriptor_->file()->options().java_multiple_files(); +// =================================================================== +ImmutableServiceGenerator::ImmutableServiceGenerator( + const ServiceDescriptor* descriptor, Context* context) + : ServiceGenerator(descriptor), context_(context), + name_resolver_(context->GetNameResolver()) {} + +ImmutableServiceGenerator::~ImmutableServiceGenerator() {} + +void ImmutableServiceGenerator::Generate(io::Printer* printer) { + bool is_own_file = + MultipleJavaFiles(descriptor_->file(), /* immutable = */ true); WriteServiceDocComment(printer, descriptor_); printer->Print( "public $static$ abstract class $classname$\n" @@ -77,7 +89,7 @@ void ServiceGenerator::Generate(io::Printer* printer) { " getDescriptor() {\n" " return $file$.getDescriptor().getServices().get($index$);\n" "}\n", - "file", ClassName(descriptor_->file()), + "file", name_resolver_->GetImmutableClassName(descriptor_->file()), "index", SimpleItoa(descriptor_->index())); GenerateGetDescriptorForType(printer); @@ -98,7 +110,8 @@ void ServiceGenerator::Generate(io::Printer* printer) { printer->Print("}\n\n"); } -void ServiceGenerator::GenerateGetDescriptorForType(io::Printer* printer) { +void ImmutableServiceGenerator::GenerateGetDescriptorForType( + io::Printer* printer) { printer->Print( "public final com.google.protobuf.Descriptors.ServiceDescriptor\n" " getDescriptorForType() {\n" @@ -106,7 +119,7 @@ void ServiceGenerator::GenerateGetDescriptorForType(io::Printer* printer) { "}\n"); } -void ServiceGenerator::GenerateInterface(io::Printer* printer) { +void ImmutableServiceGenerator::GenerateInterface(io::Printer* printer) { printer->Print("public interface Interface {\n"); printer->Indent(); GenerateAbstractMethods(printer); @@ -114,7 +127,7 @@ void ServiceGenerator::GenerateInterface(io::Printer* printer) { printer->Print("}\n\n"); } -void ServiceGenerator::GenerateNewReflectiveServiceMethod( +void ImmutableServiceGenerator::GenerateNewReflectiveServiceMethod( io::Printer* printer) { printer->Print( "public static com.google.protobuf.Service newReflectiveService(\n" @@ -141,7 +154,7 @@ void ServiceGenerator::GenerateNewReflectiveServiceMethod( printer->Print("}\n\n"); } -void ServiceGenerator::GenerateNewReflectiveBlockingServiceMethod( +void ImmutableServiceGenerator::GenerateNewReflectiveBlockingServiceMethod( io::Printer* printer) { printer->Print( "public static com.google.protobuf.BlockingService\n" @@ -162,7 +175,7 @@ void ServiceGenerator::GenerateNewReflectiveBlockingServiceMethod( printer->Print("}\n\n"); } -void ServiceGenerator::GenerateAbstractMethods(io::Printer* printer) { +void ImmutableServiceGenerator::GenerateAbstractMethods(io::Printer* printer) { for (int i = 0; i < descriptor_->method_count(); i++) { const MethodDescriptor* method = descriptor_->method(i); WriteMethodDocComment(printer, method); @@ -171,7 +184,7 @@ void ServiceGenerator::GenerateAbstractMethods(io::Printer* printer) { } } -void ServiceGenerator::GenerateCallMethod(io::Printer* printer) { +void ImmutableServiceGenerator::GenerateCallMethod(io::Printer* printer) { printer->Print( "\n" "public final void callMethod(\n" @@ -194,8 +207,10 @@ void ServiceGenerator::GenerateCallMethod(io::Printer* printer) { map<string, string> vars; vars["index"] = SimpleItoa(i); vars["method"] = UnderscoresToCamelCase(method); - vars["input"] = ClassName(method->input_type()); - vars["output"] = ClassName(method->output_type()); + vars["input"] = name_resolver_->GetImmutableClassName( + method->input_type()); + vars["output"] = name_resolver_->GetImmutableClassName( + method->output_type()); printer->Print(vars, "case $index$:\n" " this.$method$(controller, ($input$)request,\n" @@ -217,7 +232,8 @@ void ServiceGenerator::GenerateCallMethod(io::Printer* printer) { "\n"); } -void ServiceGenerator::GenerateCallBlockingMethod(io::Printer* printer) { +void ImmutableServiceGenerator::GenerateCallBlockingMethod( + io::Printer* printer) { printer->Print( "\n" "public final com.google.protobuf.Message callBlockingMethod(\n" @@ -239,8 +255,10 @@ void ServiceGenerator::GenerateCallBlockingMethod(io::Printer* printer) { map<string, string> vars; vars["index"] = SimpleItoa(i); vars["method"] = UnderscoresToCamelCase(method); - vars["input"] = ClassName(method->input_type()); - vars["output"] = ClassName(method->output_type()); + vars["input"] = name_resolver_->GetImmutableClassName( + method->input_type()); + vars["output"] = name_resolver_->GetImmutableClassName( + method->output_type()); printer->Print(vars, "case $index$:\n" " return impl.$method$(controller, ($input$)request);\n"); @@ -259,7 +277,7 @@ void ServiceGenerator::GenerateCallBlockingMethod(io::Printer* printer) { "\n"); } -void ServiceGenerator::GenerateGetPrototype(RequestOrResponse which, +void ImmutableServiceGenerator::GenerateGetPrototype(RequestOrResponse which, io::Printer* printer) { /* * TODO(cpovirk): The exception message says "Service.foo" when it may be @@ -283,7 +301,7 @@ void ServiceGenerator::GenerateGetPrototype(RequestOrResponse which, const MethodDescriptor* method = descriptor_->method(i); map<string, string> vars; vars["index"] = SimpleItoa(i); - vars["type"] = ClassName( + vars["type"] = name_resolver_->GetImmutableClassName( (which == REQUEST) ? method->input_type() : method->output_type()); printer->Print(vars, "case $index$:\n" @@ -303,7 +321,7 @@ void ServiceGenerator::GenerateGetPrototype(RequestOrResponse which, "\n"); } -void ServiceGenerator::GenerateStub(io::Printer* printer) { +void ImmutableServiceGenerator::GenerateStub(io::Printer* printer) { printer->Print( "public static Stub newStub(\n" " com.google.protobuf.RpcChannel channel) {\n" @@ -312,7 +330,7 @@ void ServiceGenerator::GenerateStub(io::Printer* printer) { "\n" "public static final class Stub extends $classname$ implements Interface {" "\n", - "classname", ClassName(descriptor_)); + "classname", name_resolver_->GetImmutableClassName(descriptor_)); printer->Indent(); printer->Print( @@ -335,7 +353,8 @@ void ServiceGenerator::GenerateStub(io::Printer* printer) { map<string, string> vars; vars["index"] = SimpleItoa(i); - vars["output"] = ClassName(method->output_type()); + vars["output"] = name_resolver_->GetImmutableClassName( + method->output_type()); printer->Print(vars, "channel.callMethod(\n" " getDescriptor().getMethods().get($index$),\n" @@ -357,7 +376,7 @@ void ServiceGenerator::GenerateStub(io::Printer* printer) { "\n"); } -void ServiceGenerator::GenerateBlockingStub(io::Printer* printer) { +void ImmutableServiceGenerator::GenerateBlockingStub(io::Printer* printer) { printer->Print( "public static BlockingInterface newBlockingStub(\n" " com.google.protobuf.BlockingRpcChannel channel) {\n" @@ -399,7 +418,8 @@ void ServiceGenerator::GenerateBlockingStub(io::Printer* printer) { map<string, string> vars; vars["index"] = SimpleItoa(i); - vars["output"] = ClassName(method->output_type()); + vars["output"] = name_resolver_->GetImmutableClassName( + method->output_type()); printer->Print(vars, "return ($output$) channel.callBlockingMethod(\n" " getDescriptor().getMethods().get($index$),\n" @@ -417,13 +437,13 @@ void ServiceGenerator::GenerateBlockingStub(io::Printer* printer) { printer->Print("}\n"); } -void ServiceGenerator::GenerateMethodSignature(io::Printer* printer, +void ImmutableServiceGenerator::GenerateMethodSignature(io::Printer* printer, const MethodDescriptor* method, IsAbstract is_abstract) { map<string, string> vars; vars["name"] = UnderscoresToCamelCase(method); - vars["input"] = ClassName(method->input_type()); - vars["output"] = ClassName(method->output_type()); + vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); + vars["output"] = name_resolver_->GetImmutableClassName(method->output_type()); vars["abstract"] = (is_abstract == IS_ABSTRACT) ? "abstract" : ""; printer->Print(vars, "public $abstract$ void $name$(\n" @@ -432,13 +452,13 @@ void ServiceGenerator::GenerateMethodSignature(io::Printer* printer, " com.google.protobuf.RpcCallback<$output$> done)"); } -void ServiceGenerator::GenerateBlockingMethodSignature( +void ImmutableServiceGenerator::GenerateBlockingMethodSignature( io::Printer* printer, const MethodDescriptor* method) { map<string, string> vars; vars["method"] = UnderscoresToCamelCase(method); - vars["input"] = ClassName(method->input_type()); - vars["output"] = ClassName(method->output_type()); + vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); + vars["output"] = name_resolver_->GetImmutableClassName(method->output_type()); printer->Print(vars, "\n" "public $output$ $method$(\n" |