Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public A() { // Noncompliant {{Document this public constructor by adding an exp
/**
* 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>}}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about something like this?

  /**
   * Description.
   */
  public record MyRecord<U>(U a, int b) {
  }


private int status; // Compliant - not public

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public String missingThrows(int value) throws NumberFormatException { // Noncomp
}

/// Documented, but not the type.
public class SomethingGenericBad<T> { // Noncompliant {{Document the parameter(s): <T>}}
public class SomethingGenericBad<T> { // Noncompliant {{Document the type parameter(s): <T>}}
}

/// Documented.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ private void visitNode(Tree tree, Tree reportTree, SymbolMetadata symbolMetadata
} else {
Set<String> undocumentedParameters = javadoc.undocumentedParameters();
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(", ")));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can try to improve existing code: String.join(", ", undocumentedParameters) should do the same as the long expression with a stream.

}
if (hasNonVoidReturnType(tree) && javadoc.noReturnDescription()) {
context.reportIssue(this, reportTree, "Document this method return value.");
Expand All @@ -153,6 +154,10 @@ private boolean isNonVoidMethodWithNoParameter(Tree tree, Javadoc javadoc) {
&& !javadoc.noReturnDescription();
}

private static String getParamLabel(Tree tree) {
return (tree.is(Kind.CLASS) || tree.is(Kind.INTERFACE)) ? "type parameter(s): " : "parameter(s): ";
Comment thread
sonar-review-alpha[bot] marked this conversation as resolved.
Outdated
}

private static String getType(Tree tree) {
switch (tree.kind()) {
case CONSTRUCTOR:
Expand Down
Loading