Breaking change: Make deprecated Java gencode PARSER variable private.

This was marked deprecated ~8 years ago.

PiperOrigin-RevId: 584690916
pull/14834/head
Sandy Zhang 1 year ago committed by Copybara-Service
parent c25e9ca0f8
commit b4858b255b
  1. 7
      src/google/protobuf/compiler/java/helpers.h
  2. 5
      src/google/protobuf/compiler/java/message.cc
  3. 6
      src/google/protobuf/compiler/java/message_field.cc

@ -344,13 +344,6 @@ inline bool HasHasbit(const FieldDescriptor* descriptor) {
return internal::cpp::HasHasbit(descriptor); return internal::cpp::HasHasbit(descriptor);
} }
// Whether generate classes expose public PARSER instances.
inline bool ExposePublicParser(const FileDescriptor* descriptor) {
// TODO: Mark the PARSER private in 3.1.x releases.
return FileDescriptorLegacy(descriptor).syntax() ==
FileDescriptorLegacy::Syntax::SYNTAX_PROTO2;
}
// Whether unknown enum values are kept (i.e., not stored in UnknownFieldSet // 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 // but in the message and can be queried using additional getters that return
// ints. // ints.

@ -1140,7 +1140,7 @@ void ImmutableMessageGenerator::GenerateExtensionRegistrationCode(
// =================================================================== // ===================================================================
void ImmutableMessageGenerator::GenerateParser(io::Printer* printer) { void ImmutableMessageGenerator::GenerateParser(io::Printer* printer) {
printer->Print( printer->Print(
"$visibility$ static final com.google.protobuf.Parser<$classname$>\n" "private static final com.google.protobuf.Parser<$classname$>\n"
" PARSER = new com.google.protobuf.AbstractParser<$classname$>() {\n" " PARSER = new com.google.protobuf.AbstractParser<$classname$>() {\n"
" @java.lang.Override\n" " @java.lang.Override\n"
" public $classname$ parsePartialFrom(\n" " public $classname$ parsePartialFrom(\n"
@ -1173,9 +1173,6 @@ void ImmutableMessageGenerator::GenerateParser(io::Printer* printer) {
" return PARSER;\n" " return PARSER;\n"
"}\n" "}\n"
"\n", "\n",
"visibility",
ExposePublicParser(descriptor_->file()) ? "@java.lang.Deprecated public"
: "private",
"classname", descriptor_->name()); "classname", descriptor_->name());
} }

@ -62,11 +62,7 @@ void SetMessageVariables(
: ""}); : ""});
(*variables)["on_changed"] = "onChanged();"; (*variables)["on_changed"] = "onChanged();";
(*variables)["ver"] = GeneratedCodeVersionSuffix(); (*variables)["ver"] = GeneratedCodeVersionSuffix();
(*variables)["get_parser"] = (*variables)["get_parser"] = "parser()";
ExposePublicParser(descriptor->message_type()->file()) &&
context->options().opensource_runtime
? "PARSER"
: "parser()";
if (HasHasbit(descriptor)) { if (HasHasbit(descriptor)) {
// For singular messages and builders, one bit is used for the hasField bit. // For singular messages and builders, one bit is used for the hasField bit.

Loading…
Cancel
Save