SONARJAVA-5719 S1176 Should have a separate message for undocumented type parameters.#5575
Conversation
SummaryThis PR modifies rule S1176 (undocumented API) to use context-aware messages for undocumented parameters:
The implementation adds a helper method What reviewers should knowStart here: Read Key changes:
Minor cleanup: Removed unused Reviewers should verify: The distinction between type parameters and method parameters is clear in the updated test cases, especially the record example around line 336.
|
| if (!undocumentedParameters.isEmpty()) { | ||
| context.reportIssue(this, reportTree, "Document the parameter(s): " + undocumentedParameters.stream().collect(Collectors.joining(", "))); | ||
| String label = getParamLabel(tree); | ||
| context.reportIssue(this, reportTree, "Document the " + label + undocumentedParameters.stream().collect(Collectors.joining(", "))); |
There was a problem hiding this comment.
We can try to improve existing code: String.join(", ", undocumentedParameters) should do the same as the long expression with a stream.
| * This is a Javadoc comment | ||
| */ | ||
| public class MyClass<T> implements Runnable { // Noncompliant {{Document the parameter(s): <T>}} | ||
| public class MyClass<T> implements Runnable { // Noncompliant {{Document the type parameter(s): <T>}} |
There was a problem hiding this comment.
How about something like this?
/**
* Description.
*/
public record MyRecord<U>(U a, int b) {
}
There was a problem hiding this comment.
We should add such a test I think. In addtion to that, Let's file a ticket that this rule should also flag record fields that do not have a description (b in the example will not trigger an issue).
tomasz-tylenda-sonarsource
left a comment
There was a problem hiding this comment.
Do we have a test for a record with fields and type parameters. If not, then let's add it. See the comment.
| * This is a Javadoc comment | ||
| */ | ||
| public class MyClass<T> implements Runnable { // Noncompliant {{Document the parameter(s): <T>}} | ||
| public class MyClass<T> implements Runnable { // Noncompliant {{Document the type parameter(s): <T>}} |
There was a problem hiding this comment.
We should add such a test I think. In addtion to that, Let's file a ticket that this rule should also flag record fields that do not have a description (b in the example will not trigger an issue).
|




Add separate message for type parameters in rule S1176.