-
Notifications
You must be signed in to change notification settings - Fork 592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleanup Deprecated Metadata #2129
Changes from 5 commits
d7be95f
86785f6
0e938cf
61310cd
893e403
abf24c3
b643b6e
32d4ccd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -748,19 +748,14 @@ Slice::Contained::parseComment(bool stripMarkup) const | |
{ | ||
CommentPtr comment = make_shared<Comment>(); | ||
|
||
comment->_isDeprecated = false; | ||
comment->_isDeprecated = isDeprecated(false); | ||
|
||
// | ||
// First check metadata for a deprecated tag. | ||
// | ||
string deprecateMetadata; | ||
if (findMetaData("deprecate", deprecateMetadata)) | ||
if (auto reason = getDeprecateReason(false)) | ||
{ | ||
comment->_isDeprecated = true; | ||
if (deprecateMetadata.find("deprecate:") == 0 && deprecateMetadata.size() > 10) | ||
{ | ||
comment->_deprecated.push_back(IceUtilInternal::trim(deprecateMetadata.substr(10))); | ||
} | ||
comment->_deprecated.push_back(IceUtilInternal::trim(*reason)); | ||
} | ||
|
||
if (!comment->_isDeprecated && _comment.empty()) | ||
|
@@ -1003,6 +998,31 @@ Slice::Contained::parseFormatMetaData(const list<string>& metaData) | |
return result; | ||
} | ||
|
||
bool | ||
Slice::Contained::isDeprecated(bool checkParent) const | ||
{ | ||
const string deprecate = "deprecate"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would be nice to update findMetaData to take a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I'll do that in a follow-up PR though. |
||
string metadata; | ||
ContainedPtr parent = checkParent ? dynamic_pointer_cast<Contained>(_container) : nullptr; | ||
|
||
return (findMetaData(deprecate, metadata) || (parent && parent->findMetaData(deprecate, metadata))); | ||
} | ||
|
||
optional<string> | ||
Slice::Contained::getDeprecateReason(bool checkParent) const | ||
{ | ||
const string prefix = "deprecate:"; | ||
string metadata; | ||
ContainedPtr parent = checkParent ? dynamic_pointer_cast<Contained>(_container) : nullptr; | ||
|
||
if (findMetaData(prefix, metadata) || (parent && parent->findMetaData(prefix, metadata))) | ||
{ | ||
assert(metadata.find(prefix) == 0); | ||
return metadata.substr(prefix.size()); | ||
} | ||
return nullopt; | ||
} | ||
|
||
Slice::Contained::Contained(const ContainerPtr& container, const string& name) | ||
: SyntaxTreeBase(container->unit()), | ||
_container(container), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,18 +72,19 @@ namespace | |
} | ||
} | ||
|
||
string getDeprecateSymbol(const ContainedPtr& p1, const ContainedPtr& p2) | ||
string getDeprecateSymbol(const ContainedPtr& p1) | ||
{ | ||
string deprecateMetadata, deprecateSymbol; | ||
if (p1->findMetaData("deprecate", deprecateMetadata) || | ||
(p2 != 0 && p2->findMetaData("deprecate", deprecateMetadata))) | ||
string deprecateSymbol; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd use "deprecated" instead of "deprecate". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also fixed! |
||
if (p1->isDeprecated(true)) | ||
{ | ||
string msg = "is deprecated"; | ||
if (deprecateMetadata.find("deprecate:") == 0 && deprecateMetadata.size() > 10) | ||
if (auto reason = p1->getDeprecateReason(false)) | ||
{ | ||
msg = deprecateMetadata.substr(10); | ||
deprecateSymbol = "[[deprecated(\"" + *reason + "\")]] "; | ||
} | ||
else | ||
{ | ||
deprecateSymbol = "[[deprecated]] "; | ||
} | ||
deprecateSymbol = "[[deprecated(\"" + msg + "\")]] "; | ||
} | ||
return deprecateSymbol; | ||
} | ||
|
@@ -1701,7 +1702,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) | |
string futureTAbsolute = createOutgoingAsyncTypeParam(createOutgoingAsyncParams(p, "", _useWstring)); | ||
string lambdaT = createOutgoingAsyncTypeParam(lambdaOutParams); | ||
|
||
const string deprecateSymbol = getDeprecateSymbol(p, interface); | ||
const string deprecateSymbol = getDeprecateSymbol(p); | ||
|
||
CommentPtr comment = p->parseComment(false); | ||
const string contextDoc = "@param " + contextParam + " The Context map to send with the invocation."; | ||
|
@@ -3097,7 +3098,7 @@ Slice::Gen::InterfaceVisitor::visitOperation(const OperationPtr& p) | |
string isConst = ((p->mode() == Operation::Nonmutating) || p->hasMetaData("cpp:const")) ? " const" : ""; | ||
|
||
string opName = amd ? (name + "Async") : fixKwd(name); | ||
string deprecateSymbol = getDeprecateSymbol(p, interface); | ||
string deprecateSymbol = getDeprecateSymbol(p); | ||
|
||
H << sp; | ||
if (comment) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,28 +83,35 @@ namespace | |
return "???"; | ||
} | ||
|
||
string getDeprecateReason(const ContainedPtr& p1, const ContainedPtr& p2, const string& type) | ||
string getDeprecateReason(const ContainedPtr& p1, const string& type) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if we should generate a special doc-comment message for deprecated operation and the like. But we should at least give this helper function a clearer/consistent name, like |
||
{ | ||
string deprecateMetadata, deprecateReason; | ||
if (p1->findMetaData("deprecate", deprecateMetadata) || | ||
(p2 != 0 && p2->findMetaData("deprecate", deprecateMetadata))) | ||
string deprecateReason; | ||
if (p1->isDeprecated(true)) | ||
{ | ||
deprecateReason = "This " + type + " has been deprecated."; | ||
const string prefix = "deprecate:"; | ||
if (deprecateMetadata.find(prefix) == 0 && deprecateMetadata.size() > prefix.size()) | ||
if (auto reason = p1->getDeprecateReason(true)) | ||
{ | ||
deprecateReason = deprecateMetadata.substr(prefix.size()); | ||
deprecateReason = *reason; | ||
} | ||
else | ||
{ | ||
deprecateReason = "This " + type + " has been deprecated."; | ||
} | ||
} | ||
return deprecateReason; | ||
} | ||
|
||
void emitDeprecate(const ContainedPtr& p1, const ContainedPtr& p2, Output& out, const string& type) | ||
void emitObsoleteAttribute(const ContainedPtr& p1, Output& out) | ||
{ | ||
string reason = getDeprecateReason(p1, p2, type); | ||
if (!reason.empty()) | ||
if (p1->isDeprecated(true)) | ||
{ | ||
out << nl << "[global::System.Obsolete(\"" << reason << "\")]"; | ||
if (auto reason = p1->getDeprecateReason(true)) | ||
{ | ||
out << nl << "[global::System.Obsolete(\"" << *reason << "\")]"; | ||
} | ||
else | ||
{ | ||
out << nl << "[global::System.Obsolete]"; | ||
} | ||
} | ||
} | ||
|
||
|
@@ -1678,8 +1685,7 @@ Slice::CsVisitor::writeDocCommentTaskAsyncAMI( | |
void | ||
Slice::CsVisitor::writeDocCommentAMD(const OperationPtr& p, const string& extraParam) | ||
{ | ||
InterfaceDefPtr interface = p->interface(); | ||
string deprecateReason = getDeprecateReason(p, interface, "operation"); | ||
string deprecateReason = getDeprecateReason(p, "operation"); | ||
|
||
StringList summaryLines; | ||
StringList remarksLines; | ||
|
@@ -2326,8 +2332,8 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p) | |
ExceptionPtr base = p->base(); | ||
|
||
_out << sp; | ||
writeDocComment(p, getDeprecateReason(p, 0, "type")); | ||
emitDeprecate(p, 0, _out, "type"); | ||
writeDocComment(p, getDeprecateReason(p, "type")); | ||
emitObsoleteAttribute(p, _out); | ||
emitAttributes(p); | ||
emitComVisibleAttribute(); | ||
// | ||
|
@@ -2575,7 +2581,7 @@ Slice::Gen::TypesVisitor::visitStructStart(const StructPtr& p) | |
string ns = getNamespace(p); | ||
_out << sp; | ||
|
||
emitDeprecate(p, 0, _out, "type"); | ||
emitObsoleteAttribute(p, _out); | ||
|
||
emitAttributes(p); | ||
emitPartialTypeAttributes(); | ||
|
@@ -2830,8 +2836,8 @@ Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) | |
const bool explicitValue = p->explicitValue(); | ||
|
||
_out << sp; | ||
emitDeprecate(p, 0, _out, "type"); | ||
writeDocComment(p, getDeprecateReason(p, 0, "type")); | ||
emitObsoleteAttribute(p, _out); | ||
writeDocComment(p, getDeprecateReason(p, "type")); | ||
emitAttributes(p); | ||
emitGeneratedCodeAttribute(); | ||
_out << nl << "public enum " << name; | ||
|
@@ -2951,7 +2957,7 @@ Slice::Gen::TypesVisitor::visitDataMember(const DataMemberPtr& p) | |
|
||
_out << sp; | ||
|
||
emitDeprecate(p, cont, _out, "member"); | ||
emitObsoleteAttribute(p, _out); | ||
|
||
string type = typeToString(p->type(), ns, isOptional); | ||
string dataMemberName = fixId(p->name(), baseTypes, isClass); | ||
|
@@ -3291,7 +3297,7 @@ Slice::Gen::ProxyVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) | |
InterfaceList bases = p->bases(); | ||
|
||
_out << sp; | ||
writeDocComment(p, getDeprecateReason(p, 0, "interface")); | ||
writeDocComment(p, getDeprecateReason(p, "interface")); | ||
emitGeneratedCodeAttribute(); | ||
_out << nl << "public interface " << name << "Prx : "; | ||
|
||
|
@@ -3334,7 +3340,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) | |
vector<string> inParams = getInParams(p, ns); | ||
ParamDeclList inParamDecls = p->inParameters(); | ||
string retS = typeToString(p->returnType(), ns, p->returnIsOptional()); | ||
string deprecateReason = getDeprecateReason(p, interface, "operation"); | ||
string deprecateReason = getDeprecateReason(p, "operation"); | ||
|
||
{ | ||
// | ||
|
@@ -3346,10 +3352,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) | |
p, | ||
deprecateReason, | ||
"<param name=\"" + context + "\">The Context map to send with the invocation.</param>"); | ||
if (!deprecateReason.empty()) | ||
{ | ||
_out << nl << "[global::System.Obsolete(\"" << deprecateReason << "\")]"; | ||
} | ||
emitObsoleteAttribute(p, _out); | ||
_out << nl << retS << " " << name << spar << getParams(p, ns) | ||
<< (getUnqualified("Ice.OptionalContext", ns) + " " + context + " = new " + | ||
getUnqualified("Ice.OptionalContext", ns) + "()") | ||
|
@@ -3371,10 +3374,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) | |
"<param name=\"" + context + "\">Context map to send with the invocation.</param>", | ||
"<param name=\"" + progress + "\">Sent progress provider.</param>", | ||
"<param name=\"" + cancel + "\">A cancellation token that receives the cancellation requests.</param>"); | ||
if (!deprecateReason.empty()) | ||
{ | ||
_out << nl << "[global::System.Obsolete(\"" << deprecateReason << "\")]"; | ||
} | ||
emitObsoleteAttribute(p, _out); | ||
_out << nl << taskResultType(p, ns); | ||
_out << " " << p->name() << "Async" << spar << inParams | ||
<< (getUnqualified("Ice.OptionalContext", ns) + " " + context + " = new " + | ||
|
@@ -3470,7 +3470,7 @@ Slice::Gen::OpsVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) | |
string opIntfName = "Operations"; | ||
|
||
_out << sp; | ||
writeDocComment(p, getDeprecateReason(p, 0, "interface")); | ||
writeDocComment(p, getDeprecateReason(p, "interface")); | ||
emitGeneratedCodeAttribute(); | ||
_out << nl << "public interface " << name << opIntfName << '_'; | ||
if (bases.size() > 0) | ||
|
@@ -3513,11 +3513,11 @@ Slice::Gen::OpsVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) | |
{ | ||
writeDocComment( | ||
op, | ||
getDeprecateReason(op, p, "operation"), | ||
getDeprecateReason(op, "operation"), | ||
"<param name=\"" + args.back() + "\">The Current object for the invocation.</param>"); | ||
} | ||
emitAttributes(op); | ||
emitDeprecate(op, op, _out, "operation"); | ||
emitObsoleteAttribute(op, _out); | ||
emitGeneratedCodeAttribute(); | ||
_out << nl << retS << " " << opName << spar << params << epar << ";"; | ||
} | ||
|
@@ -3587,7 +3587,7 @@ Slice::Gen::HelperVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) | |
vector<string> args = getArgs(op); | ||
vector<string> argsAMI = getInArgs(op); | ||
|
||
string deprecateReason = getDeprecateReason(op, p, "operation"); | ||
string deprecateReason = getDeprecateReason(op, "operation"); | ||
|
||
ParamDeclList inParams = op->inParameters(); | ||
ParamDeclList outParams = op->outParameters(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,13 +86,6 @@ namespace | |
return name; | ||
} | ||
|
||
bool isDeprecated(const ContainedPtr& p1, const ContainedPtr& p2) | ||
{ | ||
string deprecateMetadata; | ||
return p1->findMetaData("deprecate", deprecateMetadata) || | ||
(p2 != 0 && p2->findMetaData("deprecate", deprecateMetadata)); | ||
} | ||
|
||
bool isValue(const TypePtr& type) | ||
{ | ||
BuiltinPtr b = dynamic_pointer_cast<Builtin>(type); | ||
|
@@ -1625,15 +1618,10 @@ Slice::JavaVisitor::writeDispatch(Output& out, const InterfaceDefPtr& p) | |
|
||
out << sp; | ||
writeHiddenDocComment(out); | ||
for (OperationList::iterator r = allOps.begin(); r != allOps.end(); ++r) | ||
for (const OperationPtr& op : allOps) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add a TODO: temporary. |
||
{ | ||
// | ||
// Suppress deprecation warnings if this method dispatches to a deprecated operation. | ||
// | ||
OperationPtr op = *r; | ||
InterfaceDefPtr interface = op->interface(); | ||
assert(interface); | ||
if (isDeprecated(op, interface)) | ||
if (op->isDeprecated(true)) | ||
{ | ||
out << nl << "@SuppressWarnings(\"deprecation\")"; | ||
break; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though your functions are named "isDeprecated", you didn't add "deprecated" as an alias for the "deprecate" metadata?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but only because
isDeprecate
isn't a sensible thing to say IMO. Nothing to do with our eventual renaming.I plan to add the alias in my next PR, alongside removing the dispatch side.