Issue #2451: removed excess hierarchy from MutableExceptionCheck

This commit is contained in:
rnveach 2015-10-31 10:33:12 -04:00 committed by Roman Ivanov
parent d34fe20b92
commit 3514294e65
3 changed files with 21 additions and 12 deletions

View File

@ -37,7 +37,7 @@
files="AbstractClassNameCheckTest.java|AbstractTypeAwareCheckTest.java|AbstractJavadocCheckTest.java|AbstractViolationReporterTest.java"/>
<!-- Tone down the checking for test code -->
<suppress checks="CyclomaticComplexity" files="[\\/]XDocsPagesTest\.java" lines="319"/>
<suppress checks="CyclomaticComplexity" files="[\\/]XDocsPagesTest\.java" lines="318"/>
<suppress checks="EmptyBlock" files=".*[\\/]src[\\/]test[\\/]"/>
<suppress checks="ImportControl" files=".*[\\/]src[\\/](test|it)[\\/]"/>
<suppress checks="Javadoc" files=".*[\\/]src[\\/](test|it)[\\/]"/>

View File

@ -21,10 +21,12 @@ package com.puppycrawl.tools.checkstyle.checks.design;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.regex.Pattern;
import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.checks.AbstractFormatCheck;
import com.puppycrawl.tools.checkstyle.utils.CommonUtils;
/**
* <p> Ensures that exceptions (classes with names conforming to some regular
@ -39,7 +41,7 @@ import com.puppycrawl.tools.checkstyle.checks.AbstractFormatCheck;
*
* @author <a href="mailto:simon@redhillconsulting.com.au">Simon Harris</a>
*/
public final class MutableExceptionCheck extends AbstractFormatCheck {
public final class MutableExceptionCheck extends Check {
/**
* A key is pointing to the warning message text in "messages.properties"
@ -50,17 +52,15 @@ public final class MutableExceptionCheck extends AbstractFormatCheck {
/** Default value for format and extendedClassNameFormat properties. */
private static final String DEFAULT_FORMAT = "^.*Exception$|^.*Error$|^.*Throwable$";
/** Pattern for class name that is being extended. */
private String extendedClassNameFormat;
private String extendedClassNameFormat = DEFAULT_FORMAT;
/** Stack of checking information for classes. */
private final Deque<Boolean> checkingStack = new ArrayDeque<>();
/** Should we check current class or not. */
private boolean checking;
/** Creates new instance of the check. */
public MutableExceptionCheck() {
super(DEFAULT_FORMAT);
extendedClassNameFormat = DEFAULT_FORMAT;
}
/** The format string of the regexp. */
private String format = DEFAULT_FORMAT;
/** The regexp to match against. */
private Pattern regexp = Pattern.compile(format);
/**
* Sets the format of extended class name to the specified regular expression.
@ -70,6 +70,16 @@ public final class MutableExceptionCheck extends AbstractFormatCheck {
this.extendedClassNameFormat = extendedClassNameFormat;
}
/**
* Set the format to the specified regular expression.
* @param format a {@code String} value
* @throws org.apache.commons.beanutils.ConversionException unable to parse format
*/
public void setFormat(String format) {
this.format = format;
regexp = CommonUtils.createPattern(format);
}
@Override
public int[] getDefaultTokens() {
return new int[] {TokenTypes.CLASS_DEF, TokenTypes.VARIABLE_DEF};
@ -143,7 +153,7 @@ public final class MutableExceptionCheck extends AbstractFormatCheck {
*/
private boolean isNamedAsException(DetailAST ast) {
final String className = ast.findFirstToken(TokenTypes.IDENT).getText();
return getRegexp().matcher(className).find();
return regexp.matcher(className).find();
}
/**

View File

@ -111,7 +111,6 @@ public class XDocsPagesTest {
private static final List<String> UNDOCUMENTED_PROPERTIES = Arrays.asList(
"SuppressWithNearbyCommentFilter.fileContents",
"IllegalTokenTextCheck.compileFlags",
"MutableExceptionCheck.compileFlags",
"AbstractClassNameCheck.compileFlags",
"ClassTypeParameterNameCheck.compileFlags",
"ConstantNameCheck.compileFlags",