| Index: third_party/protobuf/src/google/protobuf/compiler/java/java_message_lite.cc
|
| diff --git a/third_party/protobuf/src/google/protobuf/compiler/java/java_message_lite.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_message_lite.cc
|
| index 94ed2c396aa631315daef2dd8bdf434116a71e60..d4d2593a66b916ab65c9db4db61ade0a200ee72a 100644
|
| --- a/third_party/protobuf/src/google/protobuf/compiler/java/java_message_lite.cc
|
| +++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_message_lite.cc
|
| @@ -46,7 +46,7 @@
|
| #include <google/protobuf/compiler/java/java_context.h>
|
| #include <google/protobuf/compiler/java/java_doc_comment.h>
|
| #include <google/protobuf/compiler/java/java_enum_lite.h>
|
| -#include <google/protobuf/compiler/java/java_extension.h>
|
| +#include <google/protobuf/compiler/java/java_extension_lite.h>
|
| #include <google/protobuf/compiler/java/java_generator_factory.h>
|
| #include <google/protobuf/compiler/java/java_helpers.h>
|
| #include <google/protobuf/compiler/java/java_message_builder.h>
|
| @@ -87,19 +87,20 @@ ImmutableMessageLiteGenerator::ImmutableMessageLiteGenerator(
|
| : MessageGenerator(descriptor), context_(context),
|
| name_resolver_(context->GetNameResolver()),
|
| field_generators_(descriptor, context_) {
|
| - GOOGLE_CHECK_EQ(
|
| - FileOptions::LITE_RUNTIME, descriptor->file()->options().optimize_for());
|
| + GOOGLE_CHECK(!HasDescriptorMethods(descriptor->file(), context->EnforceLite()))
|
| + << "Generator factory error: A lite message generator is used to "
|
| + "generate non-lite messages.";
|
| }
|
|
|
| ImmutableMessageLiteGenerator::~ImmutableMessageLiteGenerator() {}
|
|
|
| void ImmutableMessageLiteGenerator::GenerateStaticVariables(
|
| - io::Printer* printer) {
|
| + io::Printer* printer, int* bytecode_estimate) {
|
| // Generate static members for all nested types.
|
| for (int i = 0; i < descriptor_->nested_type_count(); i++) {
|
| // TODO(kenton): Reuse MessageGenerator objects?
|
| ImmutableMessageLiteGenerator(descriptor_->nested_type(i), context_)
|
| - .GenerateStaticVariables(printer);
|
| + .GenerateStaticVariables(printer, bytecode_estimate);
|
| }
|
| }
|
|
|
| @@ -197,7 +198,8 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
|
| }
|
| printer->Indent();
|
|
|
| - GenerateParsingConstructor(printer);
|
| +
|
| + GenerateConstructor(printer);
|
|
|
| // Nested types
|
| for (int i = 0; i < descriptor_->enum_type_count(); i++) {
|
| @@ -259,12 +261,20 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
|
| "cap_oneof_name",
|
| ToUpper(vars["oneof_name"]));
|
| printer->Print(vars,
|
| - "private int value = 0;\n"
|
| + "private final int value;\n"
|
| "private $oneof_capitalized_name$Case(int value) {\n"
|
| " this.value = value;\n"
|
| "}\n");
|
| printer->Print(vars,
|
| + "/**\n"
|
| + " * @deprecated Use {@link #forNumber(int)} instead.\n"
|
| + " */\n"
|
| + "@java.lang.Deprecated\n"
|
| "public static $oneof_capitalized_name$Case valueOf(int value) {\n"
|
| + " return forNumber(value);\n"
|
| + "}\n"
|
| + "\n"
|
| + "public static $oneof_capitalized_name$Case forNumber(int value) {\n"
|
| " switch (value) {\n");
|
| for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) {
|
| const FieldDescriptor* field = descriptor_->oneof_decl(i)->field(j);
|
| @@ -277,8 +287,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
|
| }
|
| printer->Print(
|
| " case 0: return $cap_oneof_name$_NOT_SET;\n"
|
| - " default: throw new java.lang.IllegalArgumentException(\n"
|
| - " \"Value is undefined for this oneof enum.\");\n"
|
| + " default: return null;\n"
|
| " }\n"
|
| "}\n"
|
| "public int getNumber() {\n"
|
| @@ -291,7 +300,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
|
| printer->Print(vars,
|
| "public $oneof_capitalized_name$Case\n"
|
| "get$oneof_capitalized_name$Case() {\n"
|
| - " return $oneof_capitalized_name$Case.valueOf(\n"
|
| + " return $oneof_capitalized_name$Case.forNumber(\n"
|
| " $oneof_name$Case_);\n"
|
| "}\n"
|
| "\n"
|
| @@ -313,11 +322,6 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
|
|
|
| GenerateMessageSerializationMethods(printer);
|
|
|
| - if (HasEqualsAndHashCode(descriptor_)) {
|
| - GenerateEqualsAndHashCode(printer);
|
| - }
|
| -
|
| -
|
| GenerateParseFromMethods(printer);
|
| GenerateBuilder(printer);
|
|
|
| @@ -334,16 +338,8 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
|
| " com.google.protobuf.GeneratedMessageLite.MethodToInvoke method,\n"
|
| " Object arg0, Object arg1) {\n"
|
| " switch (method) {\n"
|
| - " case PARSE_PARTIAL_FROM: {\n"
|
| - " return new $classname$("
|
| - " (com.google.protobuf.CodedInputStream) arg0,\n"
|
| - " (com.google.protobuf.ExtensionRegistryLite) arg1);\n"
|
| - " }\n"
|
| - " case NEW_INSTANCE: {\n"
|
| - " return new $classname$(\n"
|
| - " com.google.protobuf.Internal.EMPTY_CODED_INPUT_STREAM,\n"
|
| - " com.google.protobuf.ExtensionRegistryLite\n"
|
| - " .getEmptyRegistry());\n"
|
| + " case NEW_MUTABLE_INSTANCE: {\n"
|
| + " return new $classname$();\n"
|
| " }\n",
|
| "classname", name_resolver_->GetImmutableClassName(descriptor_));
|
|
|
| @@ -374,10 +370,18 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
|
|
|
| printer->Print(
|
| "}\n"
|
| - "case MERGE_FROM: {\n");
|
| + "case VISIT: {\n");
|
|
|
| printer->Indent();
|
| - GenerateDynamicMethodMergeFrom(printer);
|
| + GenerateDynamicMethodVisit(printer);
|
| + printer->Outdent();
|
| +
|
| + printer->Print(
|
| + "}\n"
|
| + "case MERGE_FROM_STREAM: {\n");
|
| +
|
| + printer->Indent();
|
| + GenerateDynamicMethodMergeFromStream(printer);
|
| printer->Outdent();
|
|
|
| printer->Print(
|
| @@ -425,11 +429,8 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
|
|
|
| printer->Print(
|
| "static {\n"
|
| - " DEFAULT_INSTANCE = new $classname$(\n"
|
| - " com.google.protobuf.Internal\n"
|
| - " .EMPTY_CODED_INPUT_STREAM,\n"
|
| - " com.google.protobuf.ExtensionRegistryLite\n"
|
| - " .getEmptyRegistry());\n"
|
| + " DEFAULT_INSTANCE = new $classname$();\n"
|
| + " DEFAULT_INSTANCE.makeImmutable();\n"
|
| "}\n"
|
| "\n",
|
| "classname", descriptor_->name());
|
| @@ -446,7 +447,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
|
| // because the DEFAULT_INSTANCE is used by the extension to lazily retrieve
|
| // the outer class's FileDescriptor.
|
| for (int i = 0; i < descriptor_->extension_count(); i++) {
|
| - ImmutableExtensionGenerator(descriptor_->extension(i), context_)
|
| + ImmutableExtensionLiteGenerator(descriptor_->extension(i), context_)
|
| .Generate(printer);
|
| }
|
|
|
| @@ -557,9 +558,6 @@ GenerateMessageSerializationMethods(io::Printer* printer) {
|
| " return size;\n"
|
| "}\n"
|
| "\n");
|
| -
|
| - printer->Print(
|
| - "private static final long serialVersionUID = 0L;\n");
|
| }
|
|
|
| void ImmutableMessageLiteGenerator::
|
| @@ -571,54 +569,62 @@ GenerateParseFromMethods(io::Printer* printer) {
|
| "public static $classname$ parseFrom(\n"
|
| " com.google.protobuf.ByteString data)\n"
|
| " throws com.google.protobuf.InvalidProtocolBufferException {\n"
|
| - " return parser().parseFrom(data);\n"
|
| + " return com.google.protobuf.GeneratedMessageLite.parseFrom(\n"
|
| + " DEFAULT_INSTANCE, data);\n"
|
| "}\n"
|
| "public static $classname$ parseFrom(\n"
|
| " com.google.protobuf.ByteString data,\n"
|
| " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n"
|
| " throws com.google.protobuf.InvalidProtocolBufferException {\n"
|
| - " return parser().parseFrom(data, extensionRegistry);\n"
|
| + " return com.google.protobuf.GeneratedMessageLite.parseFrom(\n"
|
| + " DEFAULT_INSTANCE, data, extensionRegistry);\n"
|
| "}\n"
|
| "public static $classname$ parseFrom(byte[] data)\n"
|
| " throws com.google.protobuf.InvalidProtocolBufferException {\n"
|
| - " return parser().parseFrom(data);\n"
|
| + " return com.google.protobuf.GeneratedMessageLite.parseFrom(\n"
|
| + " DEFAULT_INSTANCE, data);\n"
|
| "}\n"
|
| "public static $classname$ parseFrom(\n"
|
| " byte[] data,\n"
|
| " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n"
|
| " throws com.google.protobuf.InvalidProtocolBufferException {\n"
|
| - " return parser().parseFrom(data, extensionRegistry);\n"
|
| + " return com.google.protobuf.GeneratedMessageLite.parseFrom(\n"
|
| + " DEFAULT_INSTANCE, data, extensionRegistry);\n"
|
| "}\n"
|
| "public static $classname$ parseFrom(java.io.InputStream input)\n"
|
| " throws java.io.IOException {\n"
|
| - " return parser().parseFrom(input);\n"
|
| + " return com.google.protobuf.GeneratedMessageLite.parseFrom(\n"
|
| + " DEFAULT_INSTANCE, 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 parser().parseFrom(input, extensionRegistry);\n"
|
| + " return com.google.protobuf.GeneratedMessageLite.parseFrom(\n"
|
| + " DEFAULT_INSTANCE, input, extensionRegistry);\n"
|
| "}\n"
|
| "public static $classname$ parseDelimitedFrom(java.io.InputStream input)\n"
|
| " throws java.io.IOException {\n"
|
| - " return parser().parseDelimitedFrom(input);\n"
|
| + " return parseDelimitedFrom(DEFAULT_INSTANCE, 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 parser().parseDelimitedFrom(input, extensionRegistry);\n"
|
| + " return parseDelimitedFrom(DEFAULT_INSTANCE, input, extensionRegistry);\n"
|
| "}\n"
|
| "public static $classname$ parseFrom(\n"
|
| " com.google.protobuf.CodedInputStream input)\n"
|
| " throws java.io.IOException {\n"
|
| - " return parser().parseFrom(input);\n"
|
| + " return com.google.protobuf.GeneratedMessageLite.parseFrom(\n"
|
| + " DEFAULT_INSTANCE, 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 parser().parseFrom(input, extensionRegistry);\n"
|
| + " return com.google.protobuf.GeneratedMessageLite.parseFrom(\n"
|
| + " DEFAULT_INSTANCE, input, extensionRegistry);\n"
|
| "}\n"
|
| "\n",
|
| "classname", name_resolver_->GetImmutableClassName(descriptor_));
|
| @@ -789,11 +795,13 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodIsInitialized(
|
|
|
| void ImmutableMessageLiteGenerator::GenerateDynamicMethodMakeImmutable(
|
| io::Printer* printer) {
|
| +
|
| // Output generation code for each field.
|
| for (int i = 0; i < descriptor_->field_count(); i++) {
|
| field_generators_.get(descriptor_->field(i))
|
| .GenerateDynamicMethodMakeImmutableCode(printer);
|
| }
|
| +
|
| printer->Print(
|
| "return null;\n");
|
| }
|
| @@ -808,19 +816,17 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodNewBuilder(
|
|
|
| // ===================================================================
|
|
|
| -void ImmutableMessageLiteGenerator::GenerateDynamicMethodMergeFrom(
|
| +void ImmutableMessageLiteGenerator::GenerateDynamicMethodVisit(
|
| io::Printer* printer) {
|
| printer->Print(
|
| - // Optimization: If other is the default instance, we know none of its
|
| - // fields are set so we can skip the merge.
|
| - "if (arg0 == $classname$.getDefaultInstance()) return this;\n"
|
| - "$classname$ other = ($classname$) arg0;\n",
|
| + "Visitor visitor = (Visitor) arg0;\n"
|
| + "$classname$ other = ($classname$) arg1;\n",
|
| "classname", name_resolver_->GetImmutableClassName(descriptor_));
|
|
|
| for (int i = 0; i < descriptor_->field_count(); i++) {
|
| if (!descriptor_->field(i)->containing_oneof()) {
|
| field_generators_.get(
|
| - descriptor_->field(i)).GenerateMergingCode(printer);
|
| + descriptor_->field(i)).GenerateVisitCode(printer);
|
| }
|
| }
|
|
|
| @@ -839,7 +845,7 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodMergeFrom(
|
| "field_name",
|
| ToUpper(field->name()));
|
| printer->Indent();
|
| - field_generators_.get(field).GenerateMergingCode(printer);
|
| + field_generators_.get(field).GenerateVisitCode(printer);
|
| printer->Print(
|
| "break;\n");
|
| printer->Outdent();
|
| @@ -848,188 +854,66 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodMergeFrom(
|
| }
|
| printer->Print(
|
| "case $cap_oneof_name$_NOT_SET: {\n"
|
| + " visitor.visitOneofNotSet($oneof_name$Case_ != 0);\n"
|
| " break;\n"
|
| "}\n",
|
| "cap_oneof_name",
|
| ToUpper(context_->GetOneofGeneratorInfo(
|
| - descriptor_->oneof_decl(i))->name));
|
| + descriptor_->oneof_decl(i))->name),
|
| + "oneof_name",
|
| + context_->GetOneofGeneratorInfo(
|
| + descriptor_->oneof_decl(i))->name);
|
| printer->Outdent();
|
| printer->Print(
|
| "}\n");
|
| }
|
|
|
| - // if message type has extensions
|
| - if (descriptor_->extension_range_count() > 0) {
|
| - printer->Print(
|
| - "this.mergeExtensionFields(other);\n");
|
| - }
|
| -
|
| - if (PreserveUnknownFields(descriptor_)) {
|
| - printer->Print(
|
| - "this.mergeUnknownFields(other.unknownFields);\n");
|
| - }
|
| -
|
| printer->Print(
|
| - "return this;\n");
|
| -}
|
| -
|
| -// ===================================================================
|
| -
|
| -namespace {
|
| -bool CheckHasBitsForEqualsAndHashCode(const FieldDescriptor* field) {
|
| - if (field->is_repeated()) {
|
| - return false;
|
| - }
|
| - if (SupportFieldPresence(field->file())) {
|
| - return true;
|
| - }
|
| - return GetJavaType(field) == JAVATYPE_MESSAGE &&
|
| - field->containing_oneof() == NULL;
|
| -}
|
| -} // namespace
|
| -
|
| -void ImmutableMessageLiteGenerator::
|
| -GenerateEqualsAndHashCode(io::Printer* printer) {
|
| - printer->Print(
|
| - "@java.lang.Override\n"
|
| - "public boolean equals(final java.lang.Object obj) {\n");
|
| + "if (visitor == com.google.protobuf.GeneratedMessageLite.MergeFromVisitor\n"
|
| + " .INSTANCE) {\n");
|
| printer->Indent();
|
| - printer->Print(
|
| - "if (obj == this) {\n"
|
| - " return true;\n"
|
| - "}\n"
|
| - "if (!(obj instanceof $classname$)) {\n"
|
| - " return super.equals(obj);\n"
|
| - "}\n"
|
| - "$classname$ other = ($classname$) obj;\n"
|
| - "\n",
|
| - "classname", name_resolver_->GetImmutableClassName(descriptor_));
|
| -
|
| - printer->Print("boolean result = true;\n");
|
| - for (int i = 0; i < descriptor_->field_count(); i++) {
|
| - const FieldDescriptor* field = descriptor_->field(i);
|
| - const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field);
|
| - bool check_has_bits = CheckHasBitsForEqualsAndHashCode(field);
|
| - if (check_has_bits) {
|
| - printer->Print(
|
| - "result = result && (has$name$() == other.has$name$());\n"
|
| - "if (has$name$()) {\n",
|
| - "name", info->capitalized_name);
|
| - printer->Indent();
|
| - }
|
| - field_generators_.get(field).GenerateEqualsCode(printer);
|
| - if (check_has_bits) {
|
| - printer->Outdent();
|
| - printer->Print(
|
| - "}\n");
|
| - }
|
| - }
|
| - if (PreserveUnknownFields(descriptor_)) {
|
| - // Always consider unknown fields for equality. This will sometimes return
|
| - // false for non-canonical ordering when running in LITE_RUNTIME but it's
|
| - // the best we can do.
|
| + for (int i = 0; i < descriptor_->oneof_decl_count(); ++i) {
|
| + const OneofDescriptor* field = descriptor_->oneof_decl(i);
|
| printer->Print(
|
| - "result = result && unknownFields.equals(other.unknownFields);\n");
|
| + "if (other.$oneof_name$Case_ != 0) {\n"
|
| + " $oneof_name$Case_ = other.$oneof_name$Case_;\n"
|
| + "}\n",
|
| + "oneof_name", context_->GetOneofGeneratorInfo(field)->name);
|
| }
|
| - printer->Print(
|
| - "return result;\n");
|
| - printer->Outdent();
|
| - printer->Print(
|
| - "}\n"
|
| - "\n");
|
| -
|
| - printer->Print(
|
| - "@java.lang.Override\n"
|
| - "public int hashCode() {\n");
|
| - printer->Indent();
|
| - printer->Print(
|
| - "if (memoizedHashCode != 0) {\n");
|
| - printer->Indent();
|
| - printer->Print(
|
| - "return memoizedHashCode;\n");
|
| - printer->Outdent();
|
| - printer->Print(
|
| - "}\n"
|
| - "int hash = 41;\n");
|
|
|
| - // Include the hash of the class so that two objects with different types
|
| - // but the same field values will probably have different hashes.
|
| - printer->Print("hash = (19 * hash) + $classname$.class.hashCode();\n",
|
| - "classname", name_resolver_->GetImmutableClassName(descriptor_));
|
| + if (GenerateHasBits(descriptor_)) {
|
| + // Integers for bit fields.
|
| + int totalBits = 0;
|
| + for (int i = 0; i < descriptor_->field_count(); i++) {
|
| + totalBits += field_generators_.get(descriptor_->field(i))
|
| + .GetNumBitsForMessage();
|
| + }
|
| + int totalInts = (totalBits + 31) / 32;
|
|
|
| - for (int i = 0; i < descriptor_->field_count(); i++) {
|
| - const FieldDescriptor* field = descriptor_->field(i);
|
| - const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field);
|
| - bool check_has_bits = CheckHasBitsForEqualsAndHashCode(field);
|
| - if (check_has_bits) {
|
| + for (int i = 0; i < totalInts; i++) {
|
| printer->Print(
|
| - "if (has$name$()) {\n",
|
| - "name", info->capitalized_name);
|
| - printer->Indent();
|
| - }
|
| - field_generators_.get(field).GenerateHashCode(printer);
|
| - if (check_has_bits) {
|
| - printer->Outdent();
|
| - printer->Print("}\n");
|
| + "$bit_field_name$ |= other.$bit_field_name$;\n",
|
| + "bit_field_name", GetBitFieldName(i));
|
| }
|
| }
|
| -
|
| - printer->Print(
|
| - "hash = (29 * hash) + unknownFields.hashCode();\n");
|
| - printer->Print(
|
| - "memoizedHashCode = hash;\n"
|
| - "return hash;\n");
|
| printer->Outdent();
|
| printer->Print(
|
| - "}\n"
|
| - "\n");
|
| -}
|
| + "}\n");
|
|
|
| -// ===================================================================
|
|
|
| -void ImmutableMessageLiteGenerator::
|
| -GenerateExtensionRegistrationCode(io::Printer* printer) {
|
| - for (int i = 0; i < descriptor_->extension_count(); i++) {
|
| - ImmutableExtensionGenerator(descriptor_->extension(i), context_)
|
| - .GenerateRegistrationCode(printer);
|
| - }
|
| -
|
| - for (int i = 0; i < descriptor_->nested_type_count(); i++) {
|
| - ImmutableMessageLiteGenerator(descriptor_->nested_type(i), context_)
|
| - .GenerateExtensionRegistrationCode(printer);
|
| - }
|
| + printer->Print(
|
| + "return this;\n");
|
| }
|
|
|
| // ===================================================================
|
| -void ImmutableMessageLiteGenerator::
|
| -GenerateParsingConstructor(io::Printer* printer) {
|
| - google::protobuf::scoped_array<const FieldDescriptor * > sorted_fields(
|
| - SortFieldsByNumber(descriptor_));
|
| -
|
| - printer->Print(
|
| - "private $classname$(\n"
|
| - " com.google.protobuf.CodedInputStream input,\n"
|
| - " com.google.protobuf.ExtensionRegistryLite extensionRegistry) {\n",
|
| - "classname", descriptor_->name());
|
| - printer->Indent();
|
| -
|
| - // Initialize all fields to default.
|
| - GenerateInitializers(printer);
|
| -
|
| - // Use builder bits to track mutable repeated fields.
|
| - int totalBuilderBits = 0;
|
| - for (int i = 0; i < descriptor_->field_count(); i++) {
|
| - const ImmutableFieldLiteGenerator& field =
|
| - field_generators_.get(descriptor_->field(i));
|
| - totalBuilderBits += field.GetNumBitsForBuilder();
|
| - }
|
| - int totalBuilderInts = (totalBuilderBits + 31) / 32;
|
| - for (int i = 0; i < totalBuilderInts; i++) {
|
| - printer->Print("int mutable_$bit_field_name$ = 0;\n",
|
| - "bit_field_name", GetBitFieldName(i));
|
| - }
|
|
|
| +void ImmutableMessageLiteGenerator::GenerateDynamicMethodMergeFromStream(
|
| + io::Printer* printer) {
|
| printer->Print(
|
| + "com.google.protobuf.CodedInputStream input =\n"
|
| + " (com.google.protobuf.CodedInputStream) arg0;\n"
|
| + "com.google.protobuf.ExtensionRegistryLite extensionRegistry =\n"
|
| + " (com.google.protobuf.ExtensionRegistryLite) arg1;\n"
|
| "try {\n");
|
| printer->Indent();
|
|
|
| @@ -1077,6 +961,8 @@ GenerateParsingConstructor(io::Printer* printer) {
|
| "}\n");
|
| }
|
|
|
| + google::protobuf::scoped_array<const FieldDescriptor * > sorted_fields(
|
| + SortFieldsByNumber(descriptor_));
|
| for (int i = 0; i < descriptor_->field_count(); i++) {
|
| const FieldDescriptor* field = sorted_fields[i];
|
| uint32 tag = WireFormatLite::MakeTag(field->number(),
|
| @@ -1130,19 +1016,54 @@ GenerateParsingConstructor(io::Printer* printer) {
|
| "} finally {\n");
|
| printer->Indent();
|
|
|
| - // Make repeated field list immutable.
|
| - for (int i = 0; i < descriptor_->field_count(); i++) {
|
| - const FieldDescriptor* field = sorted_fields[i];
|
| - field_generators_.get(field).GenerateParsingDoneCode(printer);
|
| + printer->Outdent();
|
| + printer->Print(
|
| + "}\n"); // finally
|
| +}
|
| +
|
| +// ===================================================================
|
| +
|
| +namespace {
|
| +bool CheckHasBitsForEqualsAndHashCode(const FieldDescriptor* field) {
|
| + if (field->is_repeated()) {
|
| + return false;
|
| + }
|
| + if (SupportFieldPresence(field->file())) {
|
| + return true;
|
| + }
|
| + return GetJavaType(field) == JAVATYPE_MESSAGE &&
|
| + field->containing_oneof() == NULL;
|
| +}
|
| +} // namespace
|
| +
|
| +// ===================================================================
|
| +
|
| +void ImmutableMessageLiteGenerator::
|
| +GenerateExtensionRegistrationCode(io::Printer* printer) {
|
| + for (int i = 0; i < descriptor_->extension_count(); i++) {
|
| + ImmutableExtensionLiteGenerator(descriptor_->extension(i), context_)
|
| + .GenerateRegistrationCode(printer);
|
| + }
|
| +
|
| + for (int i = 0; i < descriptor_->nested_type_count(); i++) {
|
| + ImmutableMessageLiteGenerator(descriptor_->nested_type(i), context_)
|
| + .GenerateExtensionRegistrationCode(printer);
|
| }
|
| +}
|
|
|
| +// ===================================================================
|
| +void ImmutableMessageLiteGenerator::
|
| +GenerateConstructor(io::Printer* printer) {
|
| printer->Print(
|
| - "doneParsing();\n");
|
| + "private $classname$() {\n",
|
| + "classname", descriptor_->name());
|
| + printer->Indent();
|
| +
|
| + // Initialize all fields to default.
|
| + GenerateInitializers(printer);
|
|
|
| - printer->Outdent();
|
| printer->Outdent();
|
| printer->Print(
|
| - " }\n" // finally
|
| "}\n");
|
| }
|
|
|
| @@ -1167,7 +1088,6 @@ void ImmutableMessageLiteGenerator::GenerateInitializers(io::Printer* printer) {
|
| }
|
| }
|
|
|
| -
|
| } // namespace java
|
| } // namespace compiler
|
| } // namespace protobuf
|
|
|