浏览代码

Make the PARSER @Deprecated public.

(cherry-picking an intenral change).
Feng Xiao 10 年之前
父节点
当前提交
cc5a1bfede
共有 2 个文件被更改,包括 11 次插入2 次删除
  1. 6 0
      src/google/protobuf/compiler/java/java_helpers.h
  2. 5 2
      src/google/protobuf/compiler/java/java_message.cc

+ 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(