Skip to content

Commit 3cd820f

Browse files
committed
feat: support @relates
1 parent 6f9bd07 commit 3cd820f

File tree

5 files changed

+91
-0
lines changed

5 files changed

+91
-0
lines changed

include/mrdocs/Metadata/Javadoc.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ enum class Kind
127127
throws,
128128
details,
129129
see,
130+
related,
130131
precondition,
131132
postcondition
132133
};
@@ -365,6 +366,25 @@ struct Copied : Reference
365366
}
366367
};
367368

369+
/** A reference to a related symbol.
370+
*/
371+
struct Related : Reference
372+
{
373+
static constexpr Kind static_kind = Kind::related;
374+
375+
Related(String string_ = String()) noexcept
376+
: Reference(std::move(string_), Kind::related)
377+
{
378+
}
379+
380+
bool operator==(Related const&) const noexcept = default;
381+
bool equals(Node const& other) const noexcept override
382+
{
383+
return kind == other.kind &&
384+
*this == static_cast<const Related&>(other);
385+
}
386+
};
387+
368388
//------------------------------------------------
369389
//
370390
// Block nodes
@@ -841,6 +861,8 @@ visit(
841861
return f.template operator()<Precondition>(std::forward<Args>(args)...);
842862
case Kind::postcondition:
843863
return f.template operator()<Postcondition>(std::forward<Args>(args)...);
864+
case Kind::related:
865+
return f.template operator()<Related>(std::forward<Args>(args)...);
844866
default:
845867
return f.template operator()<void>(std::forward<Args>(args)...);
846868
}
@@ -908,6 +930,8 @@ visit(
908930
return visitor.template visit<Precondition>();
909931
case Kind::postcondition:
910932
return visitor.template visit<Postcondition>();
933+
case Kind::related:
934+
return visitor.template visit<Related>();
911935
default:
912936
MRDOCS_UNREACHABLE();
913937
}
@@ -942,6 +966,7 @@ struct Overview
942966
std::vector<See const*> sees;
943967
std::vector<Precondition const*> preconditions;
944968
std::vector<Postcondition const*> postconditions;
969+
std::vector<Related const*> related;
945970
};
946971

947972
MRDOCS_DECL dom::String toString(Style style) noexcept;

share/mrdocs/addons/generator/adoc/partials/symbol.adoc.hbs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,13 @@
219219
{{/each}}
220220

221221
{{/if}}
222+
{{! Related }}
223+
{{#if symbol.doc.related}}
224+
{{#> markup/dynamic-level-h }}Related{{/markup/dynamic-level-h}}
225+
226+
{{#each symbol.doc.related}}
227+
{{{.}}}
228+
229+
{{/each}}
230+
231+
{{/if}}

src/lib/AST/ParseJavadoc.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,38 @@ visitInlineCommandComment(
11201120
}
11211121
return;
11221122
}
1123+
// KRYSTIAN FIXME: these need to be made inline commands in clang
1124+
case CommandTraits::KCI_related:
1125+
case CommandTraits::KCI_relates:
1126+
{
1127+
if(! goodArgCount(1, *C))
1128+
return;
1129+
// The parsed reference often includes characters
1130+
// that are not valid in identifiers, so we need to
1131+
// clean it up.
1132+
// Find the first character that is not a valid C++
1133+
// identifier character, and truncate the string there.
1134+
// This potentially creates two text nodes.
1135+
auto const s = C->getArgText(0).str();
1136+
std::string_view ref = parseQualifiedIdentifier(s);
1137+
bool const hasExtraText = ref.size() != s.size();
1138+
if (!ref.empty())
1139+
{
1140+
// the referenced symbol will be resolved during
1141+
// the finalization step once all symbols are extracted
1142+
emplaceText<doc::Related>(
1143+
C->hasTrailingNewline() && !hasExtraText,
1144+
std::string(ref));
1145+
}
1146+
// Emplace the rest of the string as doc::Text
1147+
if(hasExtraText)
1148+
{
1149+
emplaceText<doc::Text>(
1150+
C->hasTrailingNewline(),
1151+
s.substr(ref.size()));
1152+
}
1153+
return;
1154+
}
11231155

11241156
default:
11251157
break;

src/lib/Gen/hbs/HandlebarsCorpus.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ domCreate(
9999
return corpus.toStringFn(corpus, I);
100100
}
101101

102+
dom::Value
103+
domCreate(
104+
const doc::Related& I,
105+
const HandlebarsCorpus& corpus)
106+
{
107+
return corpus.toStringFn(corpus, I);
108+
}
109+
102110
dom::Value
103111
domCreate(
104112
const doc::Precondition& I,
@@ -258,6 +266,7 @@ getJavadoc(Javadoc const& jd) const
258266
emplaceObjectArray("see", ov.sees);
259267
emplaceObjectArray("preconditions", ov.preconditions);
260268
emplaceObjectArray("postconditions", ov.postconditions);
269+
emplaceObjectArray("related", ov.related);
261270
return dom::Object(std::move(objKeyValues));
262271
}
263272

src/lib/Metadata/Javadoc.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ makeOverview(
263263
{
264264
case doc::Kind::brief:
265265
break;
266+
case doc::Kind::related:
267+
break;
266268
case doc::Kind::returns:
267269
ov.returns = static_cast<
268270
doc::Returns const*>(it->get());
@@ -298,6 +300,19 @@ makeOverview(
298300
}
299301
ov.blocks.push_back(it->get());
300302
}
303+
304+
for(const auto& child : it->get()->children)
305+
{
306+
switch(child->kind)
307+
{
308+
case doc::Kind::related:
309+
ov.related.push_back(static_cast<
310+
doc::Related const*>(child.get()));
311+
break;
312+
default:
313+
break;
314+
}
315+
}
301316
}
302317

303318
return ov;

0 commit comments

Comments
 (0)