Skip to content

Commit

Permalink
Allow @param tags to apply to record parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
dbartol committed Apr 2, 2024
1 parent 11acb49 commit ce98353
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions java/ql/src/Advisory/Documentation/SpuriousJavadocParam.ql
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,24 @@ where
)
or
documentable instanceof ClassOrInterface and
not documentable instanceof Record and
not exists(TypeVariable tv | tv.getGenericType() = documentable |
"<" + tv.getName() + ">" = paramTag.getParamName()
) and
msg =
"@param tag \"" + paramTag.getParamName() +
"\" does not match any actual type parameter of type \"" + documentable.getName() + "\"."
or
documentable instanceof Record and
not exists(TypeVariable tv | tv.getGenericType() = documentable |
"<" + tv.getName() + ">" = paramTag.getParamName()
) and
not documentable.(Record).getCanonicalConstructor().getAParameter().getName() =
paramTag.getParamName() and
msg =
"@param tag \"" + paramTag.getParamName() +
"\" does not match any actual type parameter or record parameter of record \"" +
documentable.getName() + "\"."
else
// The tag has no value at all.
msg = "This @param tag does not have a value."
Expand Down
5 changes: 5 additions & 0 deletions java/ql/src/change-notes/2024-04-02-javadoc-records.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
category: minorAnalysis
---
* The `java/unknown-javadoc-parameter` now accepts `@param` tags that apply to the parameters of a
record.
13 changes: 13 additions & 0 deletions java/ql/test/query-tests/SpuriousJavadocParam/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,18 @@ class GenericClass<T> {}
*/
interface GenericInterface<T> {}

/**
* @param i exists
* @param k does not
*/
static record SomeRecord(int i, int j) {}

/**
* @param <T> exists
* @param i exists
* @param k does not
*/
static record GenericRecord<T>(int i, int j) {}

// Diagnostic Matches: Incomplete inheritance relation for type java.lang.Object and supertype none
}
1 change: 1 addition & 0 deletions java/ql/test/query-tests/SpuriousJavadocParam/options
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//semmle-extractor-options: --javac-args -source 16 -target 16
2 changes: 2 additions & 0 deletions java/ql/test/query-tests/SpuriousJavadocParam/test.expected
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
| Test.java:112:6:112:12 | @param | @param tag "<X>" does not match any actual type parameter of type "GenericClass". |
| Test.java:118:6:118:12 | @param | @param tag "T" does not match any actual type parameter of type "GenericInterface". |
| Test.java:119:6:119:12 | @param | @param tag "<X>" does not match any actual type parameter of type "GenericInterface". |
| Test.java:125:6:125:12 | @param | @param tag "k" does not match any actual type parameter or record parameter of record "SomeRecord". |
| Test.java:132:6:132:12 | @param | @param tag "k" does not match any actual type parameter or record parameter of record "GenericRecord". |

0 comments on commit ce98353

Please sign in to comment.