Skip to content

Commit 996f535

Browse files
author
Dave Bartolomeo
authored
Merge pull request #16103 from github/dbartol/javadoc-record
Allow `@param` tags to apply to record parameters
2 parents 3656376 + b9cfeaf commit 996f535

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,17 @@ class GenericClass<T> {}
120120
*/
121121
interface GenericInterface<T> {}
122122

123-
// Diagnostic Matches: Incomplete inheritance relation for type java.lang.Object and supertype none
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 <U> does not
132+
* @param i exists
133+
* @param k does not
134+
*/
135+
static record GenericRecord<T>(int i, int j) {}
124136
}
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@
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:131:6:131:12 | @param | @param tag "<U>" does not match any actual type parameter or record parameter of record "GenericRecord". |
17+
| Test.java:133:6:133:12 | @param | @param tag "k" does not match any actual type parameter or record parameter of record "GenericRecord". |

0 commit comments

Comments
 (0)