Skip to content

Commit

Permalink
Automated rollback of commit 67ac9eb.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 503521593
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Jan 20, 2023
1 parent 17a9313 commit 3629ca3
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 65 deletions.
8 changes: 4 additions & 4 deletions src/google/protobuf/compiler/java/enum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void EnumGenerator::Generate(io::Printer* printer) {
printer->Annotate("name", canonical_values_[i]);
}

if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
if (ordinal_is_index) {
printer->Print("${$UNRECOGNIZED$}$(-1),\n", "{", "", "}", "");
} else {
Expand Down Expand Up @@ -167,7 +167,7 @@ void EnumGenerator::Generate(io::Printer* printer) {
printer->Print(
"\n"
"public final int getNumber() {\n");
if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
if (ordinal_is_index) {
printer->Print(
" if (this == UNRECOGNIZED) {\n"
Expand Down Expand Up @@ -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_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
if (ordinal_is_index) {
printer->Print(
" if (this == UNRECOGNIZED) {\n"
Expand Down Expand Up @@ -346,7 +346,7 @@ void EnumGenerator::Generate(io::Printer* printer) {
" \"EnumValueDescriptor is not for this type.\");\n"
" }\n",
"classname", descriptor_->name());
if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(
" if (desc.getIndex() == -1) {\n"
" return UNRECOGNIZED;\n"
Expand Down
34 changes: 17 additions & 17 deletions src/google/protobuf/compiler/java/enum_field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void SetEnumVariables(
(*variables)["get_has_field_bit_from_local"] =
GenerateGetBitFromLocal(builderBitIndex);

if (SupportUnknownEnumValue(descriptor)) {
if (SupportUnknownEnumValue(descriptor->file())) {
variables->insert(
{"unknown", absl::StrCat((*variables)["type"], ".UNRECOGNIZED")});
} else {
Expand Down Expand Up @@ -167,7 +167,7 @@ void ImmutableEnumFieldGenerator::GenerateInterfaceMembers(
printer->Print(variables_,
"$deprecation$boolean has$capitalized_name$();\n");
}
if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(variables_,
"$deprecation$int get$capitalized_name$Value();\n");
Expand All @@ -188,7 +188,7 @@ void ImmutableEnumFieldGenerator::GenerateMembers(io::Printer* printer) const {
"}\n");
printer->Annotate("{", "}", descriptor_);
}
if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(variables_,
"@java.lang.Override $deprecation$public int "
Expand Down Expand Up @@ -219,7 +219,7 @@ void ImmutableEnumFieldGenerator::GenerateBuilderMembers(
"}\n");
printer->Annotate("{", "}", descriptor_);
}
if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(variables_,
"@java.lang.Override $deprecation$public int "
Expand Down Expand Up @@ -286,7 +286,7 @@ void ImmutableEnumFieldGenerator::GenerateKotlinDslMembers(
" $kt_dsl_builder$.${$set$capitalized_name$$}$(value)\n"
" }\n");

if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(
variables_,
"$kt_deprecation$public var $kt_name$Value: kotlin.Int\n"
Expand Down Expand Up @@ -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_)) {
} else if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(
variables_,
"if (other.$name$_ != $default_number$) {\n"
Expand All @@ -362,7 +362,7 @@ void ImmutableEnumFieldGenerator::GenerateBuildingCode(

void ImmutableEnumFieldGenerator::GenerateBuilderParsingCode(
io::Printer* printer) const {
if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(variables_,
"$name$_ = input.readEnum();\n"
"$set_has_field_bit_builder$\n");
Expand Down Expand Up @@ -437,7 +437,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateMembers(
"}\n");
printer->Annotate("{", "}", descriptor_);

if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(
variables_,
Expand Down Expand Up @@ -473,7 +473,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers(
"}\n");
printer->Annotate("{", "}", descriptor_);

if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(
variables_,
Expand Down Expand Up @@ -552,7 +552,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuildingCode(

void ImmutableEnumOneofFieldGenerator::GenerateMergingCode(
io::Printer* printer) const {
if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(
variables_,
"set$capitalized_name$Value(other.get$capitalized_name$Value());\n");
Expand All @@ -564,7 +564,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateMergingCode(

void ImmutableEnumOneofFieldGenerator::GenerateBuilderParsingCode(
io::Printer* printer) const {
if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(variables_,
"int rawValue = input.readEnum();\n"
"$set_oneof_case_message$;\n"
Expand Down Expand Up @@ -604,7 +604,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateSerializedSizeCode(

void ImmutableEnumOneofFieldGenerator::GenerateEqualsCode(
io::Printer* printer) const {
if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(
variables_,
"if (get$capitalized_name$Value()\n"
Expand All @@ -619,7 +619,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateEqualsCode(

void ImmutableEnumOneofFieldGenerator::GenerateHashCode(
io::Printer* printer) const {
if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(variables_,
"hash = (37 * hash) + $constant_name$;\n"
"hash = (53 * hash) + get$capitalized_name$Value();\n");
Expand Down Expand Up @@ -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_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_GETTER);
printer->Print(variables_,
"$deprecation$java.util.List<java.lang.Integer>\n"
Expand Down Expand Up @@ -716,7 +716,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateMembers(
" return $name$_converter_.convert($name$_.get(index));\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_GETTER);
printer->Print(variables_,
"@java.lang.Override\n"
Expand Down Expand Up @@ -844,7 +844,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuilderMembers(
"}\n");
printer->Annotate("{", "}", descriptor_);

if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_GETTER);
printer->Print(variables_,
"$deprecation$public java.util.List<java.lang.Integer>\n"
Expand Down Expand Up @@ -954,7 +954,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuildingCode(
void RepeatedImmutableEnumFieldGenerator::GenerateBuilderParsingCode(
io::Printer* printer) const {
// Read and store the enum
if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(variables_,
"int tmpRaw = input.readEnum();\n"
"ensure$capitalized_name$IsMutable();\n"
Expand Down
28 changes: 14 additions & 14 deletions src/google/protobuf/compiler/java/enum_field_lite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void SetEnumVariables(
(*variables)["set_has_field_bit_to_local"] =
GenerateSetBitToLocal(messageBitIndex);

if (SupportUnknownEnumValue(descriptor)) {
if (SupportUnknownEnumValue(descriptor->file())) {
variables->insert(
{"unknown", absl::StrCat((*variables)["type"], ".UNRECOGNIZED")});
} else {
Expand Down Expand Up @@ -172,7 +172,7 @@ void ImmutableEnumFieldLiteGenerator::GenerateInterfaceMembers(
"$deprecation$boolean ${$has$capitalized_name$$}$();\n");
printer->Annotate("{", "}", descriptor_);
}
if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(variables_,
"$deprecation$int ${$get$capitalized_name$Value$}$();\n");
Expand Down Expand Up @@ -212,7 +212,7 @@ void ImmutableEnumFieldLiteGenerator::GenerateMembers(
"}\n");
printer->Annotate("{", "}", descriptor_);
}
if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(
variables_,
Expand All @@ -232,7 +232,7 @@ void ImmutableEnumFieldLiteGenerator::GenerateMembers(
printer->Annotate("{", "}", descriptor_);

// Generate private setters for the builder to proxy into.
if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, SETTER);
printer->Print(variables_,
"private void set$capitalized_name$Value(int value) {\n"
Expand Down Expand Up @@ -266,7 +266,7 @@ void ImmutableEnumFieldLiteGenerator::GenerateBuilderMembers(
"}\n");
printer->Annotate("{", "}", descriptor_);
}
if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(
variables_,
Expand Down Expand Up @@ -327,7 +327,7 @@ void ImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers(
" $kt_dsl_builder$.${$set$capitalized_name$$}$(value)\n"
" }\n");

if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(
variables_,
"$kt_deprecation$public var $kt_name$Value: kotlin.Int\n"
Expand Down Expand Up @@ -409,7 +409,7 @@ void ImmutableEnumOneofFieldLiteGenerator::GenerateMembers(
"}\n");
printer->Annotate("{", "}", descriptor_);

if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(
variables_,
Expand All @@ -436,7 +436,7 @@ void ImmutableEnumOneofFieldLiteGenerator::GenerateMembers(
printer->Annotate("{", "}", descriptor_);

// Generate private setters for the builder to proxy into.
if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, SETTER);
printer->Print(variables_,
"private void set$capitalized_name$Value(int value) {\n"
Expand Down Expand Up @@ -485,7 +485,7 @@ void ImmutableEnumOneofFieldLiteGenerator::GenerateBuilderMembers(
"}\n");
printer->Annotate("{", "}", descriptor_);

if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(
variables_,
Expand Down Expand Up @@ -571,7 +571,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateInterfaceMembers(
variables_,
"$deprecation$$type$ ${$get$capitalized_name$$}$(int index);\n");
printer->Annotate("{", "}", descriptor_);
if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_GETTER);
printer->Print(variables_,
"$deprecation$java.util.List<java.lang.Integer>\n"
Expand Down Expand Up @@ -641,7 +641,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateMembers(
" return result == null ? $unknown$ : result;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_GETTER);
printer->Print(variables_,
"@java.lang.Override\n"
Expand Down Expand Up @@ -707,7 +707,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateMembers(
" $name$_ = emptyIntList();\n"
"}\n");

if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, SETTER);
printer->Print(variables_,
"private void set$capitalized_name$Value(\n"
Expand Down Expand Up @@ -740,7 +740,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateFieldInfo(
WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_),
output);
printer->Print(variables_, "\"$name$_\",\n");
if (!SupportUnknownEnumValue(descriptor_)) {
if (!SupportUnknownEnumValue(descriptor_->file())) {
PrintEnumVerifierLogic(printer, descriptor_, variables_,
/*var_name=*/"$type$",
/*terminating_string=*/",\n",
Expand Down Expand Up @@ -815,7 +815,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateBuilderMembers(
"}\n");
printer->Annotate("{", "}", descriptor_);

if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_GETTER);
printer->Print(variables_,
"@java.lang.Override\n"
Expand Down
6 changes: 3 additions & 3 deletions src/google/protobuf/compiler/java/enum_lite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
printer->Annotate("name", canonical_values_[i]);
}

if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print("${$UNRECOGNIZED$}$(-1),\n", "{", "", "}", "");
printer->Annotate("{", "}", descriptor_);
}
Expand Down Expand Up @@ -142,7 +142,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
"\n"
"@java.lang.Override\n"
"public final int getNumber() {\n");
if (SupportUnknownEnumValue(descriptor_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(
" if (this == UNRECOGNIZED) {\n"
" throw new java.lang.IllegalArgumentException(\n"
Expand Down Expand Up @@ -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_)) {
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(
" if (this != UNRECOGNIZED) {\n"
" result.append(\" number=\").append(getNumber());\n"
Expand Down
9 changes: 5 additions & 4 deletions src/google/protobuf/compiler/java/helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -932,10 +932,11 @@ int GetExperimentalJavaFieldType(const FieldDescriptor* field) {
}

if (field->is_map()) {
const FieldDescriptor* value = field->message_type()->map_value();
if (GetJavaType(value) == JAVATYPE_ENUM &&
!SupportUnknownEnumValue(field)) {
extra_bits |= kMapWithProto2EnumValue;
if (!SupportUnknownEnumValue(field)) {
const FieldDescriptor* value = field->message_type()->map_value();
if (GetJavaType(value) == JAVATYPE_ENUM) {
extra_bits |= kMapWithProto2EnumValue;
}
}
return kMapFieldType | extra_bits;
} else if (field->is_packed()) {
Expand Down
16 changes: 6 additions & 10 deletions src/google/protobuf/compiler/java/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,19 +384,15 @@ inline bool ExposePublicParser(const FileDescriptor* descriptor) {
return descriptor->syntax() == FileDescriptor::SYNTAX_PROTO2;
}

inline bool SupportUnknownEnumValue(const EnumDescriptor* e) {
return !e->is_closed();
// 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 FieldDescriptor* field) {
// 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());
return field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3;
}

// Check whether a message has repeated fields.
Expand Down
Loading

0 comments on commit 3629ca3

Please sign in to comment.