diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/naming/ParameterNameCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/naming/ParameterNameCheck.java index 20527fa7e..b5cf4a753 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/naming/ParameterNameCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/naming/ParameterNameCheck.java @@ -30,11 +30,9 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes; * and defaults to * ^[a-z][a-zA-Z0-9]*$. *

- *

The check has the following options:

+ *

The check has the following option:

*

ignoreOverridden - allows to skip methods with Override annotation from - * validation. Default value is false .

- *

skipCatchParameter - allows to skip catcj parameter from validation. Default value - * is true .

+ * validation. Default values is false .

*

* An example of how to configure the check is: *

@@ -59,14 +57,6 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes; * <property name="ignoreOverridden" value="true"/> * </module> * - *

- * An example of how to configure the check to skip catch parameter from validation: - *

- *
- * <module name="ParameterName">
- *    <property name="skipCatchParameter" value="true"/>
- * </module>
- * 
* * @author Oliver Burn * @author Andrei Selkin @@ -79,11 +69,6 @@ public class ParameterNameCheck */ private boolean ignoreOverridden; - /** - * Allows to skip catch parameter from validation. - */ - private boolean skipCatchParameter = true; - /** * Creates a new {@code ParameterNameCheck} instance. */ @@ -100,14 +85,6 @@ public class ParameterNameCheck this.ignoreOverridden = ignoreOverridden; } - /** - * Sets whether to skip catch parameter from validation. - * @param skipCatchParameter Flag for skipping catch parameter. - */ - public void setSkipCatchParameter(boolean skipCatchParameter) { - this.skipCatchParameter = skipCatchParameter; - } - @Override public int[] getDefaultTokens() { return getAcceptableTokens(); @@ -127,7 +104,7 @@ public class ParameterNameCheck protected boolean mustCheckName(DetailAST ast) { boolean checkName = true; if (ignoreOverridden && isOverriddenMethod(ast) - || skipCatchParameter && ast.getParent().getType() == TokenTypes.LITERAL_CATCH) { + || ast.getParent().getType() == TokenTypes.LITERAL_CATCH) { checkName = false; } return checkName; diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/ParameterNameCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/ParameterNameCheckTest.java index 0d0fe084b..1c35fd32e 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/ParameterNameCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/ParameterNameCheckTest.java @@ -137,132 +137,4 @@ public class ParameterNameCheckTest }; verify(checkConfig, getPath("InputOverrideAnnotation.java"), expected); } - - @Test - public void testSkipCatchParameterTrue() - throws Exception { - final DefaultConfiguration checkConfig = - createCheckConfig(ParameterNameCheck.class); - checkConfig.addAttribute("format", "^h$"); - checkConfig.addAttribute("skipCatchParameter", "true"); - - final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY; - - verify(checkConfig, getPath("InputCatchParameter.java"), expected); - } - - @Test - public void testSkipCatchParameterFalse() - throws Exception { - final DefaultConfiguration checkConfig = - createCheckConfig(ParameterNameCheck.class); - checkConfig.addAttribute("format", "^h$"); - checkConfig.addAttribute("skipCatchParameter", "false"); - final String pattern = "^h$"; - - final String[] expected = { - "13:26: " + getCheckMessage(MSG_INVALID_PATTERN, "ex", pattern), - "22:64: " + getCheckMessage(MSG_INVALID_PATTERN, "ex", pattern), - }; - - verify(checkConfig, getPath("InputCatchParameter.java"), expected); - } - - @Test - public void testSkipCatchParameterTrueAndIgnoreOverriddenTrue() - throws Exception { - final DefaultConfiguration checkConfig = - createCheckConfig(ParameterNameCheck.class); - checkConfig.addAttribute("format", "^h$"); - checkConfig.addAttribute("skipCatchParameter", "true"); - checkConfig.addAttribute("ignoreOverridden", "true"); - final String pattern = "^h$"; - - final String[] expected = { - "13:29: " + getCheckMessage(MSG_INVALID_PATTERN, "object", pattern), - "17:30: " + getCheckMessage(MSG_INVALID_PATTERN, "aaaa", pattern), - "21:19: " + getCheckMessage(MSG_INVALID_PATTERN, "abc", pattern), - "21:28: " + getCheckMessage(MSG_INVALID_PATTERN, "bd", pattern), - "23:18: " + getCheckMessage(MSG_INVALID_PATTERN, "abc", pattern), - "30:43: " + getCheckMessage(MSG_INVALID_PATTERN, "field", pattern), - "30:62: " + getCheckMessage(MSG_INVALID_PATTERN, "packageNames", pattern), - }; - - verify(checkConfig, getPath("InputParameterNameMultipleOptions.java"), expected); - } - - @Test - public void testSkipCatchParameterFalseAndIgnoreOverriddenFalse() - throws Exception { - final DefaultConfiguration checkConfig = - createCheckConfig(ParameterNameCheck.class); - checkConfig.addAttribute("format", "^h$"); - checkConfig.addAttribute("skipCatchParameter", "false"); - checkConfig.addAttribute("ignoreOverridden", "false"); - final String pattern = "^h$"; - - final String[] expected = { - "8:34: " + getCheckMessage(MSG_INVALID_PATTERN, "o", pattern), - "13:29: " + getCheckMessage(MSG_INVALID_PATTERN, "object", pattern), - "17:30: " + getCheckMessage(MSG_INVALID_PATTERN, "aaaa", pattern), - "21:19: " + getCheckMessage(MSG_INVALID_PATTERN, "abc", pattern), - "21:28: " + getCheckMessage(MSG_INVALID_PATTERN, "bd", pattern), - "23:18: " + getCheckMessage(MSG_INVALID_PATTERN, "abc", pattern), - "30:43: " + getCheckMessage(MSG_INVALID_PATTERN, "field", pattern), - "30:62: " + getCheckMessage(MSG_INVALID_PATTERN, "packageNames", pattern), - "36:26: " + getCheckMessage(MSG_INVALID_PATTERN, "ex", pattern), - "45:64: " + getCheckMessage(MSG_INVALID_PATTERN, "ex", pattern), - }; - - verify(checkConfig, getPath("InputParameterNameMultipleOptions.java"), expected); - } - - @Test - public void testSkipCatchParameterTrueAndIgnoreOverriddenFalse() - throws Exception { - final DefaultConfiguration checkConfig = - createCheckConfig(ParameterNameCheck.class); - checkConfig.addAttribute("format", "^h$"); - checkConfig.addAttribute("skipCatchParameter", "true"); - checkConfig.addAttribute("ignoreOverridden", "false"); - final String pattern = "^h$"; - - final String[] expected = { - "8:34: " + getCheckMessage(MSG_INVALID_PATTERN, "o", pattern), - "13:29: " + getCheckMessage(MSG_INVALID_PATTERN, "object", pattern), - "17:30: " + getCheckMessage(MSG_INVALID_PATTERN, "aaaa", pattern), - "21:19: " + getCheckMessage(MSG_INVALID_PATTERN, "abc", pattern), - "21:28: " + getCheckMessage(MSG_INVALID_PATTERN, "bd", pattern), - "23:18: " + getCheckMessage(MSG_INVALID_PATTERN, "abc", pattern), - "30:43: " + getCheckMessage(MSG_INVALID_PATTERN, "field", pattern), - "30:62: " + getCheckMessage(MSG_INVALID_PATTERN, "packageNames", pattern), - }; - - verify(checkConfig, getPath("InputParameterNameMultipleOptions.java"), expected); - } - - @Test - public void testSkipCatchParameterFalseAndIgnoreOverriddenTrue() - throws Exception { - final DefaultConfiguration checkConfig = - createCheckConfig(ParameterNameCheck.class); - checkConfig.addAttribute("format", "^h$"); - checkConfig.addAttribute("skipCatchParameter", "false"); - checkConfig.addAttribute("ignoreOverridden", "true"); - final String pattern = "^h$"; - - final String[] expected = { - "13:29: " + getCheckMessage(MSG_INVALID_PATTERN, "object", pattern), - "17:30: " + getCheckMessage(MSG_INVALID_PATTERN, "aaaa", pattern), - "21:19: " + getCheckMessage(MSG_INVALID_PATTERN, "abc", pattern), - "21:28: " + getCheckMessage(MSG_INVALID_PATTERN, "bd", pattern), - "23:18: " + getCheckMessage(MSG_INVALID_PATTERN, "abc", pattern), - "30:43: " + getCheckMessage(MSG_INVALID_PATTERN, "field", pattern), - "30:62: " + getCheckMessage(MSG_INVALID_PATTERN, "packageNames", pattern), - "36:26: " + getCheckMessage(MSG_INVALID_PATTERN, "ex", pattern), - "45:64: " + getCheckMessage(MSG_INVALID_PATTERN, "ex", pattern), - }; - - verify(checkConfig, getPath("InputParameterNameMultipleOptions.java"), expected); - } } diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputCatchParameter.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputCatchParameter.java deleted file mode 100644 index 47388bef2..000000000 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputCatchParameter.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.puppycrawl.tools.checkstyle.checks.naming; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.sql.SQLException; - -public class InputCatchParameter { - - void foo1() { - try { - - } - catch (Exception ex) { - - } - } - - void foo2() { - try { - - } - catch (NullPointerException | IllegalArgumentException ex) { - // just to check how the ParentName's option 'skipCahcthParameter' deals with catching - // multiple exception types and - } - } -} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputOverrideAnnotation.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputOverrideAnnotation.java index 608b3a5c1..e4e40d126 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputOverrideAnnotation.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputOverrideAnnotation.java @@ -26,4 +26,6 @@ public class InputOverrideAnnotation { InputOverrideAnnotation() {} // No NPE here! InputOverrideAnnotation(int field, java.util.Set packageNames) {} // No NPE here! + + } diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputParameterNameMultipleOptions.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputParameterNameMultipleOptions.java deleted file mode 100644 index f42bd2125..000000000 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputParameterNameMultipleOptions.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.puppycrawl.tools.checkstyle.checks.naming; - -import java.util.Set; - -public class InputParameterNameMultipleOptions { - - @Override - public boolean equals(Object o) { - return super.equals(o); - } - - @SuppressWarnings("") - public void foo1(Object object) { - - } - - public void foo2(Integer aaaa) {} - - void foo3() {} // No NPE here! - - void foo4(int abc, int bd) {} // No NPE here! - - int foo5(int abc) {return 1;} // No NPE here! - - private int field; - private Set packageNames; - - InputParameterNameMultipleOptions() {} // No NPE here! - - InputParameterNameMultipleOptions(int field, Set packageNames) {} // No NPE here! - - void foo6() { - try { - - } - catch (Exception ex) { - - } - } - - void foo7() { - try { - - } - catch (NullPointerException | IllegalArgumentException ex) { - // just to check how the ParentName's option 'skipCahcthParameter' deals with catching - // multiple exception types and - } - } -} diff --git a/src/xdocs/config_naming.xml b/src/xdocs/config_naming.xml index f84615a02..03867b6e0 100644 --- a/src/xdocs/config_naming.xml +++ b/src/xdocs/config_naming.xml @@ -950,24 +950,6 @@ public boolean equals(Object o) { Boolean false - - skipCatchParameter - - Allows to skip catch parameter from validation. For example, the - following catch parameter will be skipped from validation, if - skipCatchParameter is true: -
-try {
-  ...
-}
-catch (Exception ex) {
-  ...
-}
-              
- - Boolean - true - @@ -987,14 +969,6 @@ catch (Exception ex) { <property name="ignoreOverridden" value="true"/> </module> -

- An example of how to configure the check to skip catch parameter from validation: -

- -<module name="ParameterName"> - <property name="skipCatchParameter" value="true"/> -</module> -