Unverified Commit 1237c3f1 authored by Jisi Liu's avatar Jisi Liu Committed by GitHub

Merge pull request #4045 from pherl/deprecate

Add deprecation annotation for oneof case.
parents 426cf6f3 594ec226
...@@ -37,22 +37,22 @@ import junit.framework.TestCase; ...@@ -37,22 +37,22 @@ import junit.framework.TestCase;
/** /**
* Test field deprecation * Test field deprecation
* *
* @author birdo@google.com (Roberto Scaramuzzi) * @author birdo@google.com (Roberto Scaramuzzi)
*/ */
public class DeprecatedFieldTest extends TestCase { public class DeprecatedFieldTest extends TestCase {
private String[] deprecatedGetterNames = { private String[] deprecatedGetterNames = {
"hasDeprecatedInt32", "hasDeprecatedInt32",
"getDeprecatedInt32"}; "getDeprecatedInt32"};
private String[] deprecatedBuilderGetterNames = { private String[] deprecatedBuilderGetterNames = {
"hasDeprecatedInt32", "hasDeprecatedInt32",
"getDeprecatedInt32", "getDeprecatedInt32",
"clearDeprecatedInt32"}; "clearDeprecatedInt32"};
private String[] deprecatedBuilderSetterNames = { private String[] deprecatedBuilderSetterNames = {
"setDeprecatedInt32"}; "setDeprecatedInt32"};
public void testDeprecatedField() throws Exception { public void testDeprecatedField() throws Exception {
Class<?> deprecatedFields = TestDeprecatedFields.class; Class<?> deprecatedFields = TestDeprecatedFields.class;
Class<?> deprecatedFieldsBuilder = TestDeprecatedFields.Builder.class; Class<?> deprecatedFieldsBuilder = TestDeprecatedFields.Builder.class;
...@@ -72,7 +72,15 @@ public class DeprecatedFieldTest extends TestCase { ...@@ -72,7 +72,15 @@ public class DeprecatedFieldTest extends TestCase {
isDeprecated(method)); isDeprecated(method));
} }
} }
public void testDeprecatedFieldInOneof() throws Exception {
Class<?> oneofCase = TestDeprecatedFields.OneofFieldsCase.class;
String name = "DEPRECATED_INT32_IN_ONEOF";
java.lang.reflect.Field enumValue = oneofCase.getField(name);
assertTrue("Enum value " + name + " should be deprecated.",
isDeprecated(enumValue));
}
private boolean isDeprecated(AnnotatedElement annotated) { private boolean isDeprecated(AnnotatedElement annotated) {
return annotated.isAnnotationPresent(Deprecated.class); return annotated.isAnnotationPresent(Deprecated.class);
} }
......
...@@ -742,6 +742,19 @@ class DescriptorCopyToProtoTest(unittest.TestCase): ...@@ -742,6 +742,19 @@ class DescriptorCopyToProtoTest(unittest.TestCase):
deprecated: true deprecated: true
> >
> >
field {
name: "deprecated_int32_in_oneof"
number: 2
label: LABEL_OPTIONAL
type: TYPE_INT32
options {
deprecated: true
}
oneof_index: 0
}
oneof_decl {
name: "oneof_fields"
}
""" """
self._InternalTestCopyToProto( self._InternalTestCopyToProto(
......
...@@ -437,11 +437,10 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { ...@@ -437,11 +437,10 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) { for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) {
const FieldDescriptor* field = descriptor_->oneof_decl(i)->field(j); const FieldDescriptor* field = descriptor_->oneof_decl(i)->field(j);
printer->Print( printer->Print(
"$field_name$($field_number$),\n", "$deprecation$$field_name$($field_number$),\n",
"field_name", "deprecation", field->options().deprecated() ? "@java.lang.Deprecated " : "",
ToUpper(field->name()), "field_name", ToUpper(field->name()),
"field_number", "field_number", SimpleItoa(field->number()));
SimpleItoa(field->number()));
} }
printer->Print( printer->Print(
"$cap_oneof_name$_NOT_SET(0);\n", "$cap_oneof_name$_NOT_SET(0);\n",
......
...@@ -189,6 +189,9 @@ message NestedTestAllTypes { ...@@ -189,6 +189,9 @@ message NestedTestAllTypes {
message TestDeprecatedFields { message TestDeprecatedFields {
optional int32 deprecated_int32 = 1 [deprecated=true]; optional int32 deprecated_int32 = 1 [deprecated=true];
oneof oneof_fields {
int32 deprecated_int32_in_oneof = 2 [deprecated=true];
}
} }
message TestDeprecatedMessage { message TestDeprecatedMessage {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment