Breaking Change: Remove unnecessary generated overrides for GeneratedMessage.Builder methods:

setUnknownFields
mergeUnknownFields
clone
setField
clearField
clearOneof
setRepeatedField
addRepeatedField
setExtension
addExtension
clearExtension

PiperOrigin-RevId: 597677225
pull/15413/head
Protobuf Team Bot 11 months ago committed by Copybara-Service
parent 03440ec744
commit 7bff169d32
  1. 97
      src/google/protobuf/compiler/java/message_builder.cc

@ -11,7 +11,6 @@
#include "google/protobuf/compiler/java/message_builder.h"
#include <algorithm>
#include <memory>
#include <vector>
@ -19,7 +18,6 @@
#include "absl/container/flat_hash_map.h"
#include "absl/strings/ascii.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/substitute.h"
#include "google/protobuf/compiler/java/context.h"
#include "google/protobuf/compiler/java/doc_comment.h"
#include "google/protobuf/compiler/java/enum.h"
@ -28,7 +26,6 @@
#include "google/protobuf/compiler/java/helpers.h"
#include "google/protobuf/compiler/java/name_resolver.h"
#include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/io/coded_stream.h"
#include "google/protobuf/io/printer.h"
#include "google/protobuf/wire_format.h"
@ -168,27 +165,6 @@ void MessageBuilderGenerator::Generate(io::Printer* printer) {
.GenerateBuilderMembers(printer);
}
if (context_->options().opensource_runtime) {
// Override methods declared in GeneratedMessage to return the concrete
// generated type so callsites won't depend on GeneratedMessage. This
// is needed to keep binary compatibility when we change generated code
// to subclass a different GeneratedMessage class (e.g., in v3.0.0 release
// we changed all generated code to subclass GeneratedMessageV3).
printer->Print(
"@java.lang.Override\n"
"public final Builder setUnknownFields(\n"
" final com.google.protobuf.UnknownFieldSet unknownFields) {\n"
" return super.setUnknownFields(unknownFields);\n"
"}\n"
"\n"
"@java.lang.Override\n"
"public final Builder mergeUnknownFields(\n"
" final com.google.protobuf.UnknownFieldSet unknownFields) {\n"
" return super.mergeUnknownFields(unknownFields);\n"
"}\n"
"\n");
}
printer->Print(
"\n"
"// @@protoc_insertion_point(builder_scope:$full_name$)\n",
@ -412,79 +388,6 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods(
GenerateBuildPartial(printer);
if (context_->options().opensource_runtime) {
// Override methods declared in GeneratedMessage to return the concrete
// generated type so callsites won't depend on GeneratedMessage. This
// is needed to keep binary compatibility when we change generated code
// to subclass a different GeneratedMessage class (e.g., in v3.0.0 release
// we changed all generated code to subclass GeneratedMessageV3).
printer->Print(
"@java.lang.Override\n"
"public Builder clone() {\n"
" return super.clone();\n"
"}\n"
"@java.lang.Override\n"
"public Builder setField(\n"
" com.google.protobuf.Descriptors.FieldDescriptor field,\n"
" java.lang.Object value) {\n"
" return super.setField(field, value);\n"
"}\n"
"@java.lang.Override\n"
"public Builder clearField(\n"
" com.google.protobuf.Descriptors.FieldDescriptor field) {\n"
" return super.clearField(field);\n"
"}\n"
"@java.lang.Override\n"
"public Builder clearOneof(\n"
" com.google.protobuf.Descriptors.OneofDescriptor oneof) {\n"
" return super.clearOneof(oneof);\n"
"}\n"
"@java.lang.Override\n"
"public Builder setRepeatedField(\n"
" com.google.protobuf.Descriptors.FieldDescriptor field,\n"
" int index, java.lang.Object value) {\n"
" return super.setRepeatedField(field, index, value);\n"
"}\n"
"@java.lang.Override\n"
"public Builder addRepeatedField(\n"
" com.google.protobuf.Descriptors.FieldDescriptor field,\n"
" java.lang.Object value) {\n"
" return super.addRepeatedField(field, value);\n"
"}\n");
if (descriptor_->extension_range_count() > 0) {
printer->Print(
"@java.lang.Override\n"
"public <Type> Builder setExtension(\n"
" com.google.protobuf.GeneratedMessage.GeneratedExtension<\n"
" $classname$, Type> extension,\n"
" Type value) {\n"
" return super.setExtension(extension, value);\n"
"}\n"
"@java.lang.Override\n"
"public <Type> Builder setExtension(\n"
" com.google.protobuf.GeneratedMessage.GeneratedExtension<\n"
" $classname$, java.util.List<Type>> extension,\n"
" int index, Type value) {\n"
" return super.setExtension(extension, index, value);\n"
"}\n"
"@java.lang.Override\n"
"public <Type> Builder addExtension(\n"
" com.google.protobuf.GeneratedMessage.GeneratedExtension<\n"
" $classname$, java.util.List<Type>> extension,\n"
" Type value) {\n"
" return super.addExtension(extension, value);\n"
"}\n"
"@java.lang.Override\n"
"public <T> Builder clearExtension(\n"
" com.google.protobuf.GeneratedMessage.GeneratedExtension<\n"
" $classname$, T> extension) {\n"
" return super.clearExtension(extension);\n"
"}\n",
"classname", name_resolver_->GetImmutableClassName(descriptor_));
}
}
// -----------------------------------------------------------------
if (context_->HasGeneratedMethods(descriptor_)) {

Loading…
Cancel
Save