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