Commit e53dd993 authored by Adam Cozzette's avatar Adam Cozzette Committed by GitHub

Merge pull request #2529 from wackoisgod/master

Class deprecation support
parents 228d242c 75ac3973
...@@ -122,8 +122,10 @@ void FieldGeneratorBase::GenerateCodecCode(io::Printer* printer) { ...@@ -122,8 +122,10 @@ void FieldGeneratorBase::GenerateCodecCode(io::Printer* printer) {
} }
void FieldGeneratorBase::AddDeprecatedFlag(io::Printer* printer) { void FieldGeneratorBase::AddDeprecatedFlag(io::Printer* printer) {
if (descriptor_->options().deprecated()) if (descriptor_->options().deprecated()) {
{ printer->Print("[global::System.ObsoleteAttribute]\n");
} else if (descriptor_->type() == FieldDescriptor::TYPE_MESSAGE &&
descriptor_->message_type()->options().deprecated()) {
printer->Print("[global::System.ObsoleteAttribute]\n"); printer->Print("[global::System.ObsoleteAttribute]\n");
} }
} }
......
...@@ -98,12 +98,20 @@ const std::vector<const FieldDescriptor*>& MessageGenerator::fields_by_number() ...@@ -98,12 +98,20 @@ const std::vector<const FieldDescriptor*>& MessageGenerator::fields_by_number()
return fields_by_number_; return fields_by_number_;
} }
void MessageGenerator::AddDeprecatedFlag(io::Printer* printer) {
if (descriptor_->options().deprecated()) {
printer->Print("[global::System.ObsoleteAttribute]\n");
}
}
void MessageGenerator::Generate(io::Printer* printer) { void MessageGenerator::Generate(io::Printer* printer) {
map<string, string> vars; map<string, string> vars;
vars["class_name"] = class_name(); vars["class_name"] = class_name();
vars["access_level"] = class_access_level(); vars["access_level"] = class_access_level();
WriteMessageDocComment(printer, descriptor_); WriteMessageDocComment(printer, descriptor_);
AddDeprecatedFlag(printer);
printer->Print( printer->Print(
vars, vars,
"$access_level$ sealed partial class $class_name$ : pb::IMessage<$class_name$> {\n"); "$access_level$ sealed partial class $class_name$ : pb::IMessage<$class_name$> {\n");
...@@ -115,6 +123,7 @@ void MessageGenerator::Generate(io::Printer* printer) { ...@@ -115,6 +123,7 @@ void MessageGenerator::Generate(io::Printer* printer) {
"private static readonly pb::MessageParser<$class_name$> _parser = new pb::MessageParser<$class_name$>(() => new $class_name$());\n"); "private static readonly pb::MessageParser<$class_name$> _parser = new pb::MessageParser<$class_name$>(() => new $class_name$());\n");
WriteGeneratedCodeAttributes(printer); WriteGeneratedCodeAttributes(printer);
printer->Print( printer->Print(
vars, vars,
"public static pb::MessageParser<$class_name$> Parser { get { return _parser; } }\n\n"); "public static pb::MessageParser<$class_name$> Parser { get { return _parser; } }\n\n");
......
...@@ -69,6 +69,8 @@ class MessageGenerator : public SourceGeneratorBase { ...@@ -69,6 +69,8 @@ class MessageGenerator : public SourceGeneratorBase {
bool HasNestedGeneratedTypes(); bool HasNestedGeneratedTypes();
void AddDeprecatedFlag(io::Printer* printer);
std::string class_name(); std::string class_name();
std::string full_class_name(); std::string full_class_name();
......
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