From 67ac9eb4e93552033b57b7b817da962ba529d9db Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 20 Jan 2023 12:32:47 -0800 Subject: [PATCH] Migrate away from examining the syntax of a proto file via reflection. PiperOrigin-RevId: 503500019 --- src/google/protobuf/compiler/java/enum.cc | 8 ++--- .../protobuf/compiler/java/enum_field.cc | 34 +++++++++---------- .../protobuf/compiler/java/enum_field_lite.cc | 28 +++++++-------- .../protobuf/compiler/java/enum_lite.cc | 6 ++-- src/google/protobuf/compiler/java/helpers.cc | 9 +++-- src/google/protobuf/compiler/java/helpers.h | 16 +++++---- .../protobuf/compiler/java/map_field.cc | 12 +++---- .../protobuf/compiler/java/map_field_lite.cc | 14 ++++---- 8 files changed, 65 insertions(+), 62 deletions(-) diff --git a/src/google/protobuf/compiler/java/enum.cc b/src/google/protobuf/compiler/java/enum.cc index 84c99e6779..341361f8f0 100644 --- a/src/google/protobuf/compiler/java/enum.cc +++ b/src/google/protobuf/compiler/java/enum.cc @@ -119,7 +119,7 @@ void EnumGenerator::Generate(io::Printer* printer) { printer->Annotate("name", canonical_values_[i]); } - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { if (ordinal_is_index) { printer->Print("${$UNRECOGNIZED$}$(-1),\n", "{", "", "}", ""); } else { @@ -167,7 +167,7 @@ void EnumGenerator::Generate(io::Printer* printer) { printer->Print( "\n" "public final int getNumber() {\n"); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { if (ordinal_is_index) { printer->Print( " if (this == UNRECOGNIZED) {\n" @@ -251,7 +251,7 @@ void EnumGenerator::Generate(io::Printer* printer) { printer->Print( "public final com.google.protobuf.Descriptors.EnumValueDescriptor\n" " getValueDescriptor() {\n"); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { if (ordinal_is_index) { printer->Print( " if (this == UNRECOGNIZED) {\n" @@ -346,7 +346,7 @@ void EnumGenerator::Generate(io::Printer* printer) { " \"EnumValueDescriptor is not for this type.\");\n" " }\n", "classname", descriptor_->name()); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { printer->Print( " if (desc.getIndex() == -1) {\n" " return UNRECOGNIZED;\n" diff --git a/src/google/protobuf/compiler/java/enum_field.cc b/src/google/protobuf/compiler/java/enum_field.cc index 528220ca53..7a02399487 100644 --- a/src/google/protobuf/compiler/java/enum_field.cc +++ b/src/google/protobuf/compiler/java/enum_field.cc @@ -120,7 +120,7 @@ void SetEnumVariables( (*variables)["get_has_field_bit_from_local"] = GenerateGetBitFromLocal(builderBitIndex); - if (SupportUnknownEnumValue(descriptor->file())) { + if (SupportUnknownEnumValue(descriptor)) { variables->insert( {"unknown", absl::StrCat((*variables)["type"], ".UNRECOGNIZED")}); } else { @@ -167,7 +167,7 @@ void ImmutableEnumFieldGenerator::GenerateInterfaceMembers( printer->Print(variables_, "$deprecation$boolean has$capitalized_name$();\n"); } - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER); printer->Print(variables_, "$deprecation$int get$capitalized_name$Value();\n"); @@ -188,7 +188,7 @@ void ImmutableEnumFieldGenerator::GenerateMembers(io::Printer* printer) const { "}\n"); printer->Annotate("{", "}", descriptor_); } - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER); printer->Print(variables_, "@java.lang.Override $deprecation$public int " @@ -219,7 +219,7 @@ void ImmutableEnumFieldGenerator::GenerateBuilderMembers( "}\n"); printer->Annotate("{", "}", descriptor_); } - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER); printer->Print(variables_, "@java.lang.Override $deprecation$public int " @@ -286,7 +286,7 @@ void ImmutableEnumFieldGenerator::GenerateKotlinDslMembers( " $kt_dsl_builder$.${$set$capitalized_name$$}$(value)\n" " }\n"); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { printer->Print( variables_, "$kt_deprecation$public var $kt_name$Value: kotlin.Int\n" @@ -338,7 +338,7 @@ void ImmutableEnumFieldGenerator::GenerateMergingCode( "if (other.has$capitalized_name$()) {\n" " set$capitalized_name$(other.get$capitalized_name$());\n" "}\n"); - } else if (SupportUnknownEnumValue(descriptor_->file())) { + } else if (SupportUnknownEnumValue(descriptor_)) { printer->Print( variables_, "if (other.$name$_ != $default_number$) {\n" @@ -362,7 +362,7 @@ void ImmutableEnumFieldGenerator::GenerateBuildingCode( void ImmutableEnumFieldGenerator::GenerateBuilderParsingCode( io::Printer* printer) const { - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { printer->Print(variables_, "$name$_ = input.readEnum();\n" "$set_has_field_bit_builder$\n"); @@ -437,7 +437,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateMembers( "}\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER); printer->Print( variables_, @@ -473,7 +473,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers( "}\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER); printer->Print( variables_, @@ -552,7 +552,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuildingCode( void ImmutableEnumOneofFieldGenerator::GenerateMergingCode( io::Printer* printer) const { - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { printer->Print( variables_, "set$capitalized_name$Value(other.get$capitalized_name$Value());\n"); @@ -564,7 +564,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateMergingCode( void ImmutableEnumOneofFieldGenerator::GenerateBuilderParsingCode( io::Printer* printer) const { - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { printer->Print(variables_, "int rawValue = input.readEnum();\n" "$set_oneof_case_message$;\n" @@ -604,7 +604,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateSerializedSizeCode( void ImmutableEnumOneofFieldGenerator::GenerateEqualsCode( io::Printer* printer) const { - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { printer->Print( variables_, "if (get$capitalized_name$Value()\n" @@ -619,7 +619,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateEqualsCode( void ImmutableEnumOneofFieldGenerator::GenerateHashCode( io::Printer* printer) const { - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { printer->Print(variables_, "hash = (37 * hash) + $constant_name$;\n" "hash = (53 * hash) + get$capitalized_name$Value();\n"); @@ -661,7 +661,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateInterfaceMembers( WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); printer->Print(variables_, "$deprecation$$type$ get$capitalized_name$(int index);\n"); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_GETTER); printer->Print(variables_, "$deprecation$java.util.List\n" @@ -716,7 +716,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateMembers( " return $name$_converter_.convert($name$_.get(index));\n" "}\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_GETTER); printer->Print(variables_, "@java.lang.Override\n" @@ -844,7 +844,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuilderMembers( "}\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_GETTER); printer->Print(variables_, "$deprecation$public java.util.List\n" @@ -954,7 +954,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuildingCode( void RepeatedImmutableEnumFieldGenerator::GenerateBuilderParsingCode( io::Printer* printer) const { // Read and store the enum - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { printer->Print(variables_, "int tmpRaw = input.readEnum();\n" "ensure$capitalized_name$IsMutable();\n" diff --git a/src/google/protobuf/compiler/java/enum_field_lite.cc b/src/google/protobuf/compiler/java/enum_field_lite.cc index c15e5e765d..bf5c789f9a 100644 --- a/src/google/protobuf/compiler/java/enum_field_lite.cc +++ b/src/google/protobuf/compiler/java/enum_field_lite.cc @@ -128,7 +128,7 @@ void SetEnumVariables( (*variables)["set_has_field_bit_to_local"] = GenerateSetBitToLocal(messageBitIndex); - if (SupportUnknownEnumValue(descriptor->file())) { + if (SupportUnknownEnumValue(descriptor)) { variables->insert( {"unknown", absl::StrCat((*variables)["type"], ".UNRECOGNIZED")}); } else { @@ -172,7 +172,7 @@ void ImmutableEnumFieldLiteGenerator::GenerateInterfaceMembers( "$deprecation$boolean ${$has$capitalized_name$$}$();\n"); printer->Annotate("{", "}", descriptor_); } - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER); printer->Print(variables_, "$deprecation$int ${$get$capitalized_name$Value$}$();\n"); @@ -212,7 +212,7 @@ void ImmutableEnumFieldLiteGenerator::GenerateMembers( "}\n"); printer->Annotate("{", "}", descriptor_); } - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER); printer->Print( variables_, @@ -232,7 +232,7 @@ void ImmutableEnumFieldLiteGenerator::GenerateMembers( printer->Annotate("{", "}", descriptor_); // Generate private setters for the builder to proxy into. - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, SETTER); printer->Print(variables_, "private void set$capitalized_name$Value(int value) {\n" @@ -266,7 +266,7 @@ void ImmutableEnumFieldLiteGenerator::GenerateBuilderMembers( "}\n"); printer->Annotate("{", "}", descriptor_); } - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER); printer->Print( variables_, @@ -327,7 +327,7 @@ void ImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers( " $kt_dsl_builder$.${$set$capitalized_name$$}$(value)\n" " }\n"); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { printer->Print( variables_, "$kt_deprecation$public var $kt_name$Value: kotlin.Int\n" @@ -409,7 +409,7 @@ void ImmutableEnumOneofFieldLiteGenerator::GenerateMembers( "}\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER); printer->Print( variables_, @@ -436,7 +436,7 @@ void ImmutableEnumOneofFieldLiteGenerator::GenerateMembers( printer->Annotate("{", "}", descriptor_); // Generate private setters for the builder to proxy into. - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, SETTER); printer->Print(variables_, "private void set$capitalized_name$Value(int value) {\n" @@ -485,7 +485,7 @@ void ImmutableEnumOneofFieldLiteGenerator::GenerateBuilderMembers( "}\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER); printer->Print( variables_, @@ -571,7 +571,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateInterfaceMembers( variables_, "$deprecation$$type$ ${$get$capitalized_name$$}$(int index);\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_GETTER); printer->Print(variables_, "$deprecation$java.util.List\n" @@ -641,7 +641,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateMembers( " return result == null ? $unknown$ : result;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_GETTER); printer->Print(variables_, "@java.lang.Override\n" @@ -707,7 +707,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateMembers( " $name$_ = emptyIntList();\n" "}\n"); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, SETTER); printer->Print(variables_, "private void set$capitalized_name$Value(\n" @@ -740,7 +740,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateFieldInfo( WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_), output); printer->Print(variables_, "\"$name$_\",\n"); - if (!SupportUnknownEnumValue(descriptor_->file())) { + if (!SupportUnknownEnumValue(descriptor_)) { PrintEnumVerifierLogic(printer, descriptor_, variables_, /*var_name=*/"$type$", /*terminating_string=*/",\n", @@ -815,7 +815,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateBuilderMembers( "}\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_GETTER); printer->Print(variables_, "@java.lang.Override\n" diff --git a/src/google/protobuf/compiler/java/enum_lite.cc b/src/google/protobuf/compiler/java/enum_lite.cc index 5d10a684bc..2aa2b4c73b 100644 --- a/src/google/protobuf/compiler/java/enum_lite.cc +++ b/src/google/protobuf/compiler/java/enum_lite.cc @@ -97,7 +97,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) { printer->Annotate("name", canonical_values_[i]); } - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { printer->Print("${$UNRECOGNIZED$}$(-1),\n", "{", "", "}", ""); printer->Annotate("{", "}", descriptor_); } @@ -142,7 +142,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) { "\n" "@java.lang.Override\n" "public final int getNumber() {\n"); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { printer->Print( " if (this == UNRECOGNIZED) {\n" " throw new java.lang.IllegalArgumentException(\n" @@ -235,7 +235,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) { " result.append(getClass().getName()).append('@')\n" " .append(java.lang.Integer.toHexString(\n" " java.lang.System.identityHashCode(this)));\n"); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { printer->Print( " if (this != UNRECOGNIZED) {\n" " result.append(\" number=\").append(getNumber());\n" diff --git a/src/google/protobuf/compiler/java/helpers.cc b/src/google/protobuf/compiler/java/helpers.cc index ab4dec6c03..77df7e4855 100644 --- a/src/google/protobuf/compiler/java/helpers.cc +++ b/src/google/protobuf/compiler/java/helpers.cc @@ -932,11 +932,10 @@ int GetExperimentalJavaFieldType(const FieldDescriptor* field) { } if (field->is_map()) { - if (!SupportUnknownEnumValue(field)) { - const FieldDescriptor* value = field->message_type()->map_value(); - if (GetJavaType(value) == JAVATYPE_ENUM) { - extra_bits |= kMapWithProto2EnumValue; - } + const FieldDescriptor* value = field->message_type()->map_value(); + if (GetJavaType(value) == JAVATYPE_ENUM && + !SupportUnknownEnumValue(field)) { + extra_bits |= kMapWithProto2EnumValue; } return kMapFieldType | extra_bits; } else if (field->is_packed()) { diff --git a/src/google/protobuf/compiler/java/helpers.h b/src/google/protobuf/compiler/java/helpers.h index 0ebb3b9ebe..bb60a65324 100644 --- a/src/google/protobuf/compiler/java/helpers.h +++ b/src/google/protobuf/compiler/java/helpers.h @@ -384,15 +384,19 @@ inline bool ExposePublicParser(const FileDescriptor* descriptor) { return descriptor->syntax() == FileDescriptor::SYNTAX_PROTO2; } -// Whether unknown enum values are kept (i.e., not stored in UnknownFieldSet -// but in the message and can be queried using additional getters that return -// ints. -inline bool SupportUnknownEnumValue(const FileDescriptor* descriptor) { - return descriptor->syntax() == FileDescriptor::SYNTAX_PROTO3; +inline bool SupportUnknownEnumValue(const EnumDescriptor* e) { + return !e->is_closed(); } inline bool SupportUnknownEnumValue(const FieldDescriptor* field) { - return field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3; + // If we get in a map field, we are asking about its value type, not the map + // field. + if (field->is_map()) { + field = field->message_type()->map_value(); + } + + GOOGLE_ABSL_CHECK(field->enum_type() != nullptr) << field->type_name(); + return SupportUnknownEnumValue(field->enum_type()); } // Check whether a message has repeated fields. diff --git a/src/google/protobuf/compiler/java/map_field.cc b/src/google/protobuf/compiler/java/map_field.cc index ad82051124..4ebaef24c5 100644 --- a/src/google/protobuf/compiler/java/map_field.cc +++ b/src/google/protobuf/compiler/java/map_field.cc @@ -147,7 +147,7 @@ void SetMessageVariables( {"value_enum_type_pass_through_nullness", absl::StrCat(pass_through_nullness, (*variables)["value_enum_type"])}); - if (SupportUnknownEnumValue(descriptor->file())) { + if (SupportUnknownEnumValue(descriptor)) { // Map unknown values to a special UNRECOGNIZED value if supported. variables->insert( {"unrecognized_value", @@ -275,7 +275,7 @@ void ImmutableMapFieldGenerator::GenerateInterfaceMembers( "$deprecation$$value_enum_type$ ${$get$capitalized_name$OrThrow$}$(\n" " $key_type$ key);\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { printer->Print( variables_, "/**\n" @@ -478,7 +478,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers( "}\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { if (context_->options().opensource_runtime) { printer->Print( variables_, @@ -645,7 +645,7 @@ void ImmutableMapFieldGenerator::GenerateMapGetters( "}\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { printer->Print( variables_, "/**\n" @@ -870,8 +870,8 @@ void ImmutableMapFieldGenerator::GenerateBuildingCode( void ImmutableMapFieldGenerator::GenerateBuilderParsingCode( io::Printer* printer) const { - if (!SupportUnknownEnumValue(descriptor_->file()) && - GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { + if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM && + !SupportUnknownEnumValue(descriptor_)) { printer->Print( variables_, "com.google.protobuf.ByteString bytes = input.readBytes();\n" diff --git a/src/google/protobuf/compiler/java/map_field_lite.cc b/src/google/protobuf/compiler/java/map_field_lite.cc index 87970ef65e..04a4051472 100644 --- a/src/google/protobuf/compiler/java/map_field_lite.cc +++ b/src/google/protobuf/compiler/java/map_field_lite.cc @@ -144,7 +144,7 @@ void SetMessageVariables( {"value_enum_type_pass_through_nullness", absl::StrCat(pass_through_nullness, (*variables)["value_enum_type"])}); - if (SupportUnknownEnumValue(descriptor->file())) { + if (SupportUnknownEnumValue(descriptor)) { // Map unknown values to a special UNRECOGNIZED value if supported. variables->insert( {"unrecognized_value", @@ -248,7 +248,7 @@ void ImmutableMapFieldLiteGenerator::GenerateInterfaceMembers( "$deprecation$$value_enum_type$ ${$get$capitalized_name$OrThrow$}$(\n" " $key_type$ key);\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { printer->Print( variables_, "/**\n" @@ -432,7 +432,7 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers( " return $name$ValueConverter.doForward(map.get(key));\n" "}\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { printer->Print( variables_, "/**\n" @@ -556,7 +556,7 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers( " internalGetMutable$capitalized_name$(),\n" " $name$ValueConverter);\n" "}\n"); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, @@ -583,8 +583,8 @@ void ImmutableMapFieldLiteGenerator::GenerateFieldInfo( printer->Print(variables_, "\"$name$_\",\n" "$default_entry$,\n"); - if (!SupportUnknownEnumValue(descriptor_) && - GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { + if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM && + !SupportUnknownEnumValue(descriptor_)) { PrintEnumVerifierLogic(printer, ValueField(descriptor_), variables_, /*var_name=*/"$value_enum_type$", /*terminating_string=*/",\n", @@ -711,7 +711,7 @@ void ImmutableMapFieldLiteGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - if (SupportUnknownEnumValue(descriptor_->file())) { + if (SupportUnknownEnumValue(descriptor_)) { printer->Print( variables_, "/**\n"