Skip to content

Commit

Permalink
feat: add @deprecation and @since docs (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
edusperoni committed Jun 25, 2024
1 parent 6ec9a8f commit daceac1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
13 changes: 13 additions & 0 deletions metadata-generator/src/Meta/MetaEntities.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ struct Version {
bool operator >=(const Version& other) const {
return !(*this < other);
}
std::string toString() const {
std::string result;
if (Major >= 0) {
result.append(std::to_string(Major));
if (Minor >= 0) {
result.append("." + std::to_string(Minor));
if (SubMinor >= 0) {
result.append("." + std::to_string(SubMinor));
}
}
}
return result;
}
};

enum MetaFlags : uint16_t {
Expand Down
18 changes: 15 additions & 3 deletions metadata-generator/src/TypeScript/DocSetManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,39 @@ using namespace std;

std::string TSComment::toString(std::string linePrefix)
{
if (description.length() == 0 && params.size() == 0) {
if (description.length() == 0 && params.size() == 0 && deprecatedIn.isUnknown() && introducedIn.isUnknown()) {
return std::string();
}

std::stringstream result;
result << linePrefix << "/**" << std::endl;
std::string processedDesc = description;
findAndReplaceIn(processedDesc, "\n", "");
result << linePrefix << " * " << processedDesc << std::endl;
if (processedDesc.length() > 0) {
result << linePrefix << " * " << processedDesc << std::endl;
}
for (std::pair<std::string, std::string>& param : params) {
// @param paramName - paramDesc
result << linePrefix << " * "
<< "@param " + param.first + " - " + param.second << std::endl;
}
if (!introducedIn.isUnknown()) {
result << linePrefix << " * " << "@since " << introducedIn.toString() << std::endl;
}
if (!deprecatedIn.isUnknown()) {
result << linePrefix << " * " << "@deprecated " << deprecatedIn.toString() << std::endl;
}
result << linePrefix << " */" << std::endl;
return result.str();
}

TSComment DocSetManager::getCommentFor(Meta::Meta* meta, Meta::Meta* parent)
{
return (parent == nullptr) ? getCommentFor(meta->name, meta->type) : getCommentFor(meta->name, meta->type, parent->name, parent->type);
auto comment = (parent == nullptr) ? getCommentFor(meta->name, meta->type) : getCommentFor(meta->name, meta->type, parent->name, parent->type);
comment.deprecatedIn = meta->deprecatedIn;
comment.introducedIn = meta->introducedIn;
comment.obsoletedIn = meta->obsoletedIn;
return comment;
}

TSComment DocSetManager::getCommentFor(std::string name, Meta::MetaType type, std::string parentName, Meta::MetaType parentType)
Expand Down
6 changes: 5 additions & 1 deletion metadata-generator/src/TypeScript/DocSetManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ struct TSComment {
* \brief A brief description of the symbol.
*/
std::string description;

Meta::Version introducedIn = UNKNOWN_VERSION;
Meta::Version obsoletedIn = UNKNOWN_VERSION;
Meta::Version deprecatedIn = UNKNOWN_VERSION;

/*
* \brief An optional list of parameters. Useful in method and function comments.
Expand Down Expand Up @@ -74,4 +78,4 @@ class DocSetManager {
};
}

#endif //METADATAGENERATOR_DOCSETPARSER_H
#endif //METADATAGENERATOR_DOCSETPARSER_H

0 comments on commit daceac1

Please sign in to comment.