Allow @param tags to apply to record parameters

This commit is contained in:
Dave Bartolomeo
2024-04-02 15:15:11 -04:00
parent 11acb499bb
commit ce98353d22
5 changed files with 33 additions and 0 deletions

View File

@@ -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."

View File

@@ -0,0 +1,5 @@
---
category: minorAnalysis
---
* The `java/unknown-javadoc-parameter` now accepts `@param` tags that apply to the parameters of a
record.

View File

@@ -120,5 +120,18 @@ public class Test<V> {
*/
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
}

View File

@@ -0,0 +1 @@
//semmle-extractor-options: --javac-args -source 16 -target 16

View File

@@ -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". |