Index: third_party/protobuf/src/google/protobuf/compiler/java/java_service.cc |
diff --git a/third_party/protobuf/src/google/protobuf/compiler/java/java_service.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_service.cc |
index bcd803590d1e7e077c11bc16b415915cd2c78f1d..11bfc12d1b306c11c8d88083101f738a53cfcbd4 100644 |
--- a/third_party/protobuf/src/google/protobuf/compiler/java/java_service.cc |
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_service.cc |
@@ -1,6 +1,6 @@ |
// Protocol Buffers - Google's data interchange format |
// Copyright 2008 Google Inc. All rights reserved. |
-// http://code.google.com/p/protobuf/ |
+// https://developers.google.com/protocol-buffers/ |
// |
// Redistribution and use in source and binary forms, with or without |
// modification, are permitted provided that the following conditions are |
@@ -33,10 +33,12 @@ |
// 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> |
namespace google { |
@@ -49,8 +51,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 +88,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 +109,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 +118,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 +126,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 +153,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 +174,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 +183,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 +206,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 +231,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 +254,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 +276,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 +300,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 +320,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 +329,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 +352,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 +375,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 +417,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 +436,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 +451,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" |