aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrnveach <rveach02@gmail.com>2015-10-31 11:19:14 -0400
committerRoman Ivanov <ivanov-jr@mail.ru>2015-11-04 13:42:15 -0800
commita619bc13918d23861116ec46dd858aa69d698498 (patch)
tree80143c301f8095b33c3f9f8b1de2edef5de7acec /src
parentb7f5b3fbed8e2906f8abd72c1a602bea03ac2157 (diff)
downloadcheckstyle-a619bc13918d23861116ec46dd858aa69d698498.tar.gz
Issue #2451: removed excess hierarchy from IllegalTokenTextCheck
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTokenTextCheck.java49
-rw-r--r--src/test/java/com/puppycrawl/tools/checkstyle/XDocsPagesTest.java1
2 files changed, 37 insertions, 13 deletions
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTokenTextCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTokenTextCheck.java
index aab5cb0d0..2c959d4ca 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTokenTextCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTokenTextCheck.java
@@ -23,8 +23,9 @@ import java.util.regex.Pattern;
import org.apache.commons.lang3.ArrayUtils;
+import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
-import com.puppycrawl.tools.checkstyle.checks.AbstractFormatCheck;
+import com.puppycrawl.tools.checkstyle.utils.CommonUtils;
import com.puppycrawl.tools.checkstyle.utils.TokenUtils;
/**
@@ -53,7 +54,7 @@ import com.puppycrawl.tools.checkstyle.utils.TokenUtils;
* @author Rick Giles
*/
public class IllegalTokenTextCheck
- extends AbstractFormatCheck {
+ extends Check {
/**
* A key is pointing to the warning message text in "messages.properties"
@@ -67,13 +68,14 @@ public class IllegalTokenTextCheck
*/
private String message = "";
- /**
- * Instantiates a new instance.
- */
- public IllegalTokenTextCheck() {
- // the empty language
- super("$^");
- }
+ /** The format string of the regexp. */
+ private String format = "$^";
+
+ /** The regexp to match against. */
+ private Pattern regexp = Pattern.compile(format);
+
+ /** The flags to use with the regexp. */
+ private int compileFlags;
@Override
public int[] getDefaultTokens() {
@@ -93,7 +95,7 @@ public class IllegalTokenTextCheck
@Override
public void visitToken(DetailAST ast) {
final String text = ast.getText();
- if (getRegexp().matcher(text).find()) {
+ if (regexp.matcher(text).find()) {
String customMessage = message;
if (customMessage.isEmpty()) {
customMessage = MSG_KEY;
@@ -102,7 +104,7 @@ public class IllegalTokenTextCheck
ast.getLineNo(),
ast.getColumnNo(),
customMessage,
- getFormat());
+ format);
}
}
@@ -121,12 +123,35 @@ public class IllegalTokenTextCheck
}
/**
+ * 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;
+ updateRegexp();
+ }
+
+ /**
* Set whether or not the match is case sensitive.
* @param caseInsensitive true if the match is case insensitive.
*/
public void setIgnoreCase(boolean caseInsensitive) {
if (caseInsensitive) {
- setCompileFlags(Pattern.CASE_INSENSITIVE);
+ compileFlags = Pattern.CASE_INSENSITIVE;
+ }
+ else {
+ compileFlags = 0;
}
+
+ updateRegexp();
+ }
+
+ /**
+ * Updates the {@link #regexp} based on the values from {@link #format} and
+ * {@link #compileFlags}.
+ */
+ private void updateRegexp() {
+ regexp = CommonUtils.createPattern(format, compileFlags);
}
}
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/XDocsPagesTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/XDocsPagesTest.java
index f9a3aa126..bacda83a7 100644
--- a/src/test/java/com/puppycrawl/tools/checkstyle/XDocsPagesTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/XDocsPagesTest.java
@@ -110,7 +110,6 @@ public class XDocsPagesTest {
private static final List<String> UNDOCUMENTED_PROPERTIES = Arrays.asList(
"SuppressWithNearbyCommentFilter.fileContents",
- "IllegalTokenTextCheck.compileFlags",
"AbstractClassNameCheck.compileFlags",
"ClassTypeParameterNameCheck.compileFlags",
"ConstantNameCheck.compileFlags",