Commit 9afacb44 authored by Jisi Liu's avatar Jisi Liu Committed by GitHub

Merge pull request #2814 from pherl/javadeprecate

Add annotations for deprecated messages in Java
parents fa178802 baceff7c
...@@ -253,18 +253,22 @@ void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) { ...@@ -253,18 +253,22 @@ void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) {
/* immutable = */ true, "OrBuilder"); /* immutable = */ true, "OrBuilder");
if (descriptor_->extension_range_count() > 0) { if (descriptor_->extension_range_count() > 0) {
printer->Print( printer->Print(
"public interface $classname$OrBuilder$idend$ extends\n" "$deprecation$public interface $classname$OrBuilder$idend$ extends\n"
" $extra_interfaces$\n" " $extra_interfaces$\n"
" com.google.protobuf.GeneratedMessage$ver$.\n" " com.google.protobuf.GeneratedMessage$ver$.\n"
" ExtendableMessageOrBuilder<$classname$> {\n", " ExtendableMessageOrBuilder<$classname$> {\n",
"deprecation", descriptor_->options().deprecated() ?
"@java.lang.Deprecated " : "",
"extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_),
"classname", descriptor_->name(), "classname", descriptor_->name(),
"idend", "", "ver", GeneratedCodeVersionSuffix()); "idend", "", "ver", GeneratedCodeVersionSuffix());
} else { } else {
printer->Print( printer->Print(
"public interface $classname$OrBuilder$idend$ extends\n" "$deprecation$public interface $classname$OrBuilder$idend$ extends\n"
" $extra_interfaces$\n" " $extra_interfaces$\n"
" com.google.protobuf.MessageOrBuilder {\n", " com.google.protobuf.MessageOrBuilder {\n",
"deprecation", descriptor_->options().deprecated() ?
"@java.lang.Deprecated " : "",
"extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_),
"classname", descriptor_->name(), "classname", descriptor_->name(),
"idend", ""); "idend", "");
...@@ -304,6 +308,8 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { ...@@ -304,6 +308,8 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
variables["classname"] = descriptor_->name(); variables["classname"] = descriptor_->name();
variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_); variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_);
variables["ver"] = GeneratedCodeVersionSuffix(); variables["ver"] = GeneratedCodeVersionSuffix();
variables["deprecation"] = descriptor_->options().deprecated()
? "@java.lang.Deprecated " : "";
WriteMessageDocComment(printer, descriptor_); WriteMessageDocComment(printer, descriptor_);
MaybePrintGeneratedAnnotation(context_, printer, descriptor_, MaybePrintGeneratedAnnotation(context_, printer, descriptor_,
...@@ -312,8 +318,9 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { ...@@ -312,8 +318,9 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
// The builder_type stores the super type name of the nested Builder class. // The builder_type stores the super type name of the nested Builder class.
string builder_type; string builder_type;
if (descriptor_->extension_range_count() > 0) { if (descriptor_->extension_range_count() > 0) {
printer->Print(variables, printer->Print(
"public $static$final class $classname$ extends\n"); variables,
"$deprecation$public $static$final class $classname$ extends\n");
printer->Annotate("classname", descriptor_); printer->Annotate("classname", descriptor_);
printer->Print( printer->Print(
variables, variables,
...@@ -326,8 +333,9 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { ...@@ -326,8 +333,9 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
name_resolver_->GetImmutableClassName(descriptor_), name_resolver_->GetImmutableClassName(descriptor_),
GeneratedCodeVersionSuffix()); GeneratedCodeVersionSuffix());
} else { } else {
printer->Print(variables, printer->Print(
"public $static$final class $classname$ extends\n"); variables,
"$deprecation$public $static$final class $classname$ extends\n");
printer->Annotate("classname", descriptor_); printer->Annotate("classname", descriptor_);
printer->Print(variables, printer->Print(variables,
" com.google.protobuf.GeneratedMessage$ver$ implements\n" " com.google.protobuf.GeneratedMessage$ver$ implements\n"
......
...@@ -124,19 +124,23 @@ void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) { ...@@ -124,19 +124,23 @@ void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) {
/* immutable = */ true, "OrBuilder"); /* immutable = */ true, "OrBuilder");
if (descriptor_->extension_range_count() > 0) { if (descriptor_->extension_range_count() > 0) {
printer->Print( printer->Print(
"public interface $classname$OrBuilder$idend$ extends \n" "$deprecation$public interface $classname$OrBuilder$idend$ extends \n"
" $extra_interfaces$\n" " $extra_interfaces$\n"
" com.google.protobuf.GeneratedMessageLite.\n" " com.google.protobuf.GeneratedMessageLite.\n"
" ExtendableMessageOrBuilder<\n" " ExtendableMessageOrBuilder<\n"
" $classname$, $classname$.Builder> {\n", " $classname$, $classname$.Builder> {\n",
"deprecation", descriptor_->options().deprecated() ?
"@java.lang.Deprecated " : "",
"extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_),
"classname", descriptor_->name(), "classname", descriptor_->name(),
"idend", ""); "idend", "");
} else { } else {
printer->Print( printer->Print(
"public interface $classname$OrBuilder$idend$ extends\n" "$deprecation$public interface $classname$OrBuilder$idend$ extends\n"
" $extra_interfaces$\n" " $extra_interfaces$\n"
" com.google.protobuf.MessageLiteOrBuilder {\n", " com.google.protobuf.MessageLiteOrBuilder {\n",
"deprecation", descriptor_->options().deprecated() ?
"@java.lang.Deprecated " : "",
"extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_),
"classname", descriptor_->name(), "classname", descriptor_->name(),
"idend", ""); "idend", "");
...@@ -174,6 +178,8 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { ...@@ -174,6 +178,8 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
variables["static"] = is_own_file ? " " : " static "; variables["static"] = is_own_file ? " " : " static ";
variables["classname"] = descriptor_->name(); variables["classname"] = descriptor_->name();
variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_); variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_);
variables["deprecation"] = descriptor_->options().deprecated()
? "@java.lang.Deprecated " : "";
WriteMessageDocComment(printer, descriptor_); WriteMessageDocComment(printer, descriptor_);
MaybePrintGeneratedAnnotation(context_, printer, descriptor_, MaybePrintGeneratedAnnotation(context_, printer, descriptor_,
...@@ -184,7 +190,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { ...@@ -184,7 +190,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
string builder_type; string builder_type;
if (descriptor_->extension_range_count() > 0) { if (descriptor_->extension_range_count() > 0) {
printer->Print(variables, printer->Print(variables,
"public $static$final class $classname$ extends\n" "$deprecation$public $static$final class $classname$ extends\n"
" com.google.protobuf.GeneratedMessageLite.ExtendableMessage<\n" " com.google.protobuf.GeneratedMessageLite.ExtendableMessage<\n"
" $classname$, $classname$.Builder> implements\n" " $classname$, $classname$.Builder> implements\n"
" $extra_interfaces$\n" " $extra_interfaces$\n"
...@@ -194,7 +200,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { ...@@ -194,7 +200,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
name_resolver_->GetImmutableClassName(descriptor_)); name_resolver_->GetImmutableClassName(descriptor_));
} else { } else {
printer->Print(variables, printer->Print(variables,
"public $static$final class $classname$ extends\n" "$deprecation$public $static$final class $classname$ extends\n"
" com.google.protobuf.GeneratedMessageLite<\n" " com.google.protobuf.GeneratedMessageLite<\n"
" $classname$, $classname$.Builder> implements\n" " $classname$, $classname$.Builder> implements\n"
" $extra_interfaces$\n" " $extra_interfaces$\n"
......
...@@ -191,6 +191,10 @@ message TestDeprecatedFields { ...@@ -191,6 +191,10 @@ message TestDeprecatedFields {
optional int32 deprecated_int32 = 1 [deprecated=true]; optional int32 deprecated_int32 = 1 [deprecated=true];
} }
message TestDeprecatedMessage {
option deprecated = true;
}
// Define these after TestAllTypes to make sure the compiler can handle // Define these after TestAllTypes to make sure the compiler can handle
// that. // that.
message ForeignMessage { message ForeignMessage {
......
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