diff --git a/docs/config_misc.html b/docs/config_misc.html index 9aeb8816b..b37408819 100644 --- a/docs/config_misc.html +++ b/docs/config_misc.html @@ -72,10 +72,16 @@ regular expression ^$ (empty) + + ignoreCase + Controls whether to ignore case when searching. + Boolean + false + message message which is used to notify about violations, - if empty then default(hard-codded) message is used. + if empty then default(hard-coded) message is used. String ""(empty) @@ -98,6 +104,15 @@ <module name="GenericIllegalRegexp"> <!-- \s matches whitespace character, $ matches end of line. --> <property name="format" value="\s$"/> +</module> + +

+ To configure the check to find case-insensitive occurrences of "debug": +

+
+<module name="GenericIllegalRegexp">
+    <property name="format" value="debug"/>
+    <property name="ignoreCase" value="true"/>
 </module>
       

Package

@@ -349,7 +364,7 @@ like 1.

FinalParameters

Description

Check that method/constructor parameters are final. Interface methods are not checked - - the final keyword does not make sense for interface mathod parameters as there is no code + the final keyword does not make sense for interface method parameters as there is no code that could modify the parameter.

diff --git a/docs/releasenotes.html b/docs/releasenotes.html index d4fb67d41..6fadf73bb 100644 --- a/docs/releasenotes.html +++ b/docs/releasenotes.html @@ -145,6 +145,10 @@ a Reload Java File button and storage of the current directory of the last opened file (request 740545). +

  • Patch from Bill Schneider to add + GenericIllegalRegexpCheck property to perform + case-insensitive matches (request 740112).
  • +

    diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/GenericIllegalRegexpCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/GenericIllegalRegexpCheck.java index 8b3ae510c..1536fdf3c 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/GenericIllegalRegexpCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/GenericIllegalRegexpCheck.java @@ -18,6 +18,8 @@ //////////////////////////////////////////////////////////////////////////////// package com.puppycrawl.tools.checkstyle.checks; +import org.apache.regexp.RE; + import com.puppycrawl.tools.checkstyle.api.DetailAST; /** @@ -39,6 +41,7 @@ import com.puppycrawl.tools.checkstyle.api.DetailAST; * </module> * * @author lkuehne + * @author Bill Schneider */ public class GenericIllegalRegexpCheck extends AbstractFormatCheck { @@ -48,6 +51,9 @@ public class GenericIllegalRegexpCheck extends AbstractFormatCheck */ private String mMessage = ""; + /** case insensitive? **/ + private boolean mIgnoreCase = false; + /** * Setter for message property * @param aMessage custom message which should be used @@ -62,6 +68,15 @@ public class GenericIllegalRegexpCheck extends AbstractFormatCheck mMessage = aMessage; } + /** + * Set whether or not the match is case sensitive. + * @param aCaseInsensitive true if the match is case insensitive. + */ + public void setIgnoreCase(boolean aCaseInsensitive) + { + mIgnoreCase = aCaseInsensitive; + } + /** * Instantiates an new GenericIllegalRegexpCheck. */ @@ -93,4 +108,26 @@ public class GenericIllegalRegexpCheck extends AbstractFormatCheck } } } + + /** @return the regexp to match against */ + public RE getRegexp() + { + final RE regexp = super.getRegexp(); + if (mIgnoreCase) { + regexp.setMatchFlags(RE.MATCH_CASEINDEPENDENT); + } + // Without the else, in a sequence of GenericIllegalRegexpCheck's, + // the first with mIgnoreCase true, the second with mIgnoreCase + // false, the second still has match behaviour flags as + // RE.MATCH_CASEINDEPENDENT. + // This happens with GenericIllegalRegexpCheckTest method + // testIgnoreCaseFalse(), for example. + // TODO: Check whether this a bug or known feature of + // org.apache.regexp.RE. + else { + regexp.setMatchFlags(RE.MATCH_NORMAL); + } + return regexp; + } + } diff --git a/src/tests/com/puppycrawl/tools/checkstyle/checks/GenericIllegalRegexpCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/checks/GenericIllegalRegexpCheckTest.java index 4997159d3..3b2881ac1 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/checks/GenericIllegalRegexpCheckTest.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/checks/GenericIllegalRegexpCheckTest.java @@ -33,4 +33,39 @@ public class GenericIllegalRegexpCheckTest }; verify(checkConfig, getPath("InputSemantic.java"), expected); } + + + public void testIgnoreCaseTrue() + throws Exception + { + final String illegal = "SYSTEM\\.(OUT)|(ERR)\\.PRINT(LN)?\\("; + final DefaultConfiguration checkConfig = + createCheckConfig(GenericIllegalRegexpCheck.class); + checkConfig.addAttribute("format", illegal); + checkConfig.addAttribute("ignoreCase", "true"); + final String[] expected = { + "69: Line matches the illegal pattern '" + illegal + "'." + }; + verify(checkConfig, getPath("InputSemantic.java"), expected); + } + + public void testIgnoreCaseFalse() + throws Exception + { + final String illegal = "SYSTEM\\.(OUT)|(ERR)\\.PRINT(LN)?\\("; + final DefaultConfiguration checkConfigTrue = + createCheckConfig(GenericIllegalRegexpCheck.class); + checkConfigTrue.addAttribute("format", illegal); + checkConfigTrue.addAttribute("ignoreCase", "true"); + final String[] expectedTrue = { + "69: Line matches the illegal pattern '" + illegal + "'."}; + verify(checkConfigTrue, getPath("InputSemantic.java"), expectedTrue); + + final DefaultConfiguration checkConfigFalse = + createCheckConfig(GenericIllegalRegexpCheck.class); + checkConfigFalse.addAttribute("format", illegal); + checkConfigFalse.addAttribute("ignoreCase", "false"); + final String[] expectedFalse = {}; + verify(checkConfigFalse, getPath("InputSemantic.java"), expectedFalse); + } }