diff --git a/java-checks-test-sources/default/src/main/files/non-compiling/checks/api/undocumentedAPI/UndocumentedApi.java b/java-checks-test-sources/default/src/main/files/non-compiling/checks/api/undocumentedAPI/UndocumentedApi.java index 18efdfb1f5a..bfcf6bed790 100644 --- a/java-checks-test-sources/default/src/main/files/non-compiling/checks/api/undocumentedAPI/UndocumentedApi.java +++ b/java-checks-test-sources/default/src/main/files/non-compiling/checks/api/undocumentedAPI/UndocumentedApi.java @@ -67,7 +67,7 @@ public A() { // Noncompliant {{Document this public constructor by adding an exp /** * This is a Javadoc comment */ -public class MyClass implements Runnable { // Noncompliant {{Document the parameter(s): }} +public class MyClass implements Runnable { // Noncompliant {{Document the type parameter(s): }} private int status; // Compliant - not public diff --git a/java-checks-test-sources/default/src/main/java/checks/api/undocumentedAPI/UndocumentedApiJava23.java b/java-checks-test-sources/default/src/main/java/checks/api/undocumentedAPI/UndocumentedApiJava23.java index 87bf9a639b5..5b4de26c8e4 100644 --- a/java-checks-test-sources/default/src/main/java/checks/api/undocumentedAPI/UndocumentedApiJava23.java +++ b/java-checks-test-sources/default/src/main/java/checks/api/undocumentedAPI/UndocumentedApiJava23.java @@ -51,7 +51,7 @@ public String missingThrows(int value) throws NumberFormatException { // Noncomp } /// Documented, but not the type. - public class SomethingGenericBad { // Noncompliant {{Document the parameter(s): }} + public class SomethingGenericBad { // Noncompliant {{Document the type parameter(s): }} } /// Documented. diff --git a/java-checks/src/main/java/org/sonar/java/checks/UndocumentedApiCheck.java b/java-checks/src/main/java/org/sonar/java/checks/UndocumentedApiCheck.java index 962bcd211e8..1efb94e992c 100644 --- a/java-checks/src/main/java/org/sonar/java/checks/UndocumentedApiCheck.java +++ b/java-checks/src/main/java/org/sonar/java/checks/UndocumentedApiCheck.java @@ -20,7 +20,6 @@ import java.util.LinkedList; import java.util.Set; import java.util.regex.Pattern; -import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; import org.sonar.api.utils.WildcardPattern; import org.sonar.check.Rule; @@ -129,14 +128,15 @@ private void visitNode(Tree tree, Tree reportTree, SymbolMetadata symbolMetadata } else { Set 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 + String.join(", ", undocumentedParameters)); } if (hasNonVoidReturnType(tree) && javadoc.noReturnDescription()) { context.reportIssue(this, reportTree, "Document this method return value."); } Set undocumentedExceptions = javadoc.undocumentedThrownExceptions(); if (!undocumentedExceptions.isEmpty()) { - context.reportIssue(this, reportTree, "Document this method thrown exception(s): " + undocumentedExceptions.stream().collect(Collectors.joining(", "))); + context.reportIssue(this, reportTree, "Document this method thrown exception(s): " + String.join(", ", undocumentedExceptions)); } } } @@ -153,6 +153,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) || tree.is(Kind.RECORD)) ? "type parameter(s): " : "parameter(s): "; + } + private static String getType(Tree tree) { switch (tree.kind()) { case CONSTRUCTOR: @@ -163,10 +167,7 @@ private static String getType(Tree tree) { return "field"; case ANNOTATION_TYPE: return "annotation"; - case CLASS, - INTERFACE, - ENUM, - RECORD: + case CLASS, INTERFACE, ENUM, RECORD: return ((ClassTree) tree).declarationKeyword().text(); default: return "";