diff --git a/java/core/src/main/java/com/google/protobuf/Descriptors.java b/java/core/src/main/java/com/google/protobuf/Descriptors.java index 75456869fa12..f3365e24cc22 100644 --- a/java/core/src/main/java/com/google/protobuf/Descriptors.java +++ b/java/core/src/main/java/com/google/protobuf/Descriptors.java @@ -1266,7 +1266,9 @@ public OneofDescriptor getRealContainingOneof() { * Returns true if this field was syntactically written with "optional" in the .proto file. * Excludes singular proto3 fields that do not have a label. */ - public boolean hasOptionalKeyword() { + @Deprecated + public + boolean hasOptionalKeyword() { return isProto3Optional || (file.getSyntax() == Syntax.PROTO2 && isOptional() && getContainingOneof() == null); } diff --git a/java/core/src/main/java/com/google/protobuf/LegacyDescriptorsUtil.java b/java/core/src/main/java/com/google/protobuf/LegacyDescriptorsUtil.java index b091752a4809..8be98bf2dc89 100644 --- a/java/core/src/main/java/com/google/protobuf/LegacyDescriptorsUtil.java +++ b/java/core/src/main/java/com/google/protobuf/LegacyDescriptorsUtil.java @@ -30,6 +30,7 @@ package com.google.protobuf; +import com.google.protobuf.Descriptors.FieldDescriptor; import com.google.protobuf.Descriptors.FileDescriptor; import com.google.protobuf.Descriptors.OneofDescriptor; @@ -70,6 +71,16 @@ public static Syntax getSyntax(FileDescriptor descriptor) { private LegacyFileDescriptor() {} } + /** Wraps FieldDescriptor */ + public static final class LegacyFieldDescriptor { + + public static boolean hasOptionalKeyword(FieldDescriptor descriptor) { + return descriptor.hasOptionalKeyword(); + } + + private LegacyFieldDescriptor() {} + } + /** Wraps OneofDescriptor */ public static final class LegacyOneofDescriptor {