aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrnveach <rveach02@gmail.com>2015-11-01 10:02:06 -0500
committerRoman Ivanov <ivanov-jr@mail.ru>2015-11-04 08:42:59 -0800
commitf4d416e749e743a0c559c43460094e1cfb761a22 (patch)
tree38eec1b82237562b0464cfe0b507114be29ec320 /src
parent181c2b0600991da6a512071c968a59f36e616074 (diff)
downloadcheckstyle-f4d416e749e743a0c559c43460094e1cfb761a22.tar.gz
Issue #2451: removed excess hierarchy from IllegalThrowsCheck
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalThrowsCheck.java38
1 files changed, 25 insertions, 13 deletions
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalThrowsCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalThrowsCheck.java
index 792f19ae5..aa65ba0e9 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalThrowsCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalThrowsCheck.java
@@ -23,6 +23,7 @@ import java.util.Collections;
import java.util.Set;
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;
@@ -49,7 +50,7 @@ import com.puppycrawl.tools.checkstyle.utils.AnnotationUtility;
* @author John Sirois
* @author <a href="mailto:nesterenko-aleksey@list.ru">Aleksey Nesterenko</a>
*/
-public final class IllegalThrowsCheck extends AbstractIllegalCheck {
+public final class IllegalThrowsCheck extends Check {
/**
* A key is pointing to the warning message text in "messages.properties"
@@ -57,22 +58,33 @@ public final class IllegalThrowsCheck extends AbstractIllegalCheck {
*/
public static final String MSG_KEY = "illegal.throw";
- /** Default ignored method names. */
- private static final String[] DEFAULT_IGNORED_METHOD_NAMES = {
- "finalize",
- };
-
/** Property for ignoring overridden methods. */
private boolean ignoreOverriddenMethods = true;
/** Methods which should be ignored. */
- private final Set<String> ignoredMethodNames = Sets.newHashSet();
+ private final Set<String> ignoredMethodNames = Sets.newHashSet("finalize");
+
+ /** Illegal class names. */
+ private final Set<String> illegalClassNames = Sets.newHashSet("Error", "RuntimeException",
+ "Throwable", "java.lang.Error", "java.lang.RuntimeException", "java.lang.Throwable");
- /** Creates new instance of the check. */
- public IllegalThrowsCheck() {
- super("Error", "RuntimeException", "Throwable", "java.lang.Error",
- "java.lang.RuntimeException", "java.lang.Throwable");
- setIgnoredMethodNames(DEFAULT_IGNORED_METHOD_NAMES);
+ /**
+ * Set the list of illegal classes.
+ *
+ * @param classNames
+ * array of illegal exception classes
+ */
+ public void setIllegalClassNames(final String... classNames) {
+ illegalClassNames.clear();
+ for (final String name : classNames) {
+ illegalClassNames.add(name);
+ final int lastDot = name.lastIndexOf('.');
+ if (lastDot > 0 && lastDot < name.length() - 1) {
+ final String shortName = name
+ .substring(name.lastIndexOf('.') + 1);
+ illegalClassNames.add(shortName);
+ }
+ }
}
@Override
@@ -99,7 +111,7 @@ public final class IllegalThrowsCheck extends AbstractIllegalCheck {
while (token != null) {
if (token.getType() != TokenTypes.COMMA) {
final FullIdent ident = FullIdent.createFullIdent(token);
- if (isIllegalClassName(ident.getText())) {
+ if (illegalClassNames.contains(ident.getText())) {
log(token, MSG_KEY, ident.getText());
}
}