Skip to content

Commit a6ac939

Browse files
committed
more Javadoc metadata
1 parent ba89710 commit a6ac939

File tree

10 files changed

+1168
-829
lines changed

10 files changed

+1168
-829
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ temp/
44
.vs/
55
.vscode/
66
CMakeSettings.json
7+
test/

include/mrdox/meta/Javadoc.hpp

Lines changed: 207 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include <mrdox/meta/List.hpp>
1616
#include <llvm/ADT/SmallString.h>
17+
#include <memory>
1718
#include <string>
1819
#include <utility>
1920

@@ -76,14 +77,41 @@ struct Javadoc
7677
text,
7778
code,
7879
styledText,
79-
paragraph
80+
paragraph,
81+
admonition,
82+
returns,
83+
param,
84+
tparam
85+
};
86+
87+
/** A text style.
88+
*/
89+
enum class Style
90+
{
91+
none,
92+
mono,
93+
bold,
94+
italic
95+
};
96+
97+
/** An admonishment style.
98+
*/
99+
enum class Admonish
100+
{
101+
note,
102+
tip,
103+
important,
104+
caution,
105+
warning
80106
};
81107

82108
/** This is a variant-like list element.
83109
*/
84110
struct Node
85111
{
86-
Kind const kind;
112+
Kind kind;
113+
114+
auto operator<=>(Node const&) const noexcept = default;
87115

88116
explicit Node(Kind kind_) noexcept
89117
: kind(kind_)
@@ -97,65 +125,166 @@ struct Javadoc
97125
{
98126
String text;
99127

128+
auto operator<=>(Text const&) const noexcept = default;
129+
100130
explicit
131+
Text(
132+
String text_)
133+
: Node(Kind::text)
134+
, text(std::move(text_))
135+
{
136+
}
137+
138+
protected:
101139
Text(
102140
String text_,
103-
Kind kind_ = Kind::text)
141+
Kind kind_)
104142
: Node(kind_)
105143
, text(std::move(text_))
106144
{
107145
}
108146
};
109147

110-
/** A string of plain text representing source code.
148+
/** A piece of style text.
149+
*/
150+
struct StyledText : Text
151+
{
152+
Style style;
153+
154+
auto operator<=>(StyledText const&) const noexcept = default;
155+
156+
StyledText(
157+
String text,
158+
Style style_)
159+
: Text(std::move(text), Kind::styledText)
160+
, style(style_)
161+
{
162+
}
163+
};
164+
165+
/** A piece of block content
166+
167+
The top level is a list of blocks.
111168
*/
112-
struct Code : Text
169+
struct Block : Node
113170
{
114-
// VFALCO this can have a language (e.g. C++),
115-
// and we can emit attributes in the generator.
171+
auto operator<=>(Block const&) const noexcept = default;
116172

173+
protected:
117174
explicit
118-
Code(
119-
String text_)
120-
: Text(std::move(text_), Kind::code)
175+
Block(Kind kind_) noexcept
176+
: Node(kind_)
121177
{
122178
}
123179
};
124180

125-
/** A text style.
181+
/** A sequence of text nodes.
126182
*/
127-
enum class Style
183+
struct Paragraph : Block
128184
{
129-
mono,
130-
bold,
131-
italic
185+
List<Text> list;
186+
187+
bool empty() const noexcept
188+
{
189+
return list.empty();
190+
}
191+
192+
auto operator<=>(Paragraph const&) const noexcept = default;
193+
194+
Paragraph()
195+
: Block(Kind::paragraph)
196+
{
197+
}
198+
199+
protected:
200+
explicit
201+
Paragraph(Kind kind) noexcept
202+
: Block(kind)
203+
{
204+
}
132205
};
133206

134-
/** A piece of style text.
207+
/** Documentation for an admonition
135208
*/
136-
struct StyledText : Text
209+
struct Admonition : Paragraph
137210
{
138-
Style style;
211+
Admonish style;
139212

140-
StyledText(
141-
String text,
142-
Style style_)
143-
: Text(std::move(text), Kind::styledText)
213+
auto operator<=>(Admonition const&) const noexcept = default;
214+
215+
explicit
216+
Admonition(Admonish style_)
217+
: Paragraph(Kind::admonition)
144218
, style(style_)
145219
{
146220
}
147221
};
148222

149-
/** A sequence of text nodes.
223+
/** Documentation for a function return type
150224
*/
151-
struct Paragraph : Node
225+
struct Returns : Paragraph
152226
{
153-
Paragraph()
154-
: Node(Kind::paragraph)
227+
auto operator<=>(Returns const&) const noexcept = default;
228+
229+
Returns()
230+
: Paragraph(Kind::returns)
231+
{
232+
}
233+
};
234+
235+
/** Documentation for a function parameter
236+
*/
237+
struct Param : Block
238+
{
239+
String name;
240+
Paragraph details;
241+
242+
auto operator<=>(Param const&) const noexcept = default;
243+
244+
Param(
245+
String name_,
246+
Paragraph details_)
247+
: Block(Kind::param)
248+
, name(std::move(name_))
249+
, details(std::move(details_))
250+
{
251+
}
252+
};
253+
254+
/** Documentation for a template parameter
255+
*/
256+
struct TParam : Block
257+
{
258+
String name;
259+
Paragraph details;
260+
261+
auto operator<=>(TParam const&) const noexcept = default;
262+
263+
TParam(
264+
String name_,
265+
Paragraph details_)
266+
: Block(Kind::param)
267+
, name(std::move(name_))
268+
, details(std::move(details_))
155269
{
156270
}
271+
};
272+
273+
/** Preformatted source code.
274+
*/
275+
struct Code : Block
276+
{
277+
// VFALCO we can add a language (e.g. C++),
278+
// then emit attributes in the generator.
157279

158280
List<Text> list;
281+
282+
auto operator<=>(Code const&) const noexcept = default;
283+
284+
Code()
285+
: Block(Kind::code)
286+
{
287+
}
159288
};
160289

161290
// VFALCO LEGACY
@@ -164,50 +293,82 @@ struct Javadoc
164293

165294
//---
166295

167-
~Javadoc()
296+
Paragraph const&
297+
getBrief() const noexcept
168298
{
169-
if(brief_)
170-
delete brief_;
299+
return *brief_;
171300
}
172301

173-
Javadoc() = default;
302+
List<Block> const&
303+
getBlocks() const noexcept
304+
{
305+
return blocks_;
306+
}
174307

175-
Paragraph const*
176-
getBrief() const noexcept
308+
Returns const&
309+
getReturns() const noexcept
177310
{
178-
return brief_;
311+
return returns_;
179312
}
180313

181-
List<Node> const&
182-
getNodes() const noexcept
314+
List<Param> const&
315+
getParams() const noexcept
183316
{
184-
return list_;
317+
return params_;
185318
}
186319

320+
List<TParam> const&
321+
getTParams() const noexcept
322+
{
323+
return tparams_;
324+
}
325+
326+
//---
327+
328+
Javadoc() = default;
329+
330+
/** Constructor
331+
*/
332+
Javadoc(
333+
Paragraph brief,
334+
List<Block> blocks,
335+
List<Param> params,
336+
List<TParam> tparams,
337+
Returns returns);
338+
339+
bool operator<(Javadoc const&) const noexcept;
340+
bool operator==(Javadoc const&) const noexcept;
341+
187342
/** Append a node to the documentation comment.,
188343
*/
189344
template<class Child>
190345
void
191-
append(Child&& node)
346+
emplace_back(Child&& node)
192347
{
193348
static_assert(std::is_base_of_v<Node, Child>);
194349

195-
list_.emplace_back<Child>(std::forward<Child>(node));
350+
blocks_.emplace_back<Child>(std::forward<Child>(node));
196351
}
197352

198-
/** Append a brief to the documentation comment.,
199-
*/
200353
void
201-
append_brief(Paragraph&& paragraph)
354+
emplace_back(Param param)
202355
{
203-
assert(brief_ == nullptr);
204-
brief_ = new Paragraph(std::move(paragraph));
356+
params_.emplace_back(std::move(param));
205357
}
206358

207-
private:
208-
List<Node> list_;
359+
void
360+
emplace_back(TParam tparam)
361+
{
362+
tparams_.emplace_back(std::move(tparam));
363+
}
209364

210-
Paragraph const* brief_ = nullptr;
365+
private:
366+
std::shared_ptr<
367+
Paragraph const> brief_;
368+
List<Block> blocks_;
369+
List<Param> params_;
370+
List<TParam> tparams_;
371+
Returns returns_;
211372
};
212373

213374
} // mrdox

0 commit comments

Comments
 (0)