Skip to content

Commit ce98353

Browse files
author
Dave Bartolomeo
committed
Allow @param tags to apply to record parameters
1 parent 11acb49 commit ce98353

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

java/ql/src/Advisory/Documentation/SpuriousJavadocParam.ql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,24 @@ where
3232
)
3333
or
3434
documentable instanceof ClassOrInterface and
35+
not documentable instanceof Record and
3536
not exists(TypeVariable tv | tv.getGenericType() = documentable |
3637
"<" + tv.getName() + ">" = paramTag.getParamName()
3738
) and
3839
msg =
3940
"@param tag \"" + paramTag.getParamName() +
4041
"\" does not match any actual type parameter of type \"" + documentable.getName() + "\"."
42+
or
43+
documentable instanceof Record and
44+
not exists(TypeVariable tv | tv.getGenericType() = documentable |
45+
"<" + tv.getName() + ">" = paramTag.getParamName()
46+
) and
47+
not documentable.(Record).getCanonicalConstructor().getAParameter().getName() =
48+
paramTag.getParamName() and
49+
msg =
50+
"@param tag \"" + paramTag.getParamName() +
51+
"\" does not match any actual type parameter or record parameter of record \"" +
52+
documentable.getName() + "\"."
4153
else
4254
// The tag has no value at all.
4355
msg = "This @param tag does not have a value."
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The `java/unknown-javadoc-parameter` now accepts `@param` tags that apply to the parameters of a
5+
record.

java/ql/test/query-tests/SpuriousJavadocParam/Test.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,18 @@ class GenericClass<T> {}
120120
*/
121121
interface GenericInterface<T> {}
122122

123+
/**
124+
* @param i exists
125+
* @param k does not
126+
*/
127+
static record SomeRecord(int i, int j) {}
128+
129+
/**
130+
* @param <T> exists
131+
* @param i exists
132+
* @param k does not
133+
*/
134+
static record GenericRecord<T>(int i, int j) {}
135+
123136
// Diagnostic Matches: Incomplete inheritance relation for type java.lang.Object and supertype none
124137
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//semmle-extractor-options: --javac-args -source 16 -target 16

java/ql/test/query-tests/SpuriousJavadocParam/test.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@
1212
| Test.java:112:6:112:12 | @param | @param tag "<X>" does not match any actual type parameter of type "GenericClass". |
1313
| Test.java:118:6:118:12 | @param | @param tag "T" does not match any actual type parameter of type "GenericInterface". |
1414
| Test.java:119:6:119:12 | @param | @param tag "<X>" does not match any actual type parameter of type "GenericInterface". |
15+
| Test.java:125:6:125:12 | @param | @param tag "k" does not match any actual type parameter or record parameter of record "SomeRecord". |
16+
| Test.java:132:6:132:12 | @param | @param tag "k" does not match any actual type parameter or record parameter of record "GenericRecord". |

0 commit comments

Comments
 (0)