Skip to content

Commit 02dfac9

Browse files
authored
Merge pull request github#640 from github/A2-7-3-doxygen
A2-7-3: Exclude Doxygen comment groups from results
2 parents cabf8d0 + 6a37d6a commit 02dfac9

File tree

4 files changed

+73
-11
lines changed

4 files changed

+73
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `A2-7-3` - `UndocumentedUserDefinedType.ql`:
2+
- Fixes #391. Declarations for which a Doxygen comment group provides documentation will no longer produce results.

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

+40-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,39 @@ 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+
pragma[inline]
35+
private predicate isBetweenDoxygenCommentGroup(
36+
Location loc, Comment opening, Comment body, Comment closing
37+
) {
38+
// All in the same file
39+
loc.getFile() = opening.getLocation().getFile() and
40+
loc.getFile() = closing.getLocation().getFile() and
41+
loc.getFile() = body.getLocation().getFile() and
42+
// The comments are doxygen comments
43+
opening.getContents().matches(doxygenCommentGroupStrings(true)) and
44+
closing.getContents().matches(doxygenCommentGroupStrings(false)) and
45+
// The closing comment is after the opening comment
46+
opening.getLocation().getStartLine() < closing.getLocation().getStartLine() and
47+
// The `body` comment directly precedes the opening comment
48+
body.getLocation().getEndLine() = opening.getLocation().getStartLine() - 1 and
49+
// There are no other opening/closing comment pairs between the opening and closing comments
50+
not exists(Comment c |
51+
c.getContents().matches(doxygenCommentGroupStrings(_)) and
52+
c.getLocation().getStartLine() > opening.getLocation().getStartLine() and
53+
c.getLocation().getStartLine() < closing.getLocation().getStartLine()
54+
) and
55+
// `loc` is between the opening and closing comments and after the body comment
56+
loc.getStartLine() > opening.getLocation().getStartLine() and
57+
loc.getStartLine() < closing.getLocation().getStartLine() and
58+
loc.getStartLine() > body.getLocation().getEndLine()
59+
}
60+
2861
/**
2962
* A declaration which is required to be preceded by documentation by AUTOSAR A2-7-3.
3063
*/
@@ -80,11 +113,13 @@ class DocumentableDeclaration extends Declaration {
80113
}
81114

82115
/**
83-
* A `DeclarationEntry` is considered documented if it has an associated `Comment`, and the `Comment`
84-
* precedes the `DeclarationEntry`.
116+
* A `DeclarationEntry` is considered documented if it has an associated `Comment`, the `Comment`
117+
* precedes the `DeclarationEntry`, and the `Comment` is not a doxygen comment group prefix.
85118
*/
119+
cached
86120
predicate isDocumented(DeclarationEntry de) {
87121
exists(Comment c | c.getCommentedElement() = de |
122+
not c.getContents() = doxygenCommentGroupStrings(true) and
88123
exists(Location commentLoc, Location deLoc |
89124
commentLoc = c.getLocation() and deLoc = de.getLocation()
90125
|
@@ -96,6 +131,9 @@ predicate isDocumented(DeclarationEntry de) {
96131
commentLoc.getStartColumn() < deLoc.getStartColumn()
97132
)
98133
)
134+
or
135+
// The declaration entry is between a doxygen comment group
136+
isBetweenDoxygenCommentGroup(de.getLocation(), _, _, _)
99137
}
100138

101139
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)