diff --git a/src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionParameterNumberTest.java b/src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionParameterNumberTest.java index 365be83b633..b0d15ffc11b 100644 --- a/src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionParameterNumberTest.java +++ b/src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionParameterNumberTest.java @@ -103,4 +103,30 @@ public void testIgnoreOverriddenMethods() throws Exception { runVerifications(moduleConfig, fileToProcess, expectedViolations, expectedXpathQueries); } + @Test + public void testIgnoreAnnotatedBy() throws Exception { + final String filePath = + getPath("SuppressionXpathRegressionParameterNumberIgnoreAnnotatedBy.java"); + final File fileToProcess = new File(filePath); + + final DefaultConfiguration moduleConfig = createModuleConfig(ParameterNumberCheck.class); + moduleConfig.addProperty("ignoreAnnotatedBy", "MyAnno"); + moduleConfig.addProperty("max", "2"); + + final String[] expectedViolations = { + "15:34: " + getCheckMessage(ParameterNumberCheck.class, MSG_KEY, 2, 3), + }; + + final List expectedXpathQueries = Collections.singletonList( + "/COMPILATION_UNIT/CLASS_DEF" + + "[./IDENT[@text='SuppressionXpathRegressionParameterNumberIgnoreAnnotatedBy']]" + + "/OBJBLOCK/CLASS_DEF[./IDENT[@text='InnerClass']]" + + "/OBJBLOCK/STATIC_INIT/SLIST/EXPR/LITERAL_NEW[./IDENT[@text='Object']]" + + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='method']]" + + "/SLIST/LITERAL_IF/SLIST/EXPR/LITERAL_NEW[./IDENT[@text='Object']]" + + "/OBJBLOCK/METHOD_DEF/IDENT[@text='checkedMethod']" + ); + + runVerifications(moduleConfig, fileToProcess, expectedViolations, expectedXpathQueries); + } } diff --git a/src/it/resources/org/checkstyle/suppressionxpathfilter/parameternumber/SuppressionXpathRegressionParameterNumberIgnoreAnnotatedBy.java b/src/it/resources/org/checkstyle/suppressionxpathfilter/parameternumber/SuppressionXpathRegressionParameterNumberIgnoreAnnotatedBy.java new file mode 100644 index 00000000000..984da4cb800 --- /dev/null +++ b/src/it/resources/org/checkstyle/suppressionxpathfilter/parameternumber/SuppressionXpathRegressionParameterNumberIgnoreAnnotatedBy.java @@ -0,0 +1,26 @@ +package org.checkstyle.suppressionxpathfilter.parameternumber; + +public class SuppressionXpathRegressionParameterNumberIgnoreAnnotatedBy { + static class InnerClass { + static { + new Object() { + void method() { + if (true) { + new Object() { + @MyAnno + void ignoredMethod(int a, @MyAnno int b, int c) { + + } + + void checkedMethod(int a, @MyAnno int b, int c) { // warn + + } + }; + } + } + }; + } + } + + @interface MyAnno {} +} diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/sizes/ParameterNumberCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/sizes/ParameterNumberCheck.java index c281efdd64b..e4a3fe16dc9 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/sizes/ParameterNumberCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/sizes/ParameterNumberCheck.java @@ -19,6 +19,9 @@ package com.puppycrawl.tools.checkstyle.checks.sizes; +import java.util.Collections; +import java.util.Set; + import com.puppycrawl.tools.checkstyle.StatelessCheck; import com.puppycrawl.tools.checkstyle.api.AbstractCheck; import com.puppycrawl.tools.checkstyle.api.DetailAST; @@ -32,6 +35,12 @@ *

*