Skip to content
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

feat: support @relates #698

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 23 additions & 54 deletions include/mrdocs/Metadata/Javadoc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ enum class Kind
throws,
details,
see,
related,
precondition,
postcondition
};
Expand Down Expand Up @@ -358,6 +359,25 @@ struct Copied : Reference
}
};

/** A reference to a related symbol.
*/
struct Related : Reference
{
static constexpr Kind static_kind = Kind::related;

Related(String string_ = String()) noexcept
: Reference(std::move(string_), Kind::related)
{
}

bool operator==(Related const&) const noexcept = default;
bool equals(Node const& other) const noexcept override
{
return kind == other.kind &&
*this == static_cast<const Related&>(other);
}
};

//------------------------------------------------
//
// Block nodes
Expand Down Expand Up @@ -753,60 +773,6 @@ struct Postcondition : Paragraph

//------------------------------------------------

/** A visitor for node types.
*/
template<class F, class... Args>
constexpr
auto
visit(
Kind kind,
F&& f, Args&&... args)
{
switch(kind)
{
case Kind::admonition:
return f.template operator()<Admonition>(std::forward<Args>(args)...);
case Kind::brief:
return f.template operator()<Brief>(std::forward<Args>(args)...);
case Kind::code:
return f.template operator()<Code>(std::forward<Args>(args)...);
case Kind::heading:
return f.template operator()<Heading>(std::forward<Args>(args)...);
case Kind::link:
return f.template operator()<Link>(std::forward<Args>(args)...);
case Kind::reference:
return f.template operator()<Reference>(std::forward<Args>(args)...);
case Kind::copied:
return f.template operator()<Copied>(std::forward<Args>(args)...);
case Kind::list_item:
return f.template operator()<ListItem>(std::forward<Args>(args)...);
case Kind::paragraph:
return f.template operator()<Paragraph>(std::forward<Args>(args)...);
case Kind::param:
return f.template operator()<Param>(std::forward<Args>(args)...);
case Kind::returns:
return f.template operator()<Returns>(std::forward<Args>(args)...);
case Kind::styled:
return f.template operator()<Styled>(std::forward<Args>(args)...);
case Kind::text:
return f.template operator()<Text>(std::forward<Args>(args)...);
case Kind::tparam:
return f.template operator()<TParam>(std::forward<Args>(args)...);
case Kind::throws:
return f.template operator()<Throws>(std::forward<Args>(args)...);
case Kind::details:
return f.template operator()<Details>(std::forward<Args>(args)...);
case Kind::see:
return f.template operator()<See>(std::forward<Args>(args)...);
case Kind::precondition:
return f.template operator()<Precondition>(std::forward<Args>(args)...);
case Kind::postcondition:
return f.template operator()<Postcondition>(std::forward<Args>(args)...);
default:
return f.template operator()<void>(std::forward<Args>(args)...);
}
}

/** Visit a node.

@param node The node to visit.
Expand Down Expand Up @@ -867,6 +833,8 @@ visit(
return visitor.template visit<Precondition>();
case Kind::postcondition:
return visitor.template visit<Postcondition>();
case Kind::related:
return visitor.template visit<Related>();
default:
MRDOCS_UNREACHABLE();
}
Expand Down Expand Up @@ -901,6 +869,7 @@ struct Overview
std::vector<See const*> sees;
std::vector<Precondition const*> preconditions;
std::vector<Postcondition const*> postconditions;
std::vector<Related const*> related;
};

MRDOCS_DECL dom::String toString(Style style) noexcept;
Expand Down
10 changes: 10 additions & 0 deletions share/mrdocs/addons/generator/adoc/partials/symbol.adoc.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,13 @@
{{/each}}

{{/if}}
{{! Related }}
{{#if symbol.doc.related}}
{{#> markup/dynamic-level-h }}Related{{/markup/dynamic-level-h}}

{{#each symbol.doc.related}}
{{{.}}}

{{/each}}

{{/if}}
35 changes: 33 additions & 2 deletions src/lib/AST/ParseJavadoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,38 @@ visitInlineCommandComment(
}
return;
}
// KRYSTIAN FIXME: these need to be made inline commands in clang
case CommandTraits::KCI_related:
case CommandTraits::KCI_relates:
{
if(! goodArgCount(1, *C))
return;
// The parsed reference often includes characters
// that are not valid in identifiers, so we need to
// clean it up.
// Find the first character that is not a valid C++
// identifier character, and truncate the string there.
// This potentially creates two text nodes.
auto const s = C->getArgText(0).str();
std::string_view ref = parseQualifiedIdentifier(s);
bool const hasExtraText = ref.size() != s.size();
if (!ref.empty())
{
// the referenced symbol will be resolved during
// the finalization step once all symbols are extracted
emplaceText<doc::Related>(
C->hasTrailingNewline() && !hasExtraText,
std::string(ref));
}
// Emplace the rest of the string as doc::Text
if(hasExtraText)
{
emplaceText<doc::Text>(
C->hasTrailingNewline(),
s.substr(ref.size()));
}
return;
}

default:
break;
Expand Down Expand Up @@ -1546,8 +1578,7 @@ JavadocVisitor::
visitVerbatimLineComment(
VerbatimLineComment const* C)
{
// VFALCO This doesn't seem to be used
// in any of my codebases, follow up
emplaceText<doc::Text>(true, C->getText().str());
}

void
Expand Down
9 changes: 9 additions & 0 deletions src/lib/Gen/hbs/HandlebarsCorpus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ domCreate(
return corpus.toStringFn(corpus, I);
}

dom::Value
domCreate(
const doc::Related& I,
const HandlebarsCorpus& corpus)
{
return corpus.toStringFn(corpus, I);
}

dom::Value
domCreate(
const doc::Precondition& I,
Expand Down Expand Up @@ -256,6 +264,7 @@ getJavadoc(Javadoc const& jd) const
emplaceObjectArray("see", ov.sees);
emplaceObjectArray("preconditions", ov.preconditions);
emplaceObjectArray("postconditions", ov.postconditions);
emplaceObjectArray("related", ov.related);
return dom::Object(std::move(objKeyValues));
}

Expand Down
15 changes: 15 additions & 0 deletions src/lib/Metadata/Javadoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ makeOverview(
{
case doc::Kind::brief:
break;
case doc::Kind::related:
break;
case doc::Kind::returns:
ov.returns = static_cast<
doc::Returns const*>(it->get());
Expand Down Expand Up @@ -292,6 +294,19 @@ makeOverview(
break;
ov.blocks.push_back(it->get());
}

for(const auto& child : it->get()->children)
{
switch(child->kind)
{
case doc::Kind::related:
ov.related.push_back(static_cast<
doc::Related const*>(child.get()));
break;
default:
break;
}
}
}

return ov;
Expand Down
Loading