aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Thomas Van Lenten <thomasvl@google.com>2016-12-08 10:14:11 -0500
committerGravatar Thomas Van Lenten <thomasvl@google.com>2016-12-08 12:12:50 -0500
commitdad775b79895df5167cfbc2c78549b8417af1c01 (patch)
tree6a880f4c75e6ed88ebfa18c8122c81fe4ec757be /src
parentc836ad4dc7db4adf4b42a30474037f712d4f6875 (diff)
Improve ObjC deprecated annotation support.
- Check the parent file options for deprecation when deciding to tag Messages and Enums as deprecated. - Within the generated source push/pop the warning for implementing deprecated things around a deprecated class implementation. - Annotate the methods generated for extension fields as deprecated. - Add a testing .proto file that covers deprecated fields, messages, enums, enum values and compile it into the unittests to confirm things compile cleanly. - Add a testing .proto file that uses the file level option to make everything deprecated and compile it into the unittests to confirm things compile cleanly.
Diffstat (limited to 'src')
-rw-r--r--src/google/protobuf/compiler/objectivec/objectivec_enum.cc2
-rw-r--r--src/google/protobuf/compiler/objectivec/objectivec_extension.cc5
-rw-r--r--src/google/protobuf/compiler/objectivec/objectivec_helpers.h14
-rw-r--r--src/google/protobuf/compiler/objectivec/objectivec_message.cc21
-rw-r--r--src/google/protobuf/compiler/objectivec/objectivec_message.h1
5 files changed, 37 insertions, 6 deletions
diff --git a/src/google/protobuf/compiler/objectivec/objectivec_enum.cc b/src/google/protobuf/compiler/objectivec/objectivec_enum.cc
index 34e17823..02d60b3e 100644
--- a/src/google/protobuf/compiler/objectivec/objectivec_enum.cc
+++ b/src/google/protobuf/compiler/objectivec/objectivec_enum.cc
@@ -74,7 +74,7 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) {
printer->Print("$comments$typedef$deprecated_attribute$ GPB_ENUM($name$) {\n",
"comments", enum_comments,
- "deprecated_attribute", GetOptionalDeprecatedAttribute(descriptor_),
+ "deprecated_attribute", GetOptionalDeprecatedAttribute(descriptor_, descriptor_->file()),
"name", name_);
printer->Indent();
diff --git a/src/google/protobuf/compiler/objectivec/objectivec_extension.cc b/src/google/protobuf/compiler/objectivec/objectivec_extension.cc
index d0de1eca..7073173c 100644
--- a/src/google/protobuf/compiler/objectivec/objectivec_extension.cc
+++ b/src/google/protobuf/compiler/objectivec/objectivec_extension.cc
@@ -67,9 +67,12 @@ void ExtensionGenerator::GenerateMembersHeader(io::Printer* printer) {
} else {
vars["comments"] = "";
}
+ // Unlike normal message fields, check if the file for the extension was
+ // deprecated.
+ vars["deprecated_attribute"] = GetOptionalDeprecatedAttribute(descriptor_, descriptor_->file());
printer->Print(vars,
"$comments$"
- "+ (GPBExtensionDescriptor *)$method_name$;\n");
+ "+ (GPBExtensionDescriptor *)$method_name$$deprecated_attribute$;\n");
}
void ExtensionGenerator::GenerateStaticVariablesInitialization(
diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h
index 316069e1..a2179446 100644
--- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h
+++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h
@@ -150,8 +150,18 @@ enum FlagType {
};
template<class TDescriptor>
-string GetOptionalDeprecatedAttribute(const TDescriptor* descriptor, bool preSpace = true, bool postNewline = false) {
- if (descriptor->options().deprecated()) {
+string GetOptionalDeprecatedAttribute(
+ const TDescriptor* descriptor,
+ const FileDescriptor* file = NULL,
+ bool preSpace = true, bool postNewline = false) {
+ bool isDeprecated = descriptor->options().deprecated();
+ // The file is only passed when checking Messages & Enums, so those types
+ // get tagged. At the moment, it doesn't seem to make sense to tag every
+ // field or enum value with when the file is deprecated.
+ if (!isDeprecated && file) {
+ isDeprecated = file->options().deprecated();
+ }
+ if (isDeprecated) {
string result = "DEPRECATED_ATTRIBUTE";
if (preSpace) {
result.insert(0, " ");
diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message.cc b/src/google/protobuf/compiler/objectivec/objectivec_message.cc
index 4c6e1b55..e0bd3dac 100644
--- a/src/google/protobuf/compiler/objectivec/objectivec_message.cc
+++ b/src/google/protobuf/compiler/objectivec/objectivec_message.cc
@@ -180,7 +180,10 @@ MessageGenerator::MessageGenerator(const string& root_classname,
: root_classname_(root_classname),
descriptor_(descriptor),
field_generators_(descriptor, options),
- class_name_(ClassName(descriptor_)) {
+ class_name_(ClassName(descriptor_)),
+ deprecated_attribute_(
+ GetOptionalDeprecatedAttribute(descriptor, descriptor->file(), false, true)) {
+
for (int i = 0; i < descriptor_->extension_count(); i++) {
extension_generators_.push_back(
new ExtensionGenerator(class_name_, descriptor_->extension(i)));
@@ -339,7 +342,7 @@ void MessageGenerator::GenerateMessageHeader(io::Printer* printer) {
printer->Print(
"$comments$$deprecated_attribute$@interface $classname$ : GPBMessage\n\n",
"classname", class_name_,
- "deprecated_attribute", GetOptionalDeprecatedAttribute(descriptor_, false, true),
+ "deprecated_attribute", deprecated_attribute_,
"comments", message_comments);
vector<char> seen_oneofs(descriptor_->oneof_decl_count(), 0);
@@ -396,6 +399,14 @@ void MessageGenerator::GenerateSource(io::Printer* printer) {
"\n",
"classname", class_name_);
+ if (!deprecated_attribute_.empty()) {
+ // No warnings when compiling the impl of this deprecated class.
+ printer->Print(
+ "#pragma clang diagnostic push\n"
+ "#pragma clang diagnostic ignored \"-Wdeprecated-implementations\"\n"
+ "\n");
+ }
+
printer->Print("@implementation $classname$\n\n",
"classname", class_name_);
@@ -601,6 +612,12 @@ void MessageGenerator::GenerateSource(io::Printer* printer) {
"}\n\n"
"@end\n\n");
+ if (!deprecated_attribute_.empty()) {
+ printer->Print(
+ "#pragma clang diagnostic pop\n"
+ "\n");
+ }
+
for (int i = 0; i < descriptor_->field_count(); i++) {
field_generators_.get(descriptor_->field(i))
.GenerateCFunctionImplementations(printer);
diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message.h b/src/google/protobuf/compiler/objectivec/objectivec_message.h
index 910535ac..0fb78bc0 100644
--- a/src/google/protobuf/compiler/objectivec/objectivec_message.h
+++ b/src/google/protobuf/compiler/objectivec/objectivec_message.h
@@ -85,6 +85,7 @@ class MessageGenerator {
const Descriptor* descriptor_;
FieldGeneratorMap field_generators_;
const string class_name_;
+ const string deprecated_attribute_;
vector<ExtensionGenerator*> extension_generators_;
vector<EnumGenerator*> enum_generators_;
vector<MessageGenerator*> nested_message_generators_;