Skip to content

Commit 986a406

Browse files
committed
Add empty-inline-tag.ql
1 parent 8475fd6 commit 986a406

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Finds empty Javadoc inline tags for tags which normally expect a value, e.g. `{@code}`.
3+
* In that case the empty inline tag has no effect (except for `{@value}` on fields), so most
4+
* likely the inline tag in the documentation comment is empty by accident.
5+
*
6+
* @kind problem
7+
*/
8+
9+
import java
10+
11+
from JavadocText javadocText, string tagName, string inlineTag
12+
where
13+
// Note: For some tags such as {@index} javadoc command displays an error
14+
(
15+
tagName = [
16+
"code",
17+
"index",
18+
"link",
19+
"linkplain",
20+
"literal",
21+
"summary",
22+
"systemProperty"
23+
]
24+
or
25+
// {@value} is allowed for fields
26+
tagName = "value"
27+
and not exists(Javadoc javadoc |
28+
javadoc = javadocText.getJavadoc()
29+
and javadoc.getCommentedElement() instanceof Field
30+
)
31+
)
32+
and inlineTag = javadocText.getText().regexpFind("\\{@" + tagName + "\\s*\\}", _, _)
33+
select javadocText, "Contains empty inline tag: " + inlineTag

0 commit comments

Comments
 (0)