Add annotations for deprecated messages in Java

pull/2814/head
Jisi Liu 8 years ago
parent 3f6f73b796
commit baceff7c9c
  1. 20
      src/google/protobuf/compiler/java/java_message.cc
  2. 14
      src/google/protobuf/compiler/java/java_message_lite.cc
  3. 4
      src/google/protobuf/unittest.proto

@ -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 {

Loading…
Cancel
Save