Skip to content

Commit 35762dd

Browse files
committed
[clang-doc] add throws comments to comment template
Serialize throw Doxygen comments for exceptions. Accepts both \throw and \throws.
1 parent 4df8f72 commit 35762dd

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

clang-tools-extra/clang-doc/JSONGenerator.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ static Object serializeComment(const CommentInfo &I, Object &Description) {
140140
insertComment(Description, TextCommentsArray, "BriefComments");
141141
else if (I.Name == "return")
142142
insertComment(Description, TextCommentsArray, "ReturnComments");
143+
else if (I.Name == "throws" || I.Name == "throw") {
144+
json::Value ThrowsVal = Object();
145+
auto &ThrowsObj = *ThrowsVal.getAsObject();
146+
ThrowsObj["Exception"] = I.Args.front();
147+
ThrowsObj["Children"] = TextCommentsArray;
148+
insertComment(Description, ThrowsVal, "ThrowsComments");
149+
}
143150
return Obj;
144151
}
145152

clang-tools-extra/clang-doc/assets/comment-template.mustache

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@
5454
</div>
5555
{{/CodeComments}}
5656
{{/HasCodeComments}}
57+
{{#HasThrowsComments}}
58+
<h3>Throws</h3>
59+
{{#ThrowsComments}}
60+
<div>
61+
<b>{{ThrowName}}</b> {{#Children}}{{>Comments}}{{/Children}}
62+
</div>
63+
{{/ThrowsComments}}
64+
{{/HasThrowsComments}}
5765
{{#BlockCommandComment}}
5866
<div class="block-command-comment__command">
5967
<div class="block-command-command">

clang-tools-extra/test/clang-doc/basic-project.mustache.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ HTML-CALC: </div>
384384
HTML-CALC: <h3>Returns</h3>
385385
HTML-CALC: <p> double The result of a / b.</p>
386386
HTML-CALC: <p></p>
387+
HTML-CALC: <h3>Throws</h3>
388+
HTML-CALC: <div>
389+
HTML-CALC: <b></b> <div>
390+
HTML-CALC: <p>if b is zero.</p>
387391
HTML-CALC: </div>
388392
HTML-CALC: </div>
389393
HTML-CALC: </div>

0 commit comments

Comments
 (0)