Skip to content

Commit

Permalink
feat: support @relates
Browse files Browse the repository at this point in the history
  • Loading branch information
sdkrystian committed Jan 8, 2025
1 parent 74d2407 commit 9063208
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 2 deletions.
25 changes: 25 additions & 0 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 @@ -802,6 +822,8 @@ visit(
return f.template operator()<Precondition>(std::forward<Args>(args)...);
case Kind::postcondition:
return f.template operator()<Postcondition>(std::forward<Args>(args)...);
case Kind::related:
return f.template operator()<Related>(std::forward<Args>(args)...);
default:
return f.template operator()<void>(std::forward<Args>(args)...);
}
Expand Down Expand Up @@ -867,6 +889,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 +925,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

0 comments on commit 9063208

Please sign in to comment.