diff --git a/.ci/validation.sh b/.ci/validation.sh index 3b32719d5b4..c96ae3eebf5 100755 --- a/.ci/validation.sh +++ b/.ci/validation.sh @@ -284,10 +284,8 @@ no-error-xwiki) echo "version:${CS_POM_VERSION} antlr4:${ANTLR4_VERSION}" mvn -e --no-transfer-progress clean install -Pno-validations echo "Checkout target sources ..." - checkout_from "https://github.com/kkoutsilis/xwiki-commons" + checkout_from "https://github.com/xwiki/xwiki-commons.git" cd .ci-temp/xwiki-commons - git ls-remote - git checkout "88f75d13376587956a5e5bd""dad0fa003383f190a" # Build custom Checkstyle rules mvn -e --no-transfer-progress -f \ xwiki-commons-tools/xwiki-commons-tool-verification-resources/pom.xml \ @@ -318,10 +316,8 @@ no-error-xwiki) cd .. removeFolderWithProtectedFiles xwiki-rendering cd .. - checkout_from https://github.com/kkoutsilis/xwiki-platform.git + checkout_from https://github.com/xwiki/xwiki-platform.git cd .ci-temp/xwiki-platform - git ls-remote - git checkout "01848f""ca559805b535559b7b94119a95990a2b5c" # Validate xwiki-platform mvn -e --no-transfer-progress checkstyle:check@default -Dcheckstyle.version="${CS_POM_VERSION}" cd .. diff --git a/config/checker-framework-suppressions/checker-index-suppressions.xml b/config/checker-framework-suppressions/checker-index-suppressions.xml index 16173efb3d6..03d64a05e51 100644 --- a/config/checker-framework-suppressions/checker-index-suppressions.xml +++ b/config/checker-framework-suppressions/checker-index-suppressions.xml @@ -1078,6 +1078,17 @@ + + src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/UnusedImportsCheck.java + return + incompatible types in return. + return methodIndex; +
+ type of expression: int + method return type: @LTLengthOf("input") int +
+
+ src/main/java/com/puppycrawl/tools/checkstyle/checks/indentation/AbstractExpressionHandler.java argument diff --git a/config/checker-framework-suppressions/checker-regex-property-key-compiler-message-suppressions.xml b/config/checker-framework-suppressions/checker-regex-property-key-compiler-message-suppressions.xml index 17ef65c9950..bd97697e3d0 100644 --- a/config/checker-framework-suppressions/checker-regex-property-key-compiler-message-suppressions.xml +++ b/config/checker-framework-suppressions/checker-regex-property-key-compiler-message-suppressions.xml @@ -297,6 +297,13 @@ references.add(topLevelType(matcher.group(1))); + + src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/UnusedImportsCheck.java + group.count.unknown + unable to verify non-literal groups parameter. + final String methodPart = matcher.group(methodIndex); + + src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.java group.count diff --git a/config/import-control.xml b/config/import-control.xml index ffbd5c88f97..786abebfb44 100644 --- a/config/import-control.xml +++ b/config/import-control.xml @@ -184,6 +184,7 @@ + diff --git a/pom.xml b/pom.xml index 2dba3622fa5..117762d3e6f 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.puppycrawl.tools checkstyle - 10.22.0 + 10.23.0 jar checkstyle @@ -1535,7 +1535,7 @@ org.apache.maven.plugins maven-failsafe-plugin - 3.5.2 + 3.5.3 com/google/**/*.java @@ -1562,7 +1562,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.5.2 + 3.5.3 -Dfile.encoding=UTF-8 ${surefire.options} @@ -1964,7 +1964,7 @@ org.apache.maven.plugins maven-surefire-report-plugin - 3.5.2 + 3.5.3 diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/XpathFileGeneratorAuditListener.java b/src/main/java/com/puppycrawl/tools/checkstyle/XpathFileGeneratorAuditListener.java index f42d830d81b..30a0c7118ca 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/XpathFileGeneratorAuditListener.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/XpathFileGeneratorAuditListener.java @@ -19,11 +19,11 @@ package com.puppycrawl.tools.checkstyle; -import java.io.File; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; +import java.nio.file.Path; import com.puppycrawl.tools.checkstyle.api.AuditEvent; import com.puppycrawl.tools.checkstyle.api.AuditListener; @@ -96,11 +96,11 @@ public void addError(AuditEvent event) { if (xpathQuery != null) { printXmlHeader(); - final File file = new File(event.getFileName()); + final Path path = Path.of(event.getFileName()); writer.println("Example:

+ *
{@code
+     * 
+     *     Table Head
+     * 
+     * }
+ * Tree: + *
+     * {@code
+     *  HTML_ELEMENT -> HTML_ELEMENT
+     *   `--TR -> TR
+     *       |--TR_TAG_START -> TR_TAG_START
+     *       |   |--START -> <
+     *       |   |--TR_HTML_TAG_NAME -> tr
+     *       |   `--END -> >
+     *       |--NEWLINE -> \r\n
+     *       |--LEADING_ASTERISK ->  *
+     *       |--TEXT ->
+     *       |--TH -> TH
+     *       |   |--TH_TAG_START -> TH_TAG_START
+     *       |   |   |--START -> <
+     *       |   |   |--TH_HTML_TAG_NAME -> th
+     *       |   |   `--END -> >
+     *       |   |--TEXT -> Table Head
+     *       |   `--TH_TAG_END -> TH_TAG_END
+     *       |       |--START -> <
+     *       |       |--SLASH -> /
+     *       |       |--TH_HTML_TAG_NAME -> th
+     *       |       `--END -> >
+     *       |--NEWLINE -> \r\n
+     *       |--LEADING_ASTERISK ->  *
+     *       |--TEXT ->
+     *       `--TR_TAG_END -> TR_TAG_END
+     *           |--START -> <
+     *           |--SLASH -> /
+     *           |--TR_HTML_TAG_NAME -> tr
+     *           `--END -> >
+     *  }
+     *  
+ * + * @see + * + * comments are written in HTML + * @see #TH_HTML_TAG_NAME + */ public static final int TH_HTML_TAG_NAME = JavadocParser.TH_HTML_TAG_NAME; /** Body tag name. */ @@ -1412,7 +1459,52 @@ public final class JavadocTokenTypes { */ public static final int DD_HTML_TAG_NAME = JavadocParser.DD_HTML_TAG_NAME; - /** Description term tag name. */ + /** + * Description term tag name. + * + *

Example:

+ *
{@code
+     * 
+ *
Java
+ *
+ * }
+ * Tree: + *
+     * {@code
+     *  HTML_ELEMENT -> HTML_ELEMENT
+     *   `--HTML_TAG -> HTML_TAG
+     *       |--HTML_ELEMENT_START -> HTML_ELEMENT_START
+     *       |   |--START -> <
+     *       |   |--HTML_TAG_NAME -> dl
+     *       |   `--END -> >
+     *       |--NEWLINE -> \r\n
+     *       |--LEADING_ASTERISK ->  *
+     *       |--TEXT ->
+     *       |--HTML_ELEMENT -> HTML_ELEMENT
+     *       |   `--DT -> DT
+     *       |       |--DT_TAG_START -> DT_TAG_START
+     *       |       |   |--START -> <
+     *       |       |   |--DT_HTML_TAG_NAME -> dt
+     *       |       |   `--END -> >
+     *       |       |--TEXT -> Java
+     *       |       `--DT_TAG_END -> DT_TAG_END
+     *       |           |--START -> <
+     *       |           |--SLASH -> /
+     *       |           |--DT_HTML_TAG_NAME -> dt
+     *       |           `--END -> >
+     *       |--NEWLINE -> \r\n
+     *       |--LEADING_ASTERISK ->  *
+     *       |--TEXT ->
+     *       `--HTML_ELEMENT_END -> HTML_ELEMENT_END
+     *           |--START -> <
+     *           |--SLASH -> /
+     *           |--HTML_TAG_NAME -> dl
+     *           `--END -> >
+     * }
+     * 
+ * + * @see #DT_HTML_TAG_NAME + */ public static final int DT_HTML_TAG_NAME = JavadocParser.DT_HTML_TAG_NAME; /** Head tag name. */ @@ -1496,19 +1588,19 @@ public final class JavadocTokenTypes { * Tree: *
      * {@code
-     *   JAVADOC ->; JAVADOC
-     *        |--NEWLINE ->; \r\n
-     *        |--LEADING_ASTERISK ->;  *
-     *        |--TEXT ->;  text before break
-     *        |--HTML_ELEMENT ->; HTML_ELEMENT
-     *        |   `--SINGLETON_ELEMENT ->; SINGLETON_ELEMENT
-     *        |       `--BR_TAG ->; BR_TAG
-     *        |           |--START ->; -<;
-     *        |           |--BR_HTML_TAG_NAME ->; br
-     *        |           `--END ->; >;
-     *        |--TEXT ->;  text after break
-     *        |--NEWLINE ->; \r\n
-     *        |--TEXT ->;
+     *   `--JAVADOC -> JAVADOC
+     *       |--NEWLINE -> \r\n
+     *       |--LEADING_ASTERISK ->  *
+     *       |--TEXT ->  text before break
+     *       |--HTML_ELEMENT -> HTML_ELEMENT
+     *       |   `--SINGLETON_ELEMENT -> SINGLETON_ELEMENT
+     *       |       `--BR_TAG -> BR_TAG
+     *       |           |--START -> <
+     *       |           |--BR_HTML_TAG_NAME -> br
+     *       |           `--END -> >
+     *       |--TEXT ->  text after break
+     *       |--NEWLINE -> \r\n
+     *       |--TEXT ->
      * }
      * 
*/ @@ -2322,7 +2414,28 @@ public final class JavadocTokenTypes { public static final int COLGROUP_TAG_END = JavadocParser.RULE_colgroupTagEnd + RULE_TYPES_OFFSET; - /** Description of a term html tag: {@code
}. */ + /** + * DD html tag. + * + *

Example AST:

+ *
{@code 
Description content
}
+ *
+     * {@code
+     *   --HTML_ELEMENT -> HTML_ELEMENT
+     *      `--DD -> DD
+     *          |--DD_TAG_START -> DD_TAG_START
+     *          |   |--START -> <
+     *          |   |--DD_HTML_TAG_NAME -> dd
+     *          |   `--END -> >
+     *          |--TEXT -> "Description content"
+     *          `--DD_TAG_END -> DD_TAG_END
+     *              |--START -> <
+     *              |--SLASH -> /
+     *              |--DD_HTML_TAG_NAME -> dd
+     *              `--END -> >
+     * }
+     * 
+ */ public static final int DD = JavadocParser.RULE_dd + RULE_TYPES_OFFSET; /** Start description of a term tag. */ public static final int DD_TAG_START = JavadocParser.RULE_ddTagStart + RULE_TYPES_OFFSET; @@ -2521,10 +2634,73 @@ public final class JavadocTokenTypes { /** Frame html tag. */ public static final int FRAME_TAG = JavadocParser.RULE_frameTag + RULE_TYPES_OFFSET; - /** Hr html tag. */ + /** + * Hr html tag. + * + *

Example:

+ *
{@code text above line
test after line}
+ * Tree: + *
+     * {@code
+     *   |--LEADING_ASTERISK ->  *
+     *   |--TEXT ->  text above line
+     *   |--HTML_ELEMENT -> HTML_ELEMENT
+     *   |   `--SINGLETON_ELEMENT -> SINGLETON_ELEMENT
+     *   |       `--HR_TAG -> HR_TAG
+     *   |           |--START -> <
+     *   |           |--HR_HTML_TAG_NAME -> hr
+     *   |           `--END -> >
+     *   |--TEXT ->  test after line
+     *   |--NEWLINE -> \r\n
+     *   |--TEXT ->
+     * }
+     * 
+ */ public static final int HR_TAG = JavadocParser.RULE_hrTag + RULE_TYPES_OFFSET; - /** Img html tag. */ + /** + * Img html tag. + * + *

Example:

+ *
{@code image description }
+ * Tree: + *
+     * {@code
+     *   `--JAVADOC -> JAVADOC
+     *        |--NEWLINE -> \r\n
+     *        |--LEADING_ASTERISK ->  *
+     *        |--TEXT ->
+     *        |--HTML_ELEMENT -> HTML_ELEMENT
+     *        |   `--SINGLETON_ELEMENT -> SINGLETON_ELEMENT
+     *        |       `--IMG_TAG -> IMG_TAG
+     *        |           |--START -> <
+     *        |           |--IMG_HTML_TAG_NAME -> img
+     *        |           |--WS ->
+     *        |           |--ATTRIBUTE -> ATTRIBUTE
+     *        |           |   |--HTML_TAG_NAME -> src
+     *        |           |   |--EQUALS -> =
+     *        |           |   `--ATTR_VALUE -> "./image.png"
+     *        |           |--WS ->
+     *        |           |--ATTRIBUTE -> ATTRIBUTE
+     *        |           |   |--HTML_TAG_NAME -> alt
+     *        |           |   |--EQUALS -> =
+     *        |           |   `--ATTR_VALUE -> "image description"
+     *        |           |--WS ->
+     *        |           |--ATTRIBUTE -> ATTRIBUTE
+     *        |           |   |--HTML_TAG_NAME -> width
+     *        |           |   |--EQUALS -> =
+     *        |           |   `--ATTR_VALUE -> "200"
+     *        |           |--WS ->
+     *        |           |--ATTRIBUTE -> ATTRIBUTE
+     *        |           |   |--HTML_TAG_NAME -> height
+     *        |           |   |--EQUALS -> =
+     *        |           |   `--ATTR_VALUE -> "100"
+     *        |           `--END -> >
+     *        |--NEWLINE -> \r\n
+     *        |--TEXT ->
+     * }
+     * 
+ */ public static final int IMG_TAG = JavadocParser.RULE_imgTag + RULE_TYPES_OFFSET; /** @@ -2573,7 +2749,34 @@ public final class JavadocTokenTypes { /** Link html tag. */ public static final int LINK_TAG = JavadocParser.RULE_linkTag + RULE_TYPES_OFFSET; - /** Meta html tag. */ + /** + * Meta html tag. + * + *

Example:

+ *
{@code  }
+ * Tree: + *
+     * {@code
+     *   `--JAVADOC -> JAVADOC
+     *        |--NEWLINE -> \r\n
+     *        |--LEADING_ASTERISK ->  *
+     *        |--TEXT ->
+     *        |--HTML_ELEMENT -> HTML_ELEMENT
+     *        |   `--SINGLETON_ELEMENT -> SINGLETON_ELEMENT
+     *        |       `--META_TAG -> META_TAG
+     *        |           |--START -> <
+     *        |           |--META_HTML_TAG_NAME -> meta
+     *        |           |--WS ->
+     *        |           |--ATTRIBUTE -> ATTRIBUTE
+     *        |           |   |--HTML_TAG_NAME -> charset
+     *        |           |   |--EQUALS -> =
+     *        |           |   `--ATTR_VALUE -> "UTF-8"
+     *        |           `--END -> >
+     *        |--NEWLINE -> \r\n
+     *        |--TEXT ->
+     * }
+     * 
+ */ public static final int META_TAG = JavadocParser.RULE_metaTag + RULE_TYPES_OFFSET; /** Param html tag. */ diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/UnusedImportsCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/UnusedImportsCheck.java index 3569d80a223..a4bc2dc02b6 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/UnusedImportsCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/UnusedImportsCheck.java @@ -19,13 +19,17 @@ package com.puppycrawl.tools.checkstyle.checks.imports; -import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.checkerframework.checker.index.qual.IndexOrLow; import com.puppycrawl.tools.checkstyle.FileStatefulCheck; import com.puppycrawl.tools.checkstyle.api.AbstractCheck; @@ -131,6 +135,18 @@ public class UnusedImportsCheck extends AbstractCheck { private static final Pattern JAVA_LANG_PACKAGE_PATTERN = CommonUtil.createPattern("^java\\.lang\\.[a-zA-Z]+$"); + /** Reference pattern. */ + private static final Pattern REFERENCE = Pattern.compile( + "^([a-z_$][a-z\\d_$<>.]*)?(#(.*))?$", + Pattern.CASE_INSENSITIVE + ); + + /** Method pattern. */ + private static final Pattern METHOD = Pattern.compile( + "^([a-z_$#][a-z\\d_$]*)(\\([^)]*\\))?$", + Pattern.CASE_INSENSITIVE + ); + /** Suffix for the star import. */ private static final String STAR_IMPORT_SUFFIX = ".*"; @@ -343,16 +359,18 @@ private void collectReferencesFromJavadoc(DetailAST ast) { * @return a set of classes referenced in the javadoc block */ private static Set collectReferencesFromJavadoc(TextBlock textBlock) { - final List tags = new ArrayList<>(); - // gather all the inline tags, like @link - // INLINE tags inside BLOCKs get hidden when using ALL - tags.addAll(getValidTags(textBlock, JavadocUtil.JavadocTagType.INLINE)); - // gather all the block-level tags, like @throws and @see - tags.addAll(getValidTags(textBlock, JavadocUtil.JavadocTagType.BLOCK)); + // Process INLINE tags + final List inlineTags = getTargetTags(textBlock, + JavadocUtil.JavadocTagType.INLINE); + // Process BLOCK tags + final List blockTags = getTargetTags(textBlock, + JavadocUtil.JavadocTagType.BLOCK); + final List targetTags = Stream.concat(inlineTags.stream(), blockTags.stream()) + .collect(Collectors.toUnmodifiableList()); final Set references = new HashSet<>(); - tags.stream() + targetTags.stream() .filter(JavadocTag::canReferenceImports) .forEach(tag -> references.addAll(processJavadocTag(tag))); return references; @@ -360,14 +378,22 @@ private static Set collectReferencesFromJavadoc(TextBlock textBlock) { /** * Returns the list of valid tags found in a javadoc {@link TextBlock}. + * Filters tags based on whether they are inline or block tags, ensuring they match + * the correct format supported. * * @param cmt The javadoc block to parse - * @param tagType The type of tags we're interested in + * @param javadocTagType The type of tags we're interested in * @return the list of tags */ - private static List getValidTags(TextBlock cmt, - JavadocUtil.JavadocTagType tagType) { - return JavadocUtil.getJavadocTags(cmt, tagType).getValidTags(); + private static List getTargetTags(TextBlock cmt, + JavadocUtil.JavadocTagType javadocTagType) { + return JavadocUtil.getJavadocTags(cmt, javadocTagType) + .getValidTags() + .stream() + .filter(tag -> isMatchingTagType(tag, javadocTagType)) + .map(UnusedImportsCheck::bestTryToMatchReference) + .flatMap(Optional::stream) + .collect(Collectors.toUnmodifiableList()); } /** @@ -423,6 +449,95 @@ private static String topLevelType(String type) { return topLevelType; } + /** + * Checks if a Javadoc tag matches the expected type based on its extraction format. + * This method checks if an inline tag is extracted as a block tag or vice versa. + * It ensures that block tags are correctly recognized as block tags and inline tags + * as inline tags during processing. + * + * @param tag The Javadoc tag to check. + * @param javadocTagType The expected type of the tag (BLOCK or INLINE). + * @return {@code true} if the tag matches the expected type, otherwise {@code false}. + */ + private static boolean isMatchingTagType(JavadocTag tag, + JavadocUtil.JavadocTagType javadocTagType) { + final boolean isInlineTag = tag.isInlineTag(); + final boolean isBlockTagType = javadocTagType == JavadocUtil.JavadocTagType.BLOCK; + + return isBlockTagType != isInlineTag; + } + + /** + * Attempts to match a reference string against a predefined pattern + * and extracts valid reference. + * + * @param tag the input tag to check + * @return Optional of extracted references + */ + public static Optional bestTryToMatchReference(JavadocTag tag) { + final String content = tag.getFirstArg(); + final int referenceIndex = extractReferencePart(content); + Optional validTag = Optional.empty(); + + if (referenceIndex != -1) { + final String referenceString; + if (referenceIndex == 0) { + referenceString = content; + } + else { + referenceString = content.substring(0, referenceIndex); + } + final Matcher matcher = REFERENCE.matcher(referenceString); + if (matcher.matches()) { + final int methodIndex = 3; + final String methodPart = matcher.group(methodIndex); + final boolean isValid = methodPart == null + || METHOD.matcher(methodPart).matches(); + if (isValid) { + validTag = Optional.of(tag); + } + } + } + return validTag; + } + + /** + * Extracts the reference part from an input string while ensuring balanced parentheses. + * + * @param input the input string + * @return -1 if parentheses are unbalanced, 0 if no method is found, + * or the index of the first space outside parentheses. + */ + private static @IndexOrLow("#1")int extractReferencePart(String input) { + int parenthesesCount = 0; + int firstSpaceOutsideParens = -1; + for (int index = 0; index < input.length(); index++) { + final char currentCharacter = input.charAt(index); + + if (currentCharacter == '(') { + parenthesesCount++; + } + else if (currentCharacter == ')') { + parenthesesCount--; + } + else if (currentCharacter == ' ' && parenthesesCount == 0) { + firstSpaceOutsideParens = index; + break; + } + } + + int methodIndex = -1; + if (parenthesesCount == 0) { + if (firstSpaceOutsideParens == -1) { + methodIndex = 0; + } + else { + methodIndex = firstSpaceOutsideParens; + } + } + return methodIndex; + } + /** * Holds the names of referenced types and names of declared inner types. */ diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.java index 8c3866e7428..7c09514d5ac 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.java @@ -115,6 +115,11 @@ * Default value is {@code public, protected, package, private}. * *
  • + * Property {@code allowInlineReturn} - Control whether to allow inline return tags. + * Type is {@code boolean}. + * Default value is {@code false}. + *
  • + *
  • * Property {@code allowMissingParamTags} - Control whether to ignore violations * when a method has parameters but does not have matching {@code param} tags in the javadoc. * Type is {@code boolean}. @@ -256,6 +261,9 @@ public class JavadocMethodCheck extends AbstractCheck { /** Compiled regexp to match Javadoc tags with no argument. */ private static final Pattern MATCH_JAVADOC_NOARG = CommonUtil.createPattern("^\\s*(?>\\*|\\/\\*\\*)?\\s*@(return|see)\\s+\\S"); + /** Compiled regexp to match Javadoc tags with no argument allowing inline return tag. */ + private static final Pattern MATCH_JAVADOC_NOARG_INLINE_RETURN = + CommonUtil.createPattern("^\\s*(?>\\*|\\/\\*\\*)?\\s*\\{?@(return|see)\\s+\\S"); /** Compiled regexp to match first part of multilineJavadoc tags. */ private static final Pattern MATCH_JAVADOC_NOARG_MULTILINE_START = CommonUtil.createPattern("^\\s*(?>\\*|\\/\\*\\*)?\\s*@(return|see)\\s*$"); @@ -263,6 +271,11 @@ public class JavadocMethodCheck extends AbstractCheck { private static final Pattern MATCH_JAVADOC_NOARG_CURLY = CommonUtil.createPattern("\\{\\s*@(inheritDoc)\\s*\\}"); + /** + * Control whether to allow inline return tags. + */ + private boolean allowInlineReturn; + /** Specify the access modifiers where Javadoc comments are checked. */ private AccessModifierOption[] accessModifiers = { AccessModifierOption.PUBLIC, @@ -291,6 +304,16 @@ public class JavadocMethodCheck extends AbstractCheck { /** Specify annotations that allow missed documentation. */ private Set allowedAnnotations = Set.of("Override"); + /** + * Setter to control whether to allow inline return tags. + * + * @param value a {@code boolean} value + * @since 10.22.1 + */ + public void setAllowInlineReturn(boolean value) { + allowInlineReturn = value; + } + /** * Setter to control whether to validate {@code throws} tags. * @@ -511,7 +534,11 @@ private boolean hasShortCircuitTag(final DetailAST ast, final List t * @param comment the Javadoc comment * @return the tags found */ - private static List getMethodTags(TextBlock comment) { + private List getMethodTags(TextBlock comment) { + Pattern matchJavadocNoArg = MATCH_JAVADOC_NOARG; + if (allowInlineReturn) { + matchJavadocNoArg = MATCH_JAVADOC_NOARG_INLINE_RETURN; + } final String[] lines = comment.getText(); final List tags = new ArrayList<>(); int currentLine = comment.getStartLineNo() - 1; @@ -524,7 +551,7 @@ private static List getMethodTags(TextBlock comment) { final Matcher javadocArgMissingDescriptionMatcher = MATCH_JAVADOC_ARG_MISSING_DESCRIPTION.matcher(lines[i]); final Matcher javadocNoargMatcher = - MATCH_JAVADOC_NOARG.matcher(lines[i]); + matchJavadocNoArg.matcher(lines[i]); final Matcher noargCurlyMatcher = MATCH_JAVADOC_NOARG_CURLY.matcher(lines[i]); final Matcher noargMultilineStart = diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocTag.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocTag.java index d1b5570c84b..2830d7389d0 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocTag.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocTag.java @@ -163,4 +163,13 @@ public boolean canReferenceImports() { || tagInfo == JavadocTagInfo.EXCEPTION; } + /** + * Checks that the tag is a inline tag. + * + * @return whether the tag is a inline tag + */ + public boolean isInlineTag() { + return tagInfo.getType() == JavadocTagInfo.Type.INLINE; + } + } diff --git a/src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/javadoc/JavadocMethodCheck.xml b/src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/javadoc/JavadocMethodCheck.xml index e0f031f00d0..455e0678377 100644 --- a/src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/javadoc/JavadocMethodCheck.xml +++ b/src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/javadoc/JavadocMethodCheck.xml @@ -74,6 +74,9 @@ Specify the access modifiers where Javadoc comments are checked. + + Control whether to allow inline return tags. + Control whether to ignore violations when a method has parameters but does not have matching {@code param} tags in the javadoc. diff --git a/src/site/xdoc/checks/javadoc/javadocmethod.xml b/src/site/xdoc/checks/javadoc/javadocmethod.xml index 8fae1bb10bc..8149a15d898 100644 --- a/src/site/xdoc/checks/javadoc/javadocmethod.xml +++ b/src/site/xdoc/checks/javadoc/javadocmethod.xml @@ -100,6 +100,13 @@ public int checkReturnTag(final int aTagIndex, public, protected, package, private 8.42 + + allowInlineReturn + Control whether to allow inline return tags. + boolean + false + 10.22.1 + allowMissingParamTags Control whether to ignore violations when a method has parameters but does not have matching param tags in the javadoc. @@ -482,6 +489,37 @@ public class Example7 { }; } } + + +

    + To configure the check to allow inline return tags, + you can use following config. +

    +
    
    +<module name="Checker">
    +  <module name="TreeWalker">
    +    <module name="JavadocMethod">
    +        <property name="allowInlineReturn" value="true"/>
    +    </module>
    +  </module>
    +</module>
    +
    +

    Example:

    +
    
    +public class Example8 {
    +
    +  /**
    +   * {@return the foo}
    +   */
    +  public int getFoo() { return 0; }
    +
    +  /**
    +   * Returns the bar
    +   * @return the bar
    +   */
    +  public int getBar() { return 0; }
    +
    +}
     
    diff --git a/src/site/xdoc/checks/javadoc/javadocmethod.xml.template b/src/site/xdoc/checks/javadoc/javadocmethod.xml.template index 2cf84d809ba..32a3c991a7f 100644 --- a/src/site/xdoc/checks/javadoc/javadocmethod.xml.template +++ b/src/site/xdoc/checks/javadoc/javadocmethod.xml.template @@ -195,6 +195,22 @@ public int checkReturnTag(final int aTagIndex, value="resources/com/puppycrawl/tools/checkstyle/checks/javadoc/javadocmethod/Example7.java"/> + +

    + To configure the check to allow inline return tags, + you can use following config. +

    + + + + +

    Example:

    + + + +
      diff --git a/src/site/xdoc/filters/suppressionsinglefilter.xml b/src/site/xdoc/filters/suppressionsinglefilter.xml index 0a4bbd80567..1a31e0ed50a 100644 --- a/src/site/xdoc/filters/suppressionsinglefilter.xml +++ b/src/site/xdoc/filters/suppressionsinglefilter.xml @@ -93,15 +93,9 @@

      - The following suppressions directs - a SuppressionSingleFilter to - reject JavadocStyleCheck violations for - lines 82 and 108 to 122 of - file AbstractComplexityCheck.java, - and MagicNumberCheck violations for line - 221 of file JavadocStyleCheck.java, - and 'Missing a Javadoc comment' violations - for all lines and files: + To configure a filter to suppress violations of JavadocStyle and + MagicNumber checks in Example1.java for specific line ranges + using SuppressionSingleFilter:

      
       <module name="Checker">
      @@ -110,12 +104,7 @@
           <module name="MagicNumber"/>
         </module>
         <module name="SuppressionSingleFilter">
      -    <property name="checks" value="JavadocStyle"/>
      -    <property name="files" value="Example1.java"/>
      -    <property name="lines" value="1,5-100"/>
      -  </module>
      -  <module name="SuppressionSingleFilter">
      -    <property name="checks" value="MagicNumber"/>
      +    <property name="checks" value="JavadocStyle|MagicNumber"/>
           <property name="files" value="Example1.java"/>
           <property name="lines" value="1,5-100"/>
         </module>
      @@ -129,23 +118,24 @@
               
      
       public class Example1 {
         public void exampleMethod() {
      -    int value = 100;
      -    // filtered violation ''100' is a magic number'
      +    int value = 100; // filtered violation ''100' is a magic number'
         }
       }
       

      - Suppress check by module id - when config have two instances on the same check: + To configure a filter to suppress violations of JavadocMethod and + EqualsAvoidNull checks in Example2.java using + SuppressionSingleFilter:

      
       <module name="Checker">
      -  <module name="EqualsAvoidNull"/>
      -  <module name="JavadocMethod"/>
      +  <module name="TreeWalker">
      +    <module name="JavadocMethod"/>
      +    <module name="EqualsAvoidNull"/>
      +  </module>
         <module name="SuppressionSingleFilter">
      -    <property name="id" value="stringEqual"/>
           <property name="files" value="Example2.java"/>
      -    <property name="checks" value="EqualsAvoidNull, JavadocMethod"/>
      +    <property name="checks" value="JavadocMethod|EqualsAvoidNull"/>
         </module>
       </module>
       
      @@ -154,19 +144,25 @@ public class Example1 {
      
       public class Example2 {
       
      -  public void checkStringEquality(String str1, String str2) {
      -    // filtered violation ''.equals()' should be used for string comparison'
      -    assert str1 == str2 ;
      +  public void checkStringEquality(String s) {
      +    // filtered violation below 'String literal expressions should be on the left'
      +    s.equals("M");
         }
      +  /**
      +   * @param p1 The first number
      +   */
      +  // filtered violation below '@return tag should be present'
      +  private int m2(int p1) { return p1; }
       }
       

      - Suppress all checks for hidden files and folders: + To configure a filter to suppress violations of RegexpSinglelineCheck + in Example3.java using SuppressionSingleFilter:

      
       <module name="Checker">
         <module name="RegexpSingleline">
      -    <property name="format" value=".*example.*"/>
      +    <property name="format" value="example"/>
         </module>
         <module name="SuppressionSingleFilter">
           <property name="files" value="Example3.java"/>
      @@ -180,26 +176,28 @@ public class Example2 {
       public class Example3 {
       
         public void printExample() {
      -    // filtered violation 'Line matches the illegal pattern 'example''
           System.out.println(
      -      "This is an example string."
      +      "example" // filtered violation 'Line matches the illegal pattern 'example''
           );
         }
       
         public void noViolation() {
           System.out.println(
      -      "This string does not contain 'example'."
      +      "RegexpSingleline is case sensitive by default. 'Example' in not matching."
           );
         }
       
       }
       

      - Suppress all checks for Maven-generated code: + To configure a filter to suppress violations of NoWhitespaceAfter + in Example4.java using SuppressionSingleFilter:

      
       <module name="Checker">
      -  <module name="NoWhitespaceAfter"/>
      +  <module name="TreeWalker">
      +    <module name="NoWhitespaceAfter"/>
      +  </module>
         <module name="SuppressionSingleFilter">
           <property name="files" value="Example4.java"/>
           <property name="checks" value="NoWhitespaceAfter"/>
      @@ -211,18 +209,20 @@ public class Example3 {
               
      
       public class Example4 {
       
      -  // filtered violation 'WhiteSpace after ',''
         public void exampleMethod(int a, int b) {
      +    // filtered violation below ''.' is followed by whitespace'
      +    Integer. parseInt("3");
         }
       
         public void exampleMethod2() {
      -    int x = 5 ; // filtered violation 'WhiteSpace before ';''
      +    int [] x; // filtered violation ''int' is followed by whitespace'
         }
       
       }
       

      - Suppress all checks for archives, classes and other binary files: + To configure a filter to suppress violations of MethodName + in Example5.java using SuppressionSingleFilter:

      
       <module name="Checker">
      @@ -237,17 +237,17 @@ public class Example4 {
               

      
       public class Example5 {
      -  // filtered violation 'Name 'example_Method' must match pattern'
      +  // filtered violation below 'Name 'example_Method' must match pattern'
         public void example_Method() {
         }
      -
      -  // filtered violation Name 'Another_Method' must match pattern
      +  // filtered violation below 'Name 'Another_Method' must match pattern'
         public void Another_Method() {
         }
       }
       

      - Suppress all checks for image files: + To configure a filter to suppress violations of ConstantName + in Example6.java using SuppressionSingleFilter:

      
       <module name="Checker">
      @@ -262,21 +262,23 @@ public class Example5 {
               

      
       public class Example6 {
      -
      -  // filtered violation 'Name 'myConstant' must match pattern'
      +  // filtered violation below 'Name 'myConstant' must match pattern'
         private static final int myConstant = 42;
       
       }
       

      - Suppress all checks for non-java files: + To configure a filter to suppress violations of MemberName + and MethodName in Example7.java using + SuppressionSingleFilter:

      
       <module name="Checker">
         <module name="MemberName"/>
      +  <module name="MethodName"/>
         <module name="SuppressionSingleFilter">
           <property name="files" value="Example7.java"/>
      -    <property name="checks" value="MemberName"/>
      +    <property name="checks" value="MemberName|MethodName"/>
         </module>
       </module>
       
      @@ -284,20 +286,16 @@ public class Example6 {

      
       public class Example7 {
      -
      -  // filtered violation 'Name 'MyVariable' must match pattern'
      +  // filtered violation below 'Name 'MyVariable' must match pattern'
         private int MyVariable = 5;
      -
      -  // filtered violation 'Name 'PrintHello' must match pattern'
      -  public void PrintHello() {
      -  }
      -
      -  public void printHello() {
      +  // filtered violation below 'Name 'MyMethod' must match pattern'
      +  public void MyMethod() {
         }
       }
       

      - Suppress all checks in generated sources: + To configure a filter to suppress ParameterNumber violations + in Example8.java using SuppressionSingleFilter:

      
       <module name="Checker">
      @@ -316,15 +314,15 @@ public class Example7 {
               

      
       public class Example8 {
      -  // filtered violation 'more than 5 parameters'
      +  // filtered violation below 'More than 5 parameters (found 6)'
         public void exampleMethod(
      -    int param1, int param2, int param3, int param4,
      -    int param5
      +    int param1, int param2, int param3, int param4, int param5, int param6
         ) {}
       }
       

      - Suppress FileLength check on integration tests in certain folder: + To configure a filter to suppress FileLength violations + in Example9.java using SuppressionSingleFilter:

      
       <module name="Checker">
      @@ -342,12 +340,14 @@ public class Example8 {
               

      
      +/* filtered violation on 1st line  'File length is 4 lines (max allowed is 1)' */
       public class Example9 {
      -  //filtered violation 'File length is 19 lines (max allowed is 1)'
      +
       }
       

      - Suppress naming violations on variable named 'log' in all files: + To configure a filter to suppress MemberName violations + in Example10.java using SuppressionSingleFilter:

      
       <module name="Checker">
      @@ -364,8 +364,7 @@ public class Example9 {
               

      
       public class Example10 {
      -
      -  // filtered violation 'Name 'log' must match pattern'
      +  // filtered violation below 'Name 'log' must match pattern'
         private String log = "Some log message";
       
       }
      diff --git a/src/site/xdoc/filters/suppressionsinglefilter.xml.template b/src/site/xdoc/filters/suppressionsinglefilter.xml.template
      index 3ed56cffd85..c3736fa48a7 100644
      --- a/src/site/xdoc/filters/suppressionsinglefilter.xml.template
      +++ b/src/site/xdoc/filters/suppressionsinglefilter.xml.template
      @@ -46,15 +46,9 @@
             
             
               

      - The following suppressions directs - a SuppressionSingleFilter to - reject JavadocStyleCheck violations for - lines 82 and 108 to 122 of - file AbstractComplexityCheck.java, - and MagicNumberCheck violations for line - 221 of file JavadocStyleCheck.java, - and 'Missing a Javadoc comment' violations - for all lines and files: + To configure a filter to suppress violations of JavadocStyle and + MagicNumber checks in Example1.java for specific line ranges + using SuppressionSingleFilter:

      - Suppress check by module id - when config have two instances on the same check: + To configure a filter to suppress violations of JavadocMethod and + EqualsAvoidNull checks in Example2.java using + SuppressionSingleFilter:

      - Suppress all checks for hidden files and folders: + To configure a filter to suppress violations of RegexpSinglelineCheck + in Example3.java using SuppressionSingleFilter:

      - Suppress all checks for Maven-generated code: + To configure a filter to suppress violations of NoWhitespaceAfter + in Example4.java using SuppressionSingleFilter:

      - Suppress all checks for archives, classes and other binary files: + To configure a filter to suppress violations of MethodName + in Example5.java using SuppressionSingleFilter:

      - Suppress all checks for image files: + To configure a filter to suppress violations of ConstantName + in Example6.java using SuppressionSingleFilter:

      - Suppress all checks for non-java files: + To configure a filter to suppress violations of MemberName + and MethodName in Example7.java using + SuppressionSingleFilter:

      - Suppress all checks in generated sources: + To configure a filter to suppress ParameterNumber violations + in Example8.java using SuppressionSingleFilter:

      - Suppress FileLength check on integration tests in certain folder: + To configure a filter to suppress FileLength violations + in Example9.java using SuppressionSingleFilter:

      - Suppress naming violations on variable named 'log' in all files: + To configure a filter to suppress MemberName violations + in Example10.java using SuppressionSingleFilter:

      +
      +
      02.04.2025
      +

      New:

      +
        +
      • + JavadocMethod: new property 'allowInlineReturn' to support for Javadoc return + tag as inline. + Author: Konstantinos Koutsilis + #9745 +
      • +
      +

      Bug fixes:

      +
        +
      • + False negative in UnusedImportCheck. + Author: Ziad Ahmed + #14697 +
      • +
      +

      Notes:

      +
        +
      • + SuppressionSingleFilterExamplesTest methods should use: + `verifyFilterWithInlineConfigParser`. + Author: Prarthana-Ramesh + #16332 +
      • +
      • + XMLLoggerTest.java to use verifyWithInlineConfigParserAndXmlLogger. + Author: Priyambada Roul + #16360 +
      • +
      • + update JavadocTokenTypes.java to new format of AST print. + Author: Simran, Brijeshthummar02, ZaeemSheikh + #14631 +
      • +
      • + use new nio jdk api instead of all api. + Author: Priyambada Roul + #16155 +
      • +
      • + CircleCI is failing on xwiki validation.. + Author: MD. Zaid + #16671 +
      • +
      +
      30.03.2025

      Breaking backward compatibility:

      @@ -79,7 +128,9 @@
      • update JavadocTokenTypes.java to new format of AST print. - Author: MD. Zaid, Prarthana-Ramesh, Sambhav Jain, Mohammad Soleh, Simran, Mahmoud Ayman, YuktiNandwana, Ziad Abd El-Fatah, sushanthraiurwa, kapishyadav, abdelrhmansersawy, kornilov-mr, Abhishek Bansode, Brijeshthummar02 + Author: MD. Zaid, Prarthana-Ramesh, Sambhav Jain, Mohammad Soleh, Simran, Mahmoud Ayman, + YuktiNandwana, Ziad Abd El-Fatah, sushanthraiurwa, kapishyadav, abdelrhmansersawy, + kornilov-mr, Abhishek Bansode, Brijeshthummar02 #14631
      • @@ -94,7 +145,8 @@
      • Enforce file size on Java inputs. - Author: Atharv Chavan, Mahmoud Ayman, MD. Zaid, vishakha-mali, Ziad Abd El-Fatah, kapishyadav, abdelrhmansersawy, bishoy, ZaeemSheikh + Author: Atharv Chavan, Mahmoud Ayman, MD. Zaid, vishakha-mali, Ziad Abd El-Fatah, + kapishyadav, abdelrhmansersawy, bishoy, ZaeemSheikh #11163
      • @@ -133,7 +185,8 @@
      • Define violation messages for all violations. - Author: Atharv Chavan, jerryyummy, MD. Zaid, Mahmoud Ayman, kapishyadav, abdelrhmansersawy, Abhishek Bansode, Prarthana-Ramesh, kornilov-mr, ZaeemSheikh + Author: Atharv Chavan, jerryyummy, MD. Zaid, Mahmoud Ayman, kapishyadav, + abdelrhmansersawy, Abhishek Bansode, Prarthana-Ramesh, kornilov-mr, ZaeemSheikh #15456
      • diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/XMLLoggerTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/XMLLoggerTest.java index e753e17aadd..c52f18aa1d9 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/XMLLoggerTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/XMLLoggerTest.java @@ -179,18 +179,8 @@ public void testFileFinished() @Test public void testAddError() throws Exception { - final XMLLogger logger = new XMLLogger(outStream, OutputStreamOptions.CLOSE); - logger.auditStarted(null); - final Violation violation = - new Violation(1, 1, - "messages.properties", "key", null, SeverityLevel.ERROR, null, - getClass(), null); - final AuditEvent ev = new AuditEvent(this, "Test.java", violation); - logger.fileStarted(ev); - logger.addError(ev); - logger.fileFinished(ev); - logger.auditFinished(null); - verifyXml(getPath("ExpectedXMLLoggerError.xml"), outStream, violation.getViolation()); + verifyWithInlineConfigParserAndXmlLogger("InputXMLLoggerAddError.java", + "ExpectedXMLLoggerAddError.xml"); } @Test @@ -232,19 +222,8 @@ public void testAddErrorWithEncodedMessage() throws Exception { @Test public void testAddErrorOnZeroColumns() throws Exception { - final XMLLogger logger = new XMLLogger(outStream, OutputStreamOptions.CLOSE); - logger.auditStarted(null); - final Violation violation = - new Violation(1, 0, - "messages.properties", "key", null, SeverityLevel.ERROR, null, - getClass(), null); - final AuditEvent ev = new AuditEvent(this, "Test.java", violation); - logger.fileStarted(ev); - logger.addError(ev); - logger.fileFinished(ev); - logger.auditFinished(null); - verifyXml(getPath("ExpectedXMLLoggerErrorZeroColumn.xml"), outStream, - violation.getViolation()); + verifyWithInlineConfigParserAndXmlLogger("InputXMLLoggerErrorOnZeroColumn.java", + "ExpectedXMLLoggerErrorZeroColumn.xml"); } @Test diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/bdd/InlineConfigParser.java b/src/test/java/com/puppycrawl/tools/checkstyle/bdd/InlineConfigParser.java index bc9911f9cdd..1182c2e54aa 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/bdd/InlineConfigParser.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/bdd/InlineConfigParser.java @@ -130,6 +130,10 @@ public final class InlineConfigParser { private static final Pattern FILTERED_VIOLATION_BELOW_PATTERN = Pattern .compile(".*//\\s*filtered violation below\\s*(?:['\"](.*)['\"])?$"); + /** A pattern to find the string: "// filtered violation X lines above". */ + private static final Pattern FILTERED_VIOLATION_SOME_LINES_ABOVE_PATTERN = Pattern + .compile(".*//\\s*filtered violation (\\d+) lines above\\s*(?:['\"](.*)['\"])?$"); + /** A pattern to find the string: "// violation X lines above". */ private static final Pattern VIOLATION_SOME_LINES_ABOVE_PATTERN = Pattern .compile(".*//\\s*violation (\\d+) lines above\\s*(?:['\"](.*)['\"])?$"); @@ -1099,6 +1103,8 @@ private static void setFilteredViolation(TestInputConfiguration.Builder inputCon FILTERED_VIOLATION_ABOVE_PATTERN.matcher(line); final Matcher violationBelowMatcher = FILTERED_VIOLATION_BELOW_PATTERN.matcher(line); + final Matcher violationSomeLinesAboveMatcher = + FILTERED_VIOLATION_SOME_LINES_ABOVE_PATTERN.matcher(line); if (violationMatcher.matches()) { final String violationMessage = violationMatcher.group(1); checkWhetherViolationSpecified(specifyViolationMessage, violationMessage, lineNo); @@ -1118,6 +1124,14 @@ else if (violationBelowMatcher.matches()) { violationLineNum); inputConfigBuilder.addFilteredViolation(violationLineNum, violationMessage); } + else if (violationSomeLinesAboveMatcher.matches()) { + final String violationMessage = violationSomeLinesAboveMatcher.group(2); + final int linesAbove = Integer.parseInt(violationSomeLinesAboveMatcher.group(1)) - 1; + final int violationLineNum = lineNo - linesAbove; + checkWhetherViolationSpecified(specifyViolationMessage, violationMessage, + violationLineNum); + inputConfigBuilder.addFilteredViolation(violationLineNum, violationMessage); + } } /** diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/UnusedImportsCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/UnusedImportsCheckTest.java index 6aa78e9a1c5..b6e80fb31c8 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/UnusedImportsCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/UnusedImportsCheckTest.java @@ -390,4 +390,32 @@ public void testUnusedImportsJavadocAboveComments() throws Exception { getPath("InputUnusedImportsJavadocAboveComments.java"), expected); } + @Test + public void testImportJavaLinkTag() throws Exception { + final String[] expected = { + "10:8: " + getCheckMessage(MSG_KEY, "java.util.List"), + "12:8: " + getCheckMessage(MSG_KEY, "java.util.TreeSet"), + + }; + verifyWithInlineConfigParser( + getPath("InputUnusedImportsWithLinkTag.java"), expected); + + } + + @Test + public void testImportJavaLinkTagWithMethod() throws Exception { + final String[] expected = { + "10:8: " + getCheckMessage(MSG_KEY, "java.util.Collections"), + "12:8: " + getCheckMessage(MSG_KEY, "java.util.Set"), + "14:8: " + getCheckMessage(MSG_KEY, "java.util.PriorityQueue"), + "16:8: " + getCheckMessage(MSG_KEY, "java.util.Queue"), + "20:8: " + getCheckMessage(MSG_KEY, "java.util.LinkedList"), + "24:8: " + getCheckMessage(MSG_KEY, "java.time.LocalDateTime"), + "27:8: " + getCheckMessage(MSG_KEY, "java.util.concurrent.TimeUnit"), + }; + verifyWithInlineConfigParser( + getPath("InputUnusedImportsWithLinkAndMethodTag.java"), expected); + + } + } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheckTest.java index 1c806e795c7..0d07a1bbf77 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheckTest.java @@ -590,4 +590,25 @@ public void testJavadocMethodAboveComments() throws Exception { verifyWithInlineConfigParser( getPath("InputJavadocMethodAboveComments.java"), expected); } + + @Test + public void testJavadocMethodAllowInlineReturn() throws Exception { + final String[] expected = { + "32: " + getCheckMessage(MSG_RETURN_EXPECTED), + "39: " + getCheckMessage(MSG_RETURN_EXPECTED), + }; + verifyWithInlineConfigParser( + getPath("InputJavadocMethodAllowInlineReturn.java"), expected); + } + + @Test + public void testJavadocMethodDoNotAllowInlineReturn() throws Exception { + final String[] expected = { + "21: " + getCheckMessage(MSG_RETURN_EXPECTED), + "33: " + getCheckMessage(MSG_RETURN_EXPECTED), + "40: " + getCheckMessage(MSG_RETURN_EXPECTED), + }; + verifyWithInlineConfigParser( + getPath("InputJavadocMethodDoNotAllowInlineReturn.java"), expected); + } } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocTagTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocTagTest.java index 853c9a9f3ee..80f31c21a0c 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocTagTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocTagTest.java @@ -86,4 +86,12 @@ public void testJavadocTagReferenceImportsInvalid() { .isFalse(); } + @Test + public void testJavadocTagIsInlineTag() { + assertThat(new JavadocTag(0, 0, "link", null).isInlineTag()).isTrue(); + assertThat(new JavadocTag(0, 0, "value", null).isInlineTag()).isTrue(); + assertThat(new JavadocTag(0, 0, "see", null).isInlineTag()).isFalse(); + + } + } diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/imports/unusedimports/InputUnusedImportsWithLinkAndMethodTag.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/imports/unusedimports/InputUnusedImportsWithLinkAndMethodTag.java new file mode 100644 index 00000000000..4b863f4652a --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/imports/unusedimports/InputUnusedImportsWithLinkAndMethodTag.java @@ -0,0 +1,54 @@ +/* +UnusedImports +processJavadoc = (default)true + + +*/ + +package com.puppycrawl.tools.checkstyle.checks.imports.unusedimports; + +import java.util.Collections; // violation 'Unused import - java.util.Collections.' +import java.util.List; +import java.util.Set; // violation 'Unused import - java.util.Set.' +import java.util.ArrayList; +import java.util.PriorityQueue; // violation 'Unused import - java.util.PriorityQueue.' +import java.time.Duration; +import java.util.Queue; // violation 'Unused import - java.util.Queue.' +import java.util.HashSet; +import java.util.TreeSet; +import java.util.Random; +import java.util.LinkedList; // violation 'Unused import - java.util.LinkedList.' +import java.net.URI; +import java.util.Collection; +import java.time.LocalDate; +import java.time.LocalDateTime; // violation 'Unused import - java.time.LocalDateTime.' +import java.time.LocalTime; +import java.time.Month; +import java.util.concurrent.TimeUnit; // violation 'Unused import - java.util.concurrent.TimeUnit.' + + +/** + * @link {Collections::emptyEnumeration} + * {@link TreeSet} + * {@see TimeUnit#SECONDS} + * {@link List#size} + * {@link Set::add} + * {@link ArrayList#add( LocalTime )}, + * {@link LinkedList#set(int index(,int element)} + * {@link Random#ints}, + * {@link PriorityQueue#123invalid} + * {@link 123invalid} + * {@link Queue# } + * {@linkplain HashSet} + * @see Duration#ZERO + * {@link #setUrl(URI)} + * {@link #Test(LocalDate, Collection)} + * {@link #Test(LocalDateTime}} + * {@link #extractParameters(double[], Month)} + * + */ +class InputUnusedImportsWithLinkAndMethodTag extends + InputUnusedImportsWithLinkAndMethodTagSuperClass { + + +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/imports/unusedimports/InputUnusedImportsWithLinkAndMethodTagSuperClass.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/imports/unusedimports/InputUnusedImportsWithLinkAndMethodTagSuperClass.java new file mode 100644 index 00000000000..15b515ec4f2 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/imports/unusedimports/InputUnusedImportsWithLinkAndMethodTagSuperClass.java @@ -0,0 +1,12 @@ +package com.puppycrawl.tools.checkstyle.checks.imports.unusedimports; + +import java.net.URI; +import java.time.LocalDate; +import java.time.Month; +import java.util.Collection; + +public class InputUnusedImportsWithLinkAndMethodTagSuperClass { + public void Test(LocalDate date, Collection s){} + public void setUrl(URI url){} + public void extractParameters(double[] d, Month month){} +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/imports/unusedimports/InputUnusedImportsWithLinkTag.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/imports/unusedimports/InputUnusedImportsWithLinkTag.java new file mode 100644 index 00000000000..6f7e0ecb46f --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/imports/unusedimports/InputUnusedImportsWithLinkTag.java @@ -0,0 +1,22 @@ +/* +UnusedImports +processJavadoc = (default)true + + +*/ + +package com.puppycrawl.tools.checkstyle.checks.imports.unusedimports; + +import java.util.List; // violation 'Unused import - java.util.List.' +import java.util.Set; +import java.util.TreeSet; // violation 'Unused import - java.util.TreeSet.' + +/** + * @link List + * {@link Set Set of items} + * @link TreeSet tree conatins items + * + */ +class InputUnusedImportsWithLinkTag { + +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/javadocmethod/InputJavadocMethodAllowInlineReturn.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/javadocmethod/InputJavadocMethodAllowInlineReturn.java new file mode 100644 index 00000000000..9b6d71d8062 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/javadocmethod/InputJavadocMethodAllowInlineReturn.java @@ -0,0 +1,41 @@ +/* +JavadocMethod +allowInlineReturn = true +allowedAnnotations = (default)Override +validateThrows = (default)false +accessModifiers = (default)public, protected, package, private +allowMissingParamTags = (default)false +allowMissingReturnTag = (default)false +tokens = (default)METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF, COMPACT_CTOR_DEF + + +*/ + +package com.puppycrawl.tools.checkstyle.checks.javadoc.javadocmethod; + +public class InputJavadocMethodAllowInlineReturn { + + /** + * {@return the foo} + */ + public int getFoo() { return 0; } + + /** + * Returns the bar + * @return the bar + */ + public int getBar() { return 0; } + + /** + * Returns the fiz + */ + public int getFiz() { return 0; } + // violation above, '@return tag should be present and have description.' + + /** + * Returns the baz + * @see "getFoo" + */ + public int getBaz() { return 0; } + // violation above, '@return tag should be present and have description.' +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/javadocmethod/InputJavadocMethodDoNotAllowInlineReturn.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/javadocmethod/InputJavadocMethodDoNotAllowInlineReturn.java new file mode 100644 index 00000000000..bd5c2a25e3d --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/javadocmethod/InputJavadocMethodDoNotAllowInlineReturn.java @@ -0,0 +1,42 @@ +/* +JavadocMethod +allowInlineReturn = (default)false +allowedAnnotations = (default)Override +validateThrows = (default)false +accessModifiers = (default)public, protected, package, private +allowMissingParamTags = (default)false +allowMissingReturnTag = (default)false +tokens = (default)METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF, COMPACT_CTOR_DEF + + +*/ + +package com.puppycrawl.tools.checkstyle.checks.javadoc.javadocmethod; + +public class InputJavadocMethodDoNotAllowInlineReturn { + + /** + * {@return the foo} + */ + public int getFoo() { return 0; } + // violation above, '@return tag should be present and have description.' + + /** + * Returns the bar + * @return the bar + */ + public int getBar() { return 0; } + + /** + * Returns the fiz + */ + public int getFiz() { return 0; } + // violation above, '@return tag should be present and have description.' + + /** + * Returns the baz + * @see "getFoo" + */ + public int getBaz() { return 0; } + // violation above, '@return tag should be present and have description.' +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/xmllogger/ExpectedXMLLoggerAddError.xml b/src/test/resources/com/puppycrawl/tools/checkstyle/xmllogger/ExpectedXMLLoggerAddError.xml new file mode 100644 index 00000000000..59855c8506b --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/xmllogger/ExpectedXMLLoggerAddError.xml @@ -0,0 +1,7 @@ + + + + + + diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/xmllogger/ExpectedXMLLoggerErrorZeroColumn.xml b/src/test/resources/com/puppycrawl/tools/checkstyle/xmllogger/ExpectedXMLLoggerErrorZeroColumn.xml index b0959a9c0dd..02a3de5870c 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/xmllogger/ExpectedXMLLoggerErrorZeroColumn.xml +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/xmllogger/ExpectedXMLLoggerErrorZeroColumn.xml @@ -1,6 +1,6 @@ - - + + diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/xmllogger/InputXMLLoggerAddError.java b/src/test/resources/com/puppycrawl/tools/checkstyle/xmllogger/InputXMLLoggerAddError.java new file mode 100644 index 00000000000..4d6cff5cf7c --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/xmllogger/InputXMLLoggerAddError.java @@ -0,0 +1,13 @@ +/*xml + + + + + + + +*/ +package com.puppycrawl.tools.checkstyle.xmllogger; + +public class InputXMLLoggerAddError { +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/xmllogger/InputXMLLoggerErrorOnZeroColumn.java b/src/test/resources/com/puppycrawl/tools/checkstyle/xmllogger/InputXMLLoggerErrorOnZeroColumn.java new file mode 100644 index 00000000000..25ae4fda316 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/xmllogger/InputXMLLoggerErrorOnZeroColumn.java @@ -0,0 +1,21 @@ +/*xml + + + + + + +*/ + +package com.puppycrawl.tools.checkstyle.xmllogger; + +/** + Test for {@link com.puppycrawl.tools.checkstyle.xmllogger} when + * the column number is 0. + *

        + * The test is to ensure that the column number is set to 0 in the XML output. + *

        + */ +public class InputXMLLoggerErrorOnZeroColumn { +} diff --git a/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/filters/SuppressionSingleFilterExamplesTest.java b/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/filters/SuppressionSingleFilterExamplesTest.java index 18a17cf3851..22a2afe27d5 100644 --- a/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/filters/SuppressionSingleFilterExamplesTest.java +++ b/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/filters/SuppressionSingleFilterExamplesTest.java @@ -19,9 +19,24 @@ package com.puppycrawl.tools.checkstyle.filters; +import static com.puppycrawl.tools.checkstyle.checks.coding.EqualsAvoidNullCheck.MSG_EQUALS_AVOID_NULL; +import static com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck.MSG_KEY; +import static com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.MSG_RETURN_EXPECTED; +import static com.puppycrawl.tools.checkstyle.checks.regexp.RegexpCheck.MSG_ILLEGAL_REGEXP; + import org.junit.jupiter.api.Test; import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport; +import com.puppycrawl.tools.checkstyle.checks.coding.EqualsAvoidNullCheck; +import com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck; +import com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck; +import com.puppycrawl.tools.checkstyle.checks.naming.ConstantNameCheck; +import com.puppycrawl.tools.checkstyle.checks.naming.MemberNameCheck; +import com.puppycrawl.tools.checkstyle.checks.naming.MethodNameCheck; +import com.puppycrawl.tools.checkstyle.checks.regexp.RegexpCheck; +import com.puppycrawl.tools.checkstyle.checks.sizes.FileLengthCheck; +import com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck; +import com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceAfterCheck; public class SuppressionSingleFilterExamplesTest extends AbstractExamplesModuleTestSupport { @Override @@ -31,91 +46,126 @@ protected String getPackageLocation() { @Test public void testExample1() throws Exception { - final String[] expected = { - + final String[] expectedWithoutFilter = { + "21:17: " + getCheckMessage(MagicNumberCheck.class, MSG_KEY, "100"), }; + final String[] expectedWithFilter = {}; - verifyWithInlineConfigParser(getPath("Example1.java"), expected); + verifyFilterWithInlineConfigParser(getPath("Example1.java"), + expectedWithoutFilter, expectedWithFilter); } @Test public void testExample2() throws Exception { - final String[] expected = { - + final String[] expectedWithoutFilter = { + "19:13: " + getCheckMessage(EqualsAvoidNullCheck.class, MSG_EQUALS_AVOID_NULL), + "25: " + getCheckMessage(JavadocMethodCheck.class, MSG_RETURN_EXPECTED), }; + final String[] expectedWithFilter = {}; - verifyWithInlineConfigParser(getPath("Example2.java"), expected); + verifyFilterWithInlineConfigParser(getPath("Example2.java"), + expectedWithoutFilter, expectedWithFilter); } @Test public void testExample3() throws Exception { - final String[] expected = { - + final String[] expectedWithoutFilter = { + "19: " + getCheckMessage(RegexpCheck.class, MSG_ILLEGAL_REGEXP, "example"), + "4: " + getCheckMessage(RegexpCheck.class, MSG_ILLEGAL_REGEXP, "example"), }; + final String[] expectedWithFilter = {}; - verifyWithInlineConfigParser(getPath("Example3.java"), expected); + verifyFilterWithInlineConfigParser(getPath("Example3.java"), + expectedWithoutFilter, expectedWithFilter); } @Test public void testExample4() throws Exception { - final String[] expected = { - + final String[] expectedWithoutFilter = { + "18:12: " + getCheckMessage(NoWhitespaceAfterCheck.class, + NoWhitespaceAfterCheck.MSG_KEY, "."), + "22:9: " + getCheckMessage(NoWhitespaceAfterCheck.class, + NoWhitespaceAfterCheck.MSG_KEY, "int"), }; + final String[] expectedWithFilter = {}; - verifyWithInlineConfigParser(getPath("Example4.java"), expected); + verifyFilterWithInlineConfigParser(getPath("Example4.java"), + expectedWithoutFilter, expectedWithFilter); } @Test public void testExample5() throws Exception { - final String[] expected = { - + final String[] expectedWithoutFilter = { + "14:15: " + getCheckMessage(MethodNameCheck.class, "name.invalidPattern", + "example_Method", "^[a-z][a-zA-Z0-9]*$"), + "17:15: " + getCheckMessage(MethodNameCheck.class, "name.invalidPattern", + "Another_Method", "^[a-z][a-zA-Z0-9]*$"), }; + final String[] expectedWithFilter = {}; - verifyWithInlineConfigParser(getPath("Example5.java"), expected); + verifyFilterWithInlineConfigParser(getPath("Example5.java"), + expectedWithoutFilter, expectedWithFilter); } @Test public void testExample6() throws Exception { - final String[] expected = { - + final String[] expectedWithoutFilter = { + "14:28: " + getCheckMessage(ConstantNameCheck.class, "name.invalidPattern", + "myConstant", "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"), }; + final String[] expectedWithFilter = {}; - verifyWithInlineConfigParser(getPath("Example6.java"), expected); + verifyFilterWithInlineConfigParser(getPath("Example6.java"), + expectedWithoutFilter, expectedWithFilter); } @Test public void testExample7() throws Exception { - final String[] expected = { - + final String[] expectedWithoutFilter = { + "15:15: " + getCheckMessage(MemberNameCheck.class, "name.invalidPattern", + "MyVariable", "^[a-z][a-zA-Z0-9]*$"), + "17:15: " + getCheckMessage(MethodNameCheck.class, "name.invalidPattern", + "MyMethod", "^[a-z][a-zA-Z0-9]*$"), }; + final String[] expectedWithFilter = {}; - verifyWithInlineConfigParser(getPath("Example7.java"), expected); + verifyFilterWithInlineConfigParser(getPath("Example7.java"), + expectedWithoutFilter, expectedWithFilter); } @Test public void testExample8() throws Exception { - final String[] expected = { - + final String[] expectedWithoutFilter = { + "18:15: " + getCheckMessage(ParameterNumberCheck.class, + ParameterNumberCheck.MSG_KEY, 5, 6), }; + final String[] expectedWithFilter = {}; - verifyWithInlineConfigParser(getPath("Example8.java"), expected); + verifyFilterWithInlineConfigParser(getPath("Example8.java"), + expectedWithoutFilter, expectedWithFilter); } @Test public void testExample9() throws Exception { - final String[] expected = { - + final String[] expectedWithoutFilter = { + "1: " + getCheckMessage(FileLengthCheck.class, + FileLengthCheck.MSG_KEY, 21, 1), }; + final String[] expectedWithFilter = {}; - verifyWithInlineConfigParser(getPath("Example9.java"), expected); + verifyFilterWithInlineConfigParser(getPath("Example9.java"), + expectedWithoutFilter, expectedWithFilter); } @Test public void testExample10() throws Exception { - final String[] expected = { - + final String[] expectedWithoutFilter = { + "16:18: " + getCheckMessage(MemberNameCheck.class, "name.invalidPattern", + "log", "^[A-Z][a-zA-Z0-9]*$"), }; + final String[] expectedWithFilter = {}; - verifyWithInlineConfigParser(getPath("Example10.java"), expected); + verifyFilterWithInlineConfigParser(getPath("Example10.java"), + expectedWithoutFilter, expectedWithFilter); } } diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/javadocmethod/Example8.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/javadocmethod/Example8.java new file mode 100644 index 00000000000..55d22601e3d --- /dev/null +++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/javadocmethod/Example8.java @@ -0,0 +1,27 @@ +/*xml + + + + + + + +*/ +package com.puppycrawl.tools.checkstyle.checks.javadoc.javadocmethod; + +// xdoc section -- start +public class Example8 { + + /** + * {@return the foo} + */ + public int getFoo() { return 0; } + + /** + * Returns the bar + * @return the bar + */ + public int getBar() { return 0; } + +} +// xdoc section -- end diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example1.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example1.java index b59829cb5ff..620f50bff66 100644 --- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example1.java +++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example1.java @@ -5,12 +5,7 @@ - - - - - - + @@ -23,8 +18,7 @@ // xdoc section -- start public class Example1 { public void exampleMethod() { - int value = 100; - // filtered violation ''100' is a magic number' + int value = 100; // filtered violation ''100' is a magic number' } } // xdoc section -- end diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example10.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example10.java index 0002c8296c5..23831a22f43 100644 --- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example10.java +++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example10.java @@ -12,8 +12,7 @@ package com.puppycrawl.tools.checkstyle.filters.suppressionsinglefilter; // xdoc section -- start public class Example10 { - - // filtered violation 'Name 'log' must match pattern' + // filtered violation below 'Name 'log' must match pattern' private String log = "Some log message"; } diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example2.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example2.java index 635ef6cb38c..1ba74a6beab 100644 --- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example2.java +++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example2.java @@ -1,11 +1,12 @@ /*xml - - + + + + - - + */ @@ -13,9 +14,14 @@ // xdoc section -- start public class Example2 { - public void checkStringEquality(String str1, String str2) { - // filtered violation ''.equals()' should be used for string comparison' - assert str1 == str2 ; + public void checkStringEquality(String s) { + // filtered violation below 'String literal expressions should be on the left' + s.equals("M"); } + /** + * @param p1 The first number + */ + // filtered violation below '@return tag should be present' + private int m2(int p1) { return p1; } } // xdoc section -- end diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example3.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example3.java index c92a9ef3916..41d0bbbf934 100644 --- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example3.java +++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example3.java @@ -1,7 +1,7 @@ /*xml - + @@ -10,19 +10,19 @@ */ package com.puppycrawl.tools.checkstyle.filters.suppressionsinglefilter; +// filtered violation 10 lines above 'Line matches the illegal pattern' // xdoc section -- start public class Example3 { public void printExample() { - // filtered violation 'Line matches the illegal pattern 'example'' System.out.println( - "This is an example string." + "example" // filtered violation 'Line matches the illegal pattern 'example'' ); } public void noViolation() { System.out.println( - "This string does not contain 'example'." + "RegexpSingleline is case sensitive by default. 'Example' in not matching." ); } diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example4.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example4.java index abf019564a6..f59f03ede8d 100644 --- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example4.java +++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example4.java @@ -1,6 +1,8 @@ /*xml - + + + @@ -11,12 +13,13 @@ // xdoc section -- start public class Example4 { - // filtered violation 'WhiteSpace after ','' public void exampleMethod(int a, int b) { + // filtered violation below ''.' is followed by whitespace' + Integer. parseInt("3"); } public void exampleMethod2() { - int x = 5 ; // filtered violation 'WhiteSpace before ';'' + int [] x; // filtered violation ''int' is followed by whitespace' } } diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example5.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example5.java index 77b83946c3f..48bfd3bc1c5 100644 --- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example5.java +++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example5.java @@ -10,11 +10,10 @@ package com.puppycrawl.tools.checkstyle.filters.suppressionsinglefilter; // xdoc section -- start public class Example5 { - // filtered violation 'Name 'example_Method' must match pattern' + // filtered violation below 'Name 'example_Method' must match pattern' public void example_Method() { } - - // filtered violation Name 'Another_Method' must match pattern + // filtered violation below 'Name 'Another_Method' must match pattern' public void Another_Method() { } } diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example6.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example6.java index 65b1c337552..f26d505a1c1 100644 --- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example6.java +++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example6.java @@ -10,8 +10,7 @@ package com.puppycrawl.tools.checkstyle.filters.suppressionsinglefilter; // xdoc section -- start public class Example6 { - - // filtered violation 'Name 'myConstant' must match pattern' + // filtered violation below 'Name 'myConstant' must match pattern' private static final int myConstant = 42; } diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example7.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example7.java index 375b6ab48ec..a9416b98e63 100644 --- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example7.java +++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example7.java @@ -1,24 +1,20 @@ /*xml + - + */ package com.puppycrawl.tools.checkstyle.filters.suppressionsinglefilter; // xdoc section -- start public class Example7 { - - // filtered violation 'Name 'MyVariable' must match pattern' + // filtered violation below 'Name 'MyVariable' must match pattern' private int MyVariable = 5; - - // filtered violation 'Name 'PrintHello' must match pattern' - public void PrintHello() { - } - - public void printHello() { + // filtered violation below 'Name 'MyMethod' must match pattern' + public void MyMethod() { } } // xdoc section -- end diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example8.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example8.java index c629caa20b3..0692a7b2d0d 100644 --- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example8.java +++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example8.java @@ -14,10 +14,9 @@ package com.puppycrawl.tools.checkstyle.filters.suppressionsinglefilter; // xdoc section -- start public class Example8 { - // filtered violation 'more than 5 parameters' + // filtered violation below 'More than 5 parameters (found 6)' public void exampleMethod( - int param1, int param2, int param3, int param4, - int param5 + int param1, int param2, int param3, int param4, int param5, int param6 ) {} } // xdoc section -- end diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example9.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example9.java index 6c08d4f695c..5022369d15c 100644 --- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example9.java +++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter/Example9.java @@ -12,8 +12,10 @@ */ package com.puppycrawl.tools.checkstyle.filters.suppressionsinglefilter; +// filtered violation 15 lines above 'File length is 21 lines (max allowed is 1)' // xdoc section -- start +/* filtered violation on 1st line 'File length is 4 lines (max allowed is 1)' */ public class Example9 { - //filtered violation 'File length is 19 lines (max allowed is 1)' + } // xdoc section -- end