Revert "Issue #2290: Add 'skipCatchParameter' to skip catch parameter from validation"
This reverts commit 176301250b.
This commit is contained in:
parent
0975fb750b
commit
c324b05dfd
|
|
@ -30,11 +30,9 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
|||
* and defaults to
|
||||
* <strong>^[a-z][a-zA-Z0-9]*$</strong>.
|
||||
* </p>
|
||||
* <p>The check has the following options:</p>
|
||||
* <p>The check has the following option:</p>
|
||||
* <p><b>ignoreOverridden</b> - allows to skip methods with Override annotation from
|
||||
* validation. Default value is <b>false</b> .</p>
|
||||
* <p><b>skipCatchParameter</b> - allows to skip catcj parameter from validation. Default value
|
||||
* is <b>true</b> .</p>
|
||||
* validation. Default values is <b>false</b> .</p>
|
||||
* <p>
|
||||
* An example of how to configure the check is:
|
||||
* </p>
|
||||
|
|
@ -59,14 +57,6 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
|||
* <property name="ignoreOverridden" value="true"/>
|
||||
* </module>
|
||||
* </pre>
|
||||
* <p>
|
||||
* An example of how to configure the check to skip catch parameter from validation:
|
||||
* </p>
|
||||
* <pre>
|
||||
* <module name="ParameterName">
|
||||
* <property name="skipCatchParameter" value="true"/>
|
||||
* </module>
|
||||
* </pre>
|
||||
*
|
||||
* @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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -26,4 +26,6 @@ public class InputOverrideAnnotation {
|
|||
InputOverrideAnnotation() {} // No NPE here!
|
||||
|
||||
InputOverrideAnnotation(int field, java.util.Set<String> packageNames) {} // No NPE here!
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<String> packageNames;
|
||||
|
||||
InputParameterNameMultipleOptions() {} // No NPE here!
|
||||
|
||||
InputParameterNameMultipleOptions(int field, Set<String> 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -950,24 +950,6 @@ public boolean equals(Object o) {
|
|||
<td><a href="property_types.html#boolean">Boolean</a></td>
|
||||
<td><code>false</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>skipCatchParameter</td>
|
||||
<td>
|
||||
Allows to skip <code>catch</code> parameter from validation. For example, the
|
||||
following catch parameter will be skipped from validation, if
|
||||
skipCatchParameter is true:
|
||||
<pre>
|
||||
try {
|
||||
...
|
||||
}
|
||||
catch (Exception ex) {
|
||||
...
|
||||
}
|
||||
</pre>
|
||||
</td>
|
||||
<td><a href="property_types.html#boolean">Boolean</a></td>
|
||||
<td><code>true</code></td>
|
||||
</tr>
|
||||
</table>
|
||||
</subsection>
|
||||
|
||||
|
|
@ -987,14 +969,6 @@ catch (Exception ex) {
|
|||
<property name="ignoreOverridden" value="true"/>
|
||||
</module>
|
||||
</source>
|
||||
<p>
|
||||
An example of how to configure the check to skip catch parameter from validation:
|
||||
</p>
|
||||
<source>
|
||||
<module name="ParameterName">
|
||||
<property name="skipCatchParameter" value="true"/>
|
||||
</module>
|
||||
</source>
|
||||
</subsection>
|
||||
|
||||
<subsection name="Example of Usage">
|
||||
|
|
|
|||
Loading…
Reference in New Issue