Skip to content

Commit

Permalink
Issue #2451: removed excess hierarchy from IllegalTypeCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach authored and mkordas committed Oct 31, 2015
1 parent aa89a8a commit 91a49a9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion config/suppressions.xml
Expand Up @@ -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="321"/>
<suppress checks="CyclomaticComplexity" files="[\\/]XDocsPagesTest\.java" lines="320"/>
<suppress checks="EmptyBlock" files=".*[\\/]src[\\/]test[\\/]"/>
<suppress checks="ImportControl" files=".*[\\/]src[\\/](test|it)[\\/]"/>
<suppress checks="Javadoc" files=".*[\\/]src[\\/](test|it)[\\/]"/>
Expand Down
Expand Up @@ -23,13 +23,15 @@
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;

import com.google.common.collect.Sets;
import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.FullIdent;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.checks.AbstractFormatCheck;
import com.puppycrawl.tools.checkstyle.utils.CheckUtils;
import com.puppycrawl.tools.checkstyle.utils.CommonUtils;
import com.puppycrawl.tools.checkstyle.utils.TokenUtils;

/**
Expand Down Expand Up @@ -89,16 +91,14 @@
* @author <a href="mailto:nesterenko-aleksey@list.ru">Aleksey Nesterenko</a>
* @author <a href="mailto:andreyselkin@gmail.com">Andrei Selkin</a>
*/
public final class IllegalTypeCheck extends AbstractFormatCheck {
public final class IllegalTypeCheck extends Check {

/**
* A key is pointing to the warning message text in "messages.properties"
* file.
*/
public static final String MSG_KEY = "illegal.type";

/** Default value of pattern for illegal class name. */
private static final String DEFAULT_FORMAT = "^(.*[\\.])?Abstract.*$";
/** Abstract classes legal by default. */
private static final String[] DEFAULT_LEGAL_ABSTRACT_NAMES = {};
/** Types illegal by default. */
Expand Down Expand Up @@ -132,19 +132,34 @@ public final class IllegalTypeCheck extends AbstractFormatCheck {
/** Check methods and fields with only corresponding modifiers. */
private List<Integer> memberModifiers;

/** The format string of the regexp. */
private String format = "^(.*[\\.])?Abstract.*$";

/** The regexp to match against. */
private Pattern regexp = Pattern.compile(format);

/**
* Controls whether to validate abstract class names.
*/
private boolean validateAbstractClassNames;

/** Creates new instance of the check. */
public IllegalTypeCheck() {
super(DEFAULT_FORMAT);
setIllegalClassNames(DEFAULT_ILLEGAL_TYPES);
setLegalAbstractClassNames(DEFAULT_LEGAL_ABSTRACT_NAMES);
setIgnoredMethodNames(DEFAULT_IGNORED_METHOD_NAMES);
}

/**
* 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);
}

/**
* Sets whether to validate abstract class names.
* @param validateAbstractClassNames whether abstract class names must be ignored.
Expand Down Expand Up @@ -325,7 +340,7 @@ private boolean isMatchingClassName(String className) {
|| illegalClassNames.contains(shortName)
|| validateAbstractClassNames
&& !legalAbstractClassNames.contains(className)
&& getRegexp().matcher(className).find();
&& regexp.matcher(className).find();
}

/**
Expand Down
Expand Up @@ -112,7 +112,6 @@ public class XDocsPagesTest {
"SuppressWithNearbyCommentFilter.fileContents",
"IllegalTokenTextCheck.compileFlags",
"ReturnCountCheck.compileFlags",
"IllegalTypeCheck.compileFlags",
"MutableExceptionCheck.compileFlags",
"AbstractClassNameCheck.compileFlags",
"ClassTypeParameterNameCheck.compileFlags",
Expand Down

0 comments on commit 91a49a9

Please sign in to comment.