Skip to content

Commit

Permalink
Remove redundant 'get_has_field_bit_message' versus 'is_field_present…
Browse files Browse the repository at this point in the history
…_message'

PiperOrigin-RevId: 696936553
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Nov 15, 2024
1 parent 8718872 commit 9fdf3f8
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 93 deletions.
17 changes: 0 additions & 17 deletions csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs

This file was deleted.

3 changes: 1 addition & 2 deletions src/google/protobuf/compiler/java/full/enum_field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ void SetEnumVariables(
descriptor->options().deprecated() ? "@java.lang.Deprecated " : "";
if (HasHasbit(descriptor)) {
// For singular messages and builders, one bit is used for the hasField bit.
(*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex);
// Note that these have a trailing ";".
(*variables)["set_has_field_bit_message"] =
absl::StrCat(GenerateSetBit(messageBitIndex), ";");
Expand Down Expand Up @@ -162,7 +161,7 @@ void ImmutableEnumFieldGenerator::GenerateMembers(io::Printer* printer) const {
printer->Print(variables_,
"@java.lang.Override $deprecation$public boolean "
"${$has$capitalized_name$$}$() {\n"
" return $get_has_field_bit_message$;\n"
" return $is_field_present_message$;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
Expand Down
32 changes: 9 additions & 23 deletions src/google/protobuf/compiler/java/full/message_field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ void SetMessageVariables(

if (HasHasbit(descriptor)) {
// For singular messages and builders, one bit is used for the hasField bit.
(*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex);

// Note that these have a trailing ";".
(*variables)["set_has_field_bit_to_local"] =
GenerateSetBitToLocal(messageBitIndex);
Expand Down Expand Up @@ -141,27 +139,15 @@ void ImmutableMessageFieldGenerator::GenerateMembers(
printer->Print(variables_, "private $type$ $name$_;\n");
PrintExtraFieldInfo(variables_, printer);

if (HasHasbit(descriptor_)) {
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER,
context_->options());
printer->Print(
variables_,
"@java.lang.Override\n"
"$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $get_has_field_bit_message$;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
} else {
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER,
context_->options());
printer->Print(
variables_,
"@java.lang.Override\n"
"$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $name$_ != null;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER,
context_->options());
printer->Print(variables_,
"@java.lang.Override\n"
"$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $is_field_present_message$;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);

WriteFieldAccessorDocComment(printer, descriptor_, GETTER,
context_->options());
printer->Print(
Expand Down
3 changes: 1 addition & 2 deletions src/google/protobuf/compiler/java/full/primitive_field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ void SetPrimitiveVariables(

if (HasHasbit(descriptor)) {
// For singular messages and builders, one bit is used for the hasField bit.
(*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex);
// Note that these have a trailing ";".
(*variables)["set_has_field_bit_to_local"] =
absl::StrCat(GenerateSetBitToLocal(messageBitIndex), ";");
Expand Down Expand Up @@ -243,7 +242,7 @@ void ImmutablePrimitiveFieldGenerator::GenerateMembers(
variables_,
"@java.lang.Override\n"
"$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $get_has_field_bit_message$;\n"
" return $is_field_present_message$;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
Expand Down
4 changes: 1 addition & 3 deletions src/google/protobuf/compiler/java/full/string_field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ void SetPrimitiveVariables(

if (HasHasbit(descriptor)) {
// For singular messages and builders, one bit is used for the hasField bit.
(*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex);
(*variables)["set_has_field_bit_to_local"] =
GenerateSetBitToLocal(messageBitIndex);

Expand All @@ -85,7 +84,6 @@ void SetPrimitiveVariables(

(*variables)["is_field_present_message"] = GenerateGetBit(messageBitIndex);
} else {
(*variables)["get_has_field_bit_message"] = "";
(*variables)["set_has_field_bit_to_local"] = "";
(*variables)["set_has_field_bit_message"] = "";

Expand Down Expand Up @@ -200,7 +198,7 @@ void ImmutableStringFieldGenerator::GenerateMembers(
variables_,
"@java.lang.Override\n"
"$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $get_has_field_bit_message$;\n"
" return $is_field_present_message$;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
Expand Down
4 changes: 1 addition & 3 deletions src/google/protobuf/compiler/java/lite/enum_field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ void SetEnumVariables(
absl::StrCat(1 << (messageBitIndex % 32));
}
// For singular messages and builders, one bit is used for the hasField bit.
(*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex);

// Note that these have a trailing ";".
(*variables)["set_has_field_bit_message"] =
absl::StrCat(GenerateSetBit(messageBitIndex), ";");
Expand Down Expand Up @@ -173,7 +171,7 @@ void ImmutableEnumFieldLiteGenerator::GenerateMembers(
variables_,
"@java.lang.Override\n"
"$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $get_has_field_bit_message$;\n"
" return $is_field_present_message$;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
Expand Down
52 changes: 15 additions & 37 deletions src/google/protobuf/compiler/java/lite/message_field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ void SetMessageVariables(

if (HasHasbit(descriptor)) {
// For singular messages and builders, one bit is used for the hasField bit.
(*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex);

// Note that these have a trailing ";".
(*variables)["set_has_field_bit_message"] =
absl::StrCat(GenerateSetBit(messageBitIndex), ";");
Expand Down Expand Up @@ -129,41 +127,21 @@ void ImmutableMessageFieldLiteGenerator::GenerateMembers(
printer->Print(variables_, "private $type$ $name$_;\n");
PrintExtraFieldInfo(variables_, printer);

if (HasHasbit(descriptor_)) {
WriteFieldDocComment(printer, descriptor_, context_->options());
printer->Print(
variables_,
"@java.lang.Override\n"
"$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $get_has_field_bit_message$;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_, context_->options());
printer->Print(
variables_,
"@java.lang.Override\n"
"$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
} else {
WriteFieldDocComment(printer, descriptor_, context_->options());
printer->Print(
variables_,
"@java.lang.Override\n"
"$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $name$_ != null;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_, context_->options());
printer->Print(
variables_,
"@java.lang.Override\n"
"$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_, context_->options());
printer->Print(variables_,
"@java.lang.Override\n"
"$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $is_field_present_message$;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_, context_->options());
printer->Print(
variables_,
"@java.lang.Override\n"
"$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);

// Field.Builder setField(Field value)
WriteFieldDocComment(printer, descriptor_, context_->options());
Expand Down
4 changes: 1 addition & 3 deletions src/google/protobuf/compiler/java/lite/primitive_field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ void SetPrimitiveVariables(

if (HasHasbit(descriptor)) {
// For singular messages and builders, one bit is used for the hasField bit.
(*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex);

// Note that these have a trailing ";".
(*variables)["set_has_field_bit_message"] =
absl::StrCat(GenerateSetBit(messageBitIndex), ";");
Expand Down Expand Up @@ -231,7 +229,7 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateMembers(
variables_,
"@java.lang.Override\n"
"$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $get_has_field_bit_message$;\n"
" return $is_field_present_message$;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
Expand Down
4 changes: 1 addition & 3 deletions src/google/protobuf/compiler/java/lite/string_field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ void SetPrimitiveVariables(
absl::StrCat(1 << (messageBitIndex % 32));
}
// For singular messages and builders, one bit is used for the hasField bit.
(*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex);

// Note that these have a trailing ";".
(*variables)["set_has_field_bit_message"] =
absl::StrCat(GenerateSetBit(messageBitIndex), ";");
Expand Down Expand Up @@ -190,7 +188,7 @@ void ImmutableStringFieldLiteGenerator::GenerateMembers(
variables_,
"@java.lang.Override\n"
"$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $get_has_field_bit_message$;\n"
" return $is_field_present_message$;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
Expand Down

0 comments on commit 9fdf3f8

Please sign in to comment.