Skip to content

Commit a070371

Browse files
committed
Support Doxygen block comments
1 parent d17443b commit a070371

File tree

3 files changed

+69
-11
lines changed

3 files changed

+69
-11
lines changed

cpp/autosar/src/rules/A2-7-3/UndocumentedUserDefinedType.ql

+38-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,38 @@ private predicate isInFunctionScope(Declaration d) {
2525
isInFunctionScope(d.getDeclaringType())
2626
}
2727

28+
private string doxygenCommentGroupStrings(boolean opening) {
29+
opening = true and result = ["///@{", "/**@{*/"]
30+
or
31+
opening = false and result = ["///@}", "/**@}*/"]
32+
}
33+
34+
private predicate isBetweenDoxygenCommentGroup(
35+
Location loc, Comment opening, Comment body, Comment closing
36+
) {
37+
// All in the same file
38+
loc.getFile() = opening.getLocation().getFile() and
39+
loc.getFile() = closing.getLocation().getFile() and
40+
loc.getFile() = body.getLocation().getFile() and
41+
// The comments are doxygen comments
42+
opening.getContents().matches(doxygenCommentGroupStrings(true)) and
43+
closing.getContents().matches(doxygenCommentGroupStrings(false)) and
44+
// The closing comment is after the opening comment
45+
opening.getLocation().getStartLine() < closing.getLocation().getStartLine() and
46+
// The `body` comment directly precedes the opening comment
47+
body.getLocation().getEndLine() = opening.getLocation().getStartLine() - 1 and
48+
// There are no other opening/closing comment pairs between the opening and closing comments
49+
not exists(Comment c |
50+
c.getContents().matches(doxygenCommentGroupStrings(_)) and
51+
c.getLocation().getStartLine() > opening.getLocation().getStartLine() and
52+
c.getLocation().getStartLine() < closing.getLocation().getStartLine()
53+
) and
54+
// `loc` is between the opening and closing comments and after the body comment
55+
loc.getStartLine() > opening.getLocation().getStartLine() and
56+
loc.getStartLine() < closing.getLocation().getStartLine() and
57+
loc.getStartLine() > body.getLocation().getEndLine()
58+
}
59+
2860
/**
2961
* A declaration which is required to be preceded by documentation by AUTOSAR A2-7-3.
3062
*/
@@ -80,11 +112,12 @@ class DocumentableDeclaration extends Declaration {
80112
}
81113

82114
/**
83-
* A `DeclarationEntry` is considered documented if it has an associated `Comment`, and the `Comment`
84-
* precedes the `DeclarationEntry`.
115+
* A `DeclarationEntry` is considered documented if it has an associated `Comment`, the `Comment`
116+
* precedes the `DeclarationEntry`, and the `Comment` is not a doxygen comment group prefix.
85117
*/
86118
predicate isDocumented(DeclarationEntry de) {
87119
exists(Comment c | c.getCommentedElement() = de |
120+
not c.getContents() = doxygenCommentGroupStrings(true) and
88121
exists(Location commentLoc, Location deLoc |
89122
commentLoc = c.getLocation() and deLoc = de.getLocation()
90123
|
@@ -96,6 +129,9 @@ predicate isDocumented(DeclarationEntry de) {
96129
commentLoc.getStartColumn() < deLoc.getStartColumn()
97130
)
98131
)
132+
or
133+
// The declaration entry is between a doxygen comment group
134+
isBetweenDoxygenCommentGroup(de.getLocation(), _, _, _)
99135
}
100136

101137
from DocumentableDeclaration d, DeclarationEntry de
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
| test.cpp:70:7:70:12 | definition of ClassD | Declaration entry for user-defined type ClassD is missing documentation. |
2-
| test.cpp:72:7:72:7 | definition of a | Declaration entry for member variable a is missing documentation. |
3-
| test.cpp:73:14:73:14 | declaration of b | Declaration entry for member variable b is missing documentation. |
4-
| test.cpp:74:8:74:8 | declaration of f | Declaration entry for function f is missing documentation. |
5-
| test.cpp:76:7:76:7 | definition of c | Declaration entry for member variable c is missing documentation. |
6-
| test.cpp:78:6:78:6 | declaration of d | Declaration entry for function d is missing documentation. |
7-
| test.cpp:81:6:81:6 | definition of e | Declaration entry for function e is missing documentation. |
8-
| test.cpp:88:1:88:30 | definition of message_to_string_undocumented | Declaration entry for function message_to_string_undocumented is missing documentation. |
9-
| test.cpp:160:21:160:24 | definition of kBar | Declaration entry for member variable kBar is missing documentation. |
1+
| test.cpp:74:8:74:8 | declaration of j | Declaration entry for function j is missing documentation. |
2+
| test.cpp:75:8:75:8 | declaration of k | Declaration entry for function k is missing documentation. |
3+
| test.cpp:90:7:90:12 | definition of ClassD | Declaration entry for user-defined type ClassD is missing documentation. |
4+
| test.cpp:92:7:92:7 | definition of a | Declaration entry for member variable a is missing documentation. |
5+
| test.cpp:93:14:93:14 | declaration of b | Declaration entry for member variable b is missing documentation. |
6+
| test.cpp:94:8:94:8 | declaration of f | Declaration entry for function f is missing documentation. |
7+
| test.cpp:96:7:96:7 | definition of c | Declaration entry for member variable c is missing documentation. |
8+
| test.cpp:98:6:98:6 | declaration of d | Declaration entry for function d is missing documentation. |
9+
| test.cpp:101:6:101:6 | definition of e | Declaration entry for function e is missing documentation. |
10+
| test.cpp:108:1:108:30 | definition of message_to_string_undocumented | Declaration entry for function message_to_string_undocumented is missing documentation. |
11+
| test.cpp:180:21:180:24 | definition of kBar | Declaration entry for member variable kBar is missing documentation. |

cpp/autosar/test/rules/A2-7-3/test.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,30 @@ class ClassC { // COMPLIANT
6060
/// @param i an integer.
6161
/// @throw std::runtime_error
6262
void f(int i); // COMPLIANT
63+
64+
/** Same documentation for all members
65+
* This is a multiline comment.
66+
*/
67+
///@{
68+
void g(); // COMPLIANT
69+
void h(); // COMPLIANT
70+
void i(); // COMPLIANT
71+
///@}
72+
73+
///@{
74+
void j(); // NON_COMPLIANT
75+
void k(); // NON_COMPLIANT
76+
/** Member-specific documentation */
77+
void l(); // COMPLIANT
78+
///@}
79+
6380
private:
6481
/// @brief A Doxygen comment.
6582
int c; // COMPLIANT
6683
};
84+
void ClassC::i() { // not flagged, as we will only flag the non-definition
85+
// declaration
86+
}
6787
/// A Doxygen comment.
6888
void c(); // COMPLIANT
6989

0 commit comments

Comments
 (0)