Quellcode durchsuchen

Merge branch 'beta-1' of github.com:google/protobuf into manual-merge

Jisi Liu vor 10 Jahren
Ursprung
Commit
144ea00659

+ 6 - 0
src/google/protobuf/compiler/java/java_helpers.h

@@ -310,6 +310,12 @@ inline bool SupportFieldPresence(const FileDescriptor* descriptor) {
   return descriptor->syntax() != FileDescriptor::SYNTAX_PROTO3;
 }
 
+// Whether generate classes expose public PARSER instances.
+inline bool ExposePublicParser(const FileDescriptor* descriptor) {
+  // TODO(liujisi): Mark the PARSER private in 3.1.x releases.
+  return descriptor->syntax() == FileDescriptor::SYNTAX_PROTO2;
+}
+
 // 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.

+ 5 - 2
src/google/protobuf/compiler/java/java_message.cc

@@ -1248,8 +1248,11 @@ GenerateParsingConstructor(io::Printer* printer) {
 // ===================================================================
 void ImmutableMessageGenerator::GenerateParser(io::Printer* printer) {
   printer->Print(
-      "private static final com.google.protobuf.Parser<$classname$> PARSER =\n"
-      "    new com.google.protobuf.AbstractParser<$classname$>() {\n",
+      "$visibility$ static final com.google.protobuf.Parser<$classname$>\n"
+      "    PARSER = new com.google.protobuf.AbstractParser<$classname$>() {\n",
+      "visibility",
+      ExposePublicParser(descriptor_->file()) ? "@java.lang.Deprecated public"
+                                              : "private",
       "classname", descriptor_->name());
   printer->Indent();
   printer->Print(