diff --git a/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java b/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java index 2c87302bc239..cea0579424f1 100644 --- a/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java @@ -1396,7 +1396,7 @@ public final BuilderType setExtension( return setExtension((ExtensionLite) extension, value); } /** Set the value of an extension. */ - public final BuilderType setExtension( + public BuilderType setExtension( final GeneratedExtension extension, final Type value) { return setExtension((ExtensionLite) extension, value); } @@ -1407,7 +1407,7 @@ public final BuilderType setExtension( return setExtension((ExtensionLite>) extension, index, value); } /** Set the value of one element of a repeated extension. */ - public final BuilderType setExtension( + public BuilderType setExtension( final GeneratedExtension> extension, final int index, final Type value) { return setExtension((ExtensionLite>) extension, index, value); @@ -1418,7 +1418,7 @@ public final BuilderType addExtension( return addExtension((ExtensionLite>) extension, value); } /** Append a value to a repeated extension. */ - public final BuilderType addExtension( + public BuilderType addExtension( final GeneratedExtension> extension, final Type value) { return addExtension((ExtensionLite>) extension, value); } @@ -1428,7 +1428,7 @@ public final BuilderType clearExtension( return clearExtension((ExtensionLite) extension); } /** Clear an extension. */ - public final BuilderType clearExtension( + public BuilderType clearExtension( final GeneratedExtension extension) { return clearExtension((ExtensionLite) extension); } diff --git a/src/google/protobuf/compiler/java/java_message_builder.cc b/src/google/protobuf/compiler/java/java_message_builder.cc index b3e9e986c478..81a70a1f5134 100644 --- a/src/google/protobuf/compiler/java/java_message_builder.cc +++ b/src/google/protobuf/compiler/java/java_message_builder.cc @@ -181,6 +181,18 @@ Generate(io::Printer* printer) { " return this;\n" "}\n" "\n"); + } else { + printer->Print( + "public final Builder setUnknownFields(\n" + " final com.google.protobuf.UnknownFieldSet unknownFields) {\n" + " return super.setUnknownFields(unknownFields);\n" + "}\n" + "\n" + "public final Builder mergeUnknownFields(\n" + " final com.google.protobuf.UnknownFieldSet unknownFields) {\n" + " return super.mergeUnknownFields(unknownFields);\n" + "}\n" + "\n"); } printer->Print( @@ -438,6 +450,62 @@ GenerateCommonBuilderMethods(io::Printer* printer) { "\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); + printer->Print( + "public Builder clone() {\n" + " return (Builder) super.clone();\n" + "}\n" + "public Builder setField(\n" + " com.google.protobuf.Descriptors.FieldDescriptor field,\n" + " Object value) {\n" + " return (Builder) super.setField(field, value);\n" + "}\n" + "public Builder clearField(\n" + " com.google.protobuf.Descriptors.FieldDescriptor field) {\n" + " return (Builder) super.clearField(field);\n" + "}\n" + "public Builder clearOneof(\n" + " com.google.protobuf.Descriptors.OneofDescriptor oneof) {\n" + " return (Builder) super.clearOneof(oneof);\n" + "}\n" + "public Builder setRepeatedField(\n" + " com.google.protobuf.Descriptors.FieldDescriptor field,\n" + " int index, Object value) {\n" + " return (Builder) super.setRepeatedField(field, index, value);\n" + "}\n" + "public Builder addRepeatedField(\n" + " com.google.protobuf.Descriptors.FieldDescriptor field,\n" + " Object value) {\n" + " return (Builder) super.addRepeatedField(field, value);\n" + "}\n"); + + if (descriptor_->extension_range_count() > 0) { + printer->Print( + "public Builder setExtension(\n" + " com.google.protobuf.GeneratedMessage.GeneratedExtension<\n" + " $classname$, Type> extension,\n" + " Type value) {\n" + " return (Builder) super.setExtension(extension, value);\n" + "}\n" + "public Builder setExtension(\n" + " com.google.protobuf.GeneratedMessage.GeneratedExtension<\n" + " $classname$, java.util.List> extension,\n" + " int index, Type value) {\n" + " return (Builder) super.setExtension(extension, index, value);\n" + "}\n" + "public Builder addExtension(\n" + " com.google.protobuf.GeneratedMessage.GeneratedExtension<\n" + " $classname$, java.util.List> extension,\n" + " Type value) {\n" + " return (Builder) super.addExtension(extension, value);\n" + "}\n" + "public Builder clearExtension(\n" + " com.google.protobuf.GeneratedMessage.GeneratedExtension<\n" + " $classname$, ?> extension) {\n" + " return (Builder) super.clearExtension(extension);\n" + "}\n", + "classname", name_resolver_->GetImmutableClassName(descriptor_)); + } + // ----------------------------------------------------------------- if (context_->HasGeneratedMethods(descriptor_)) {