Index: third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc |
diff --git a/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc |
index df4db46386f0281fa1520954e5a39b5ebc71dce0..4c474a48a692f0fee2cea85f46632d969631de12 100644 |
--- a/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc |
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc |
@@ -110,7 +110,7 @@ void ImmutableMessageGenerator::GenerateStaticVariables( |
// the outermost class in the file. This way, they will be initialized in |
// a deterministic order. |
- std::map<string, string> vars; |
+ map<string, string> vars; |
vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); |
vars["index"] = SimpleItoa(descriptor_->index()); |
vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_); |
@@ -154,7 +154,7 @@ void ImmutableMessageGenerator::GenerateStaticVariables( |
int ImmutableMessageGenerator::GenerateStaticVariableInitializers( |
io::Printer* printer) { |
int bytecode_estimate = 0; |
- std::map<string, string> vars; |
+ map<string, string> vars; |
vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); |
vars["index"] = SimpleItoa(descriptor_->index()); |
vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_); |
@@ -191,7 +191,7 @@ int ImmutableMessageGenerator::GenerateStaticVariableInitializers( |
void ImmutableMessageGenerator:: |
GenerateFieldAccessorTable(io::Printer* printer, int* bytecode_estimate) { |
- std::map<string, string> vars; |
+ map<string, string> vars; |
vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); |
if (MultipleJavaFiles(descriptor_->file(), /* immutable = */ true)) { |
// We can only make these package-private since the classes that use them |
@@ -205,10 +205,9 @@ GenerateFieldAccessorTable(io::Printer* printer, int* bytecode_estimate) { |
} else { |
vars["final"] = ""; |
} |
- vars["ver"] = GeneratedCodeVersionSuffix(); |
printer->Print(vars, |
"$private$static $final$\n" |
- " com.google.protobuf.GeneratedMessage$ver$.FieldAccessorTable\n" |
+ " com.google.protobuf.GeneratedMessage.FieldAccessorTable\n" |
" internal_$identifier$_fieldAccessorTable;\n"); |
// 6 bytes per field and oneof |
@@ -221,11 +220,11 @@ GenerateFieldAccessorTableInitializer(io::Printer* printer) { |
int bytecode_estimate = 10; |
printer->Print( |
"internal_$identifier$_fieldAccessorTable = new\n" |
- " com.google.protobuf.GeneratedMessage$ver$.FieldAccessorTable(\n" |
+ " com.google.protobuf.GeneratedMessage.FieldAccessorTable(\n" |
" internal_$identifier$_descriptor,\n" |
" new java.lang.String[] { ", |
- "identifier", UniqueFileScopeIdentifier(descriptor_), |
- "ver", GeneratedCodeVersionSuffix()); |
+ "identifier", |
+ UniqueFileScopeIdentifier(descriptor_)); |
for (int i = 0; i < descriptor_->field_count(); i++) { |
const FieldDescriptor* field = descriptor_->field(i); |
const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field); |
@@ -249,27 +248,22 @@ GenerateFieldAccessorTableInitializer(io::Printer* printer) { |
// =================================================================== |
void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) { |
- MaybePrintGeneratedAnnotation(context_, printer, descriptor_, |
- /* immutable = */ true, "OrBuilder"); |
if (descriptor_->extension_range_count() > 0) { |
printer->Print( |
- "public interface $classname$OrBuilder$idend$ extends\n" |
- " $extra_interfaces$\n" |
- " com.google.protobuf.GeneratedMessage$ver$.\n" |
- " ExtendableMessageOrBuilder<$classname$> {\n", |
- "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), |
- "classname", descriptor_->name(), |
- "idend", "", "ver", GeneratedCodeVersionSuffix()); |
+ "public interface $classname$OrBuilder extends\n" |
+ " $extra_interfaces$\n" |
+ " com.google.protobuf.GeneratedMessage.\n" |
+ " ExtendableMessageOrBuilder<$classname$> {\n", |
+ "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), |
+ "classname", descriptor_->name()); |
} else { |
printer->Print( |
- "public interface $classname$OrBuilder$idend$ extends\n" |
- " $extra_interfaces$\n" |
- " com.google.protobuf.MessageOrBuilder {\n", |
- "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), |
- "classname", descriptor_->name(), |
- "idend", ""); |
+ "public interface $classname$OrBuilder extends\n" |
+ " $extra_interfaces$\n" |
+ " com.google.protobuf.MessageOrBuilder {\n", |
+ "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), |
+ "classname", descriptor_->name()); |
} |
- printer->Annotate("classname", "idend", descriptor_); |
printer->Indent(); |
for (int i = 0; i < descriptor_->field_count(); i++) { |
@@ -297,45 +291,36 @@ void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) { |
// =================================================================== |
void ImmutableMessageGenerator::Generate(io::Printer* printer) { |
- bool is_own_file = IsOwnFile(descriptor_, /* immutable = */ true); |
+ bool is_own_file = |
+ descriptor_->containing_type() == NULL && |
+ MultipleJavaFiles(descriptor_->file(), /* immutable = */ true); |
- std::map<string, string> variables; |
+ map<string, string> variables; |
variables["static"] = is_own_file ? " " : " static "; |
variables["classname"] = descriptor_->name(); |
variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_); |
- variables["ver"] = GeneratedCodeVersionSuffix(); |
WriteMessageDocComment(printer, descriptor_); |
- MaybePrintGeneratedAnnotation(context_, printer, descriptor_, |
- /* immutable = */ true); |
// The builder_type stores the super type name of the nested Builder class. |
string builder_type; |
if (descriptor_->extension_range_count() > 0) { |
printer->Print(variables, |
- "public $static$final class $classname$ extends\n"); |
- printer->Annotate("classname", descriptor_); |
- printer->Print( |
- variables, |
- " com.google.protobuf.GeneratedMessage$ver$.ExtendableMessage<\n" |
- " $classname$> implements\n" |
- " $extra_interfaces$\n" |
- " $classname$OrBuilder {\n"); |
+ "public $static$final class $classname$ extends\n" |
+ " com.google.protobuf.GeneratedMessage.ExtendableMessage<\n" |
+ " $classname$> implements\n" |
+ " $extra_interfaces$\n" |
+ " $classname$OrBuilder {\n"); |
builder_type = strings::Substitute( |
- "com.google.protobuf.GeneratedMessage$1.ExtendableBuilder<$0, ?>", |
- name_resolver_->GetImmutableClassName(descriptor_), |
- GeneratedCodeVersionSuffix()); |
+ "com.google.protobuf.GeneratedMessage.ExtendableBuilder<$0, ?>", |
+ name_resolver_->GetImmutableClassName(descriptor_)); |
} else { |
printer->Print(variables, |
- "public $static$final class $classname$ extends\n"); |
- printer->Annotate("classname", descriptor_); |
- printer->Print(variables, |
- " com.google.protobuf.GeneratedMessage$ver$ implements\n" |
+ "public $static$final class $classname$ extends\n" |
+ " com.google.protobuf.GeneratedMessage implements\n" |
" $extra_interfaces$\n" |
" $classname$OrBuilder {\n"); |
- builder_type = strings::Substitute( |
- "com.google.protobuf.GeneratedMessage$0.Builder<?>", |
- GeneratedCodeVersionSuffix()); |
+ builder_type = "com.google.protobuf.GeneratedMessage.Builder<?>"; |
} |
printer->Indent(); |
// Using builder_type, instead of Builder, prevents the Builder class from |
@@ -409,7 +394,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { |
} |
// oneof |
- std::map<string, string> vars; |
+ map<string, string> vars; |
for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { |
vars["oneof_name"] = context_->GetOneofGeneratorInfo( |
descriptor_->oneof_decl(i))->name; |
@@ -500,6 +485,9 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { |
if (context_->HasGeneratedMethods(descriptor_)) { |
GenerateIsInitialized(printer); |
GenerateMessageSerializationMethods(printer); |
+ } |
+ |
+ if (HasEqualsAndHashCode(descriptor_)) { |
GenerateEqualsAndHashCode(printer); |
} |
@@ -561,12 +549,13 @@ GenerateMessageSerializationMethods(io::Printer* printer) { |
google::protobuf::scoped_array<const FieldDescriptor * > sorted_fields( |
SortFieldsByNumber(descriptor_)); |
- std::vector<const Descriptor::ExtensionRange*> sorted_extensions; |
+ vector<const Descriptor::ExtensionRange*> sorted_extensions; |
for (int i = 0; i < descriptor_->extension_range_count(); ++i) { |
sorted_extensions.push_back(descriptor_->extension_range(i)); |
} |
std::sort(sorted_extensions.begin(), sorted_extensions.end(), |
ExtensionRangeOrdering()); |
+ |
printer->Print( |
"public void writeTo(com.google.protobuf.CodedOutputStream output)\n" |
" throws java.io.IOException {\n"); |
@@ -585,18 +574,16 @@ GenerateMessageSerializationMethods(io::Printer* printer) { |
if (descriptor_->extension_range_count() > 0) { |
if (descriptor_->options().message_set_wire_format()) { |
printer->Print( |
- "com.google.protobuf.GeneratedMessage$ver$\n" |
+ "com.google.protobuf.GeneratedMessage\n" |
" .ExtendableMessage<$classname$>.ExtensionWriter\n" |
" extensionWriter = newMessageSetExtensionWriter();\n", |
- "classname", name_resolver_->GetImmutableClassName(descriptor_), |
- "ver", GeneratedCodeVersionSuffix()); |
+ "classname", name_resolver_->GetImmutableClassName(descriptor_)); |
} else { |
printer->Print( |
- "com.google.protobuf.GeneratedMessage$ver$\n" |
+ "com.google.protobuf.GeneratedMessage\n" |
" .ExtendableMessage<$classname$>.ExtensionWriter\n" |
" extensionWriter = newExtensionWriter();\n", |
- "classname", name_resolver_->GetImmutableClassName(descriptor_), |
- "ver", GeneratedCodeVersionSuffix()); |
+ "classname", name_resolver_->GetImmutableClassName(descriptor_)); |
} |
} |
@@ -700,44 +687,43 @@ GenerateParseFromMethods(io::Printer* printer) { |
"}\n" |
"public static $classname$ parseFrom(java.io.InputStream input)\n" |
" throws java.io.IOException {\n" |
- " return com.google.protobuf.GeneratedMessage$ver$\n" |
+ " return com.google.protobuf.GeneratedMessage\n" |
" .parseWithIOException(PARSER, input);\n" |
"}\n" |
"public static $classname$ parseFrom(\n" |
" java.io.InputStream input,\n" |
" com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n" |
" throws java.io.IOException {\n" |
- " return com.google.protobuf.GeneratedMessage$ver$\n" |
+ " return com.google.protobuf.GeneratedMessage\n" |
" .parseWithIOException(PARSER, input, extensionRegistry);\n" |
"}\n" |
"public static $classname$ parseDelimitedFrom(java.io.InputStream input)\n" |
" throws java.io.IOException {\n" |
- " return com.google.protobuf.GeneratedMessage$ver$\n" |
+ " return com.google.protobuf.GeneratedMessage\n" |
" .parseDelimitedWithIOException(PARSER, input);\n" |
"}\n" |
"public static $classname$ parseDelimitedFrom(\n" |
" java.io.InputStream input,\n" |
" com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n" |
" throws java.io.IOException {\n" |
- " return com.google.protobuf.GeneratedMessage$ver$\n" |
+ " return com.google.protobuf.GeneratedMessage\n" |
" .parseDelimitedWithIOException(PARSER, input, extensionRegistry);\n" |
"}\n" |
"public static $classname$ parseFrom(\n" |
" com.google.protobuf.CodedInputStream input)\n" |
" throws java.io.IOException {\n" |
- " return com.google.protobuf.GeneratedMessage$ver$\n" |
+ " return com.google.protobuf.GeneratedMessage\n" |
" .parseWithIOException(PARSER, input);\n" |
"}\n" |
"public static $classname$ parseFrom(\n" |
" com.google.protobuf.CodedInputStream input,\n" |
" com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n" |
" throws java.io.IOException {\n" |
- " return com.google.protobuf.GeneratedMessage$ver$\n" |
+ " return com.google.protobuf.GeneratedMessage\n" |
" .parseWithIOException(PARSER, input, extensionRegistry);\n" |
"}\n" |
"\n", |
- "classname", name_resolver_->GetImmutableClassName(descriptor_), |
- "ver", GeneratedCodeVersionSuffix()); |
+ "classname", name_resolver_->GetImmutableClassName(descriptor_)); |
} |
void ImmutableMessageGenerator::GenerateSerializeOneField( |
@@ -776,11 +762,10 @@ void ImmutableMessageGenerator::GenerateBuilder(io::Printer* printer) { |
printer->Print( |
"@java.lang.Override\n" |
"protected Builder newBuilderForType(\n" |
- " com.google.protobuf.GeneratedMessage$ver$.BuilderParent parent) {\n" |
+ " com.google.protobuf.GeneratedMessage.BuilderParent parent) {\n" |
" Builder builder = new Builder(parent);\n" |
" return builder;\n" |
- "}\n", |
- "ver", GeneratedCodeVersionSuffix()); |
+ "}\n"); |
MessageBuilderGenerator builderGenerator(descriptor_, context_); |
builderGenerator.Generate(printer); |
@@ -798,7 +783,7 @@ GenerateDescriptorMethods(io::Printer* printer) { |
"fileclass", name_resolver_->GetImmutableClassName(descriptor_->file()), |
"identifier", UniqueFileScopeIdentifier(descriptor_)); |
} |
- std::vector<const FieldDescriptor*> map_fields; |
+ vector<const FieldDescriptor*> map_fields; |
for (int i = 0; i < descriptor_->field_count(); i++) { |
const FieldDescriptor* field = descriptor_->field(i); |
if (GetJavaType(field) == JAVATYPE_MESSAGE && |
@@ -834,7 +819,7 @@ GenerateDescriptorMethods(io::Printer* printer) { |
"}\n"); |
} |
printer->Print( |
- "protected com.google.protobuf.GeneratedMessage$ver$.FieldAccessorTable\n" |
+ "protected com.google.protobuf.GeneratedMessage.FieldAccessorTable\n" |
" internalGetFieldAccessorTable() {\n" |
" return $fileclass$.internal_$identifier$_fieldAccessorTable\n" |
" .ensureFieldAccessorsInitialized(\n" |
@@ -843,8 +828,7 @@ GenerateDescriptorMethods(io::Printer* printer) { |
"\n", |
"classname", name_resolver_->GetImmutableClassName(descriptor_), |
"fileclass", name_resolver_->GetImmutableClassName(descriptor_->file()), |
- "identifier", UniqueFileScopeIdentifier(descriptor_), |
- "ver", GeneratedCodeVersionSuffix()); |
+ "identifier", UniqueFileScopeIdentifier(descriptor_)); |
} |
// =================================================================== |
@@ -927,7 +911,7 @@ void ImmutableMessageGenerator::GenerateIsInitialized( |
case FieldDescriptor::LABEL_REPEATED: |
if (IsMapEntry(field->message_type())) { |
printer->Print( |
- "for ($type$ item : get$name$Map().values()) {\n" |
+ "for ($type$ item : get$name$().values()) {\n" |
" if (!item.isInitialized()) {\n" |
" memoizedIsInitialized = 0;\n" |
" return false;\n" |
@@ -1092,12 +1076,7 @@ GenerateEqualsAndHashCode(io::Printer* printer) { |
"}\n" |
"int hash = 41;\n"); |
- // If we output a getDescriptor() method, use that as it is more efficient. |
- if (descriptor_->options().no_standard_descriptor_accessor()) { |
- printer->Print("hash = (19 * hash) + getDescriptorForType().hashCode();\n"); |
- } else { |
- printer->Print("hash = (19 * hash) + getDescriptor().hashCode();\n"); |
- } |
+ printer->Print("hash = (19 * hash) + getDescriptorForType().hashCode();\n"); |
// hashCode non-oneofs. |
for (int i = 0; i < descriptor_->field_count(); i++) { |
@@ -1246,7 +1225,8 @@ GenerateParsingConstructor(io::Printer* printer) { |
"default: {\n" |
" if (!input.skipField(tag)) {\n" |
" done = true;\n" // it's an endgroup tag |
- " }\n" |
+ " }\n"); |
+ printer->Print( |
" break;\n" |
"}\n"); |
} |
@@ -1258,7 +1238,7 @@ GenerateParsingConstructor(io::Printer* printer) { |
printer->Print( |
"case $tag$: {\n", |
- "tag", SimpleItoa(static_cast<int32>(tag))); |
+ "tag", SimpleItoa(tag)); |
printer->Indent(); |
field_generators_.get(field).GenerateParsingCode(printer); |
@@ -1275,7 +1255,7 @@ GenerateParsingConstructor(io::Printer* printer) { |
WireFormatLite::WIRETYPE_LENGTH_DELIMITED); |
printer->Print( |
"case $tag$: {\n", |
- "tag", SimpleItoa(static_cast<int32>(packed_tag))); |
+ "tag", SimpleItoa(packed_tag)); |
printer->Indent(); |
field_generators_.get(field).GenerateParsingCodeFromPacked(printer); |
@@ -1421,7 +1401,7 @@ void ImmutableMessageGenerator::GenerateAnyMethods(io::Printer* printer) { |
"}\n" |
"\n" |
"/**\n" |
- " * Packs a message using the given type URL prefix. The type URL will\n" |
+ " * Packs a message uisng the given type URL prefix. The type URL will\n" |
" * be constructed by concatenating the message type's full name to the\n" |
" * prefix with an optional \"/\" separator if the prefix doesn't end\n" |
" * with \"/\" already.\n" |