|
1 | 1 | /** |
2 | 2 | * @name Spurious Javadoc @param tags |
3 | | - * @description Javadoc @param tags that do not match any parameters in the method or constructor are confusing. |
| 3 | + * @description Javadoc @param tags that do not match any parameters in the method or constructor or |
| 4 | + * any type parameters of the annotated class are confusing. |
4 | 5 | * @kind problem |
5 | 6 | * @problem.severity recommendation |
6 | 7 | * @precision very-high |
|
10 | 11 |
|
11 | 12 | import java |
12 | 13 |
|
13 | | -from Callable callable, ParamTag paramTag, string what, string msg |
| 14 | +from Documentable documentable, ParamTag paramTag, string msg |
14 | 15 | where |
15 | | - callable.(Documentable).getJavadoc().getAChild() = paramTag and |
16 | | - (if callable instanceof Constructor then what = "constructor" else what = "method") and |
| 16 | + documentable.getJavadoc().getAChild() = paramTag and |
17 | 17 | if exists(paramTag.getParamName()) |
18 | 18 | then |
19 | | - // The tag's value is neither matched by a callable parameter name ... |
20 | | - not callable.getAParameter().getName() = paramTag.getParamName() and |
21 | | - // ... nor by a type parameter name. |
22 | | - not exists(TypeVariable tv | tv.getGenericCallable() = callable | |
| 19 | + documentable instanceof Callable and |
| 20 | + exists(string what | |
| 21 | + if documentable instanceof Constructor then what = "constructor" else what = "method" |
| 22 | + | |
| 23 | + // The tag's value is neither matched by a callable parameter name ... |
| 24 | + not documentable.(Callable).getAParameter().getName() = paramTag.getParamName() and |
| 25 | + // ... nor by a type parameter name. |
| 26 | + not exists(TypeVariable tv | tv.getGenericCallable() = documentable | |
| 27 | + "<" + tv.getName() + ">" = paramTag.getParamName() |
| 28 | + ) and |
| 29 | + msg = |
| 30 | + "@param tag \"" + paramTag.getParamName() + "\" does not match any actual parameter of " + |
| 31 | + what + " \"" + documentable.getName() + "()\"." |
| 32 | + ) |
| 33 | + or |
| 34 | + documentable instanceof ClassOrInterface and |
| 35 | + not exists(TypeVariable tv | tv.getGenericType() = documentable | |
23 | 36 | "<" + tv.getName() + ">" = paramTag.getParamName() |
24 | 37 | ) and |
25 | 38 | msg = |
26 | | - "@param tag \"" + paramTag.getParamName() + "\" does not match any actual parameter of " + |
27 | | - what + " \"" + callable.getName() + "()\"." |
| 39 | + "@param tag \"" + paramTag.getParamName() + |
| 40 | + "\" does not match any actual type parameter of type \"" + documentable.getName() + "\"." |
28 | 41 | else |
29 | 42 | // The tag has no value at all. |
30 | 43 | msg = "This @param tag does not have a value." |
|
0 commit comments