Incorporated patch from Bill Schneider to add property to
GenericIllegalRegexpCheck for case-insensitive matches (request 740112).
This commit is contained in:
parent
cb5ab77359
commit
1e67ec5577
|
|
@ -72,10 +72,16 @@
|
|||
<td><a href="property_types.html#regexp">regular expression</a></td>
|
||||
<td><span class="default">^$</span> (empty)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>ignoreCase</td>
|
||||
<td>Controls whether to ignore case when searching.</td>
|
||||
<td><a href="property_types.html#boolean">Boolean</a></td>
|
||||
<td><span class="default">false</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>message</td>
|
||||
<td>message which is used to notify about violations,
|
||||
if empty then default(hard-codded) message is used.</td>
|
||||
if empty then default(hard-coded) message is used.</td>
|
||||
<td><a href="property_types.html#String">String</a></td>
|
||||
<td><span class="default">""</span>(empty)</td>
|
||||
</tr>
|
||||
|
|
@ -98,6 +104,15 @@
|
|||
<module name="GenericIllegalRegexp">
|
||||
<!-- \s matches whitespace character, $ matches end of line. -->
|
||||
<property name="format" value="\s$"/>
|
||||
</module>
|
||||
</pre>
|
||||
<p class="body">
|
||||
To configure the check to find case-insensitive occurrences of "debug":
|
||||
</p>
|
||||
<pre class="body">
|
||||
<module name="GenericIllegalRegexp">
|
||||
<property name="format" value="debug"/>
|
||||
<property name="ignoreCase" value="true"/>
|
||||
</module>
|
||||
</pre>
|
||||
<h4>Package</h4>
|
||||
|
|
@ -349,7 +364,7 @@ like <span class="code">1</span>.
|
|||
<!-- --> <a name="FinalParameters"></a> <h2>FinalParameters</h2> <h4>Description</h4>
|
||||
<p class="body">
|
||||
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.
|
||||
</p>
|
||||
<p class="body">
|
||||
|
|
|
|||
|
|
@ -145,6 +145,10 @@
|
|||
a Reload Java File button and storage of the current directory
|
||||
of the last opened file (request 740545).</li>
|
||||
|
||||
<li class="body">Patch from Bill Schneider to add
|
||||
GenericIllegalRegexpCheck property to perform
|
||||
case-insensitive matches (request 740112).</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p class="body">
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
* </pre>
|
||||
* @author lkuehne
|
||||
* @author <a href="mailto:bschneider@vecna.com">Bill Schneider</a>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue