Incorporate patch 555878 from Rick Giles to allow pattern for local final

variables to be specified.
This commit is contained in:
Oliver Burn 2002-08-21 08:08:43 +00:00
parent 1fdf65bf01
commit f8a53831f0
8 changed files with 54 additions and 4 deletions

View File

@ -202,6 +202,13 @@ This task is included in the checkstyle distribution.</p>
<td valign="top">Specifies the regular expression to match against local variable names. Default value is defined <a href="engine.html#localvarformat">here</a>.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">localFinalVarPattern</td>
<td valign="top">Specifies the regular expression to match against local final variable names. Default value is defined <a href="engine.html#localvarformat">here</a>.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">headerFile</td>
<td valign="top">Specifies the file containing the header lines. Default is to not check.</td>

View File

@ -168,10 +168,17 @@ This command line tool is included in the checkstyle distribution.</p>
<td valign="top">checkstyle.pattern.method</td>
<td valign="top">Specifies the regular expression to match against method names. Default value is defined <a href="engine.html#methodformat">here</a>.</td>
</tr>
<tr>
<td valign="top">checkstyle.pattern.localvar</td>
<td valign="top">Specifies the regular expression to match against local variable names. Default value is defined <a href="engine.html#localvarformat">here</a>.</td>
</tr>
<tr>
<td valign="top">checkstyle.pattern.localfinalvar</td>
<td valign="top">Specifies the regular expression to match against local final variable names. Default value is defined <a href="engine.html#localvarformat">here</a>.</td>
</tr>
<tr>
<td valign="top">checkstyle.header.file</td>
<td valign="top">Specifies the file containing the header lines. Default is to not check.</td>

View File

@ -45,6 +45,7 @@
<li class="body">Detect the number of parameters in a declaration exceeding a specified amount (request 582144).</li>
<li class="body">Inspired by patch 580410 from Shinya Ohnuma, now the error message are localised.</li>
<li class="body">Support checking to determine if an unused <span class="code">@throws</span> exception is a subclass of <span class="code">java.lang.Error</span> (request 583719).</li>
<li class="body">Incorporate patch 555878 from Rick Giles to allow pattern for local final variables to be specified.</li>
<li class="body">Incorporate patch 566855 from Rob Worth to optionally check that parenthesis are padded with spaces.</li>
<li class="body">Incorporate patch 590931 from Vijay Aravamudhan to improve documentation of the build.xml file.</li>
<li class="body">Incorporate patch from Vijay Aravamudhan to enforce requiring @version tag (request 543964).</li>

View File

@ -301,6 +301,13 @@ public class CheckStyleTask
"localVarPattern");
}
/** @param aPat pattern for local final variables **/
public void setLocalFinalVarPattern(final String aPat)
{
setPatternProperty(Defn.LOCAL_FINAL_VAR_PATTERN_PROP, aPat,
"localFinalVarPattern");
}
/** @param aPat pattern for method names **/
public void setMethodPattern(final String aPat)
{

View File

@ -69,6 +69,8 @@ public class Configuration
private static final String TYPE_PATTERN = "^[A-Z][a-zA-Z0-9]*$";
/** the pattern to match against method local variables **/
private static final String LOCAL_VAR_PATTERN = "^[a-z][a-zA-Z0-9]*$";
/** the pattern to match against method local final variables **/
private static final String LOCAL_FINAL_VAR_PATTERN = "^[a-z][a-zA-Z0-9]*$";
/** the pattern to match against method names **/
private static final String METHOD_PATTERN = "^[a-z][a-zA-Z0-9]*$";
/** the pattern to exclude from line length checks **/
@ -192,6 +194,8 @@ public class Configuration
setPatternProperty(aProps, Defn.TYPE_PATTERN_PROP, TYPE_PATTERN);
setPatternProperty(aProps, Defn.LOCAL_VAR_PATTERN_PROP,
LOCAL_VAR_PATTERN);
setPatternProperty(aProps, Defn.LOCAL_FINAL_VAR_PATTERN_PROP,
LOCAL_FINAL_VAR_PATTERN);
setPatternProperty(aProps, Defn.METHOD_PATTERN_PROP, METHOD_PATTERN);
setPatternProperty(aProps, Defn.IGNORE_LINE_LENGTH_PATTERN_PROP,
IGNORE_LINE_LENGTH_PATTERN);
@ -275,6 +279,8 @@ public class Configuration
PUBLIC_MEMBER_PATTERN);
setPatternProperty(Defn.TYPE_PATTERN_PROP, TYPE_PATTERN);
setPatternProperty(Defn.LOCAL_VAR_PATTERN_PROP, LOCAL_VAR_PATTERN);
setPatternProperty(Defn.LOCAL_FINAL_VAR_PATTERN_PROP,
LOCAL_FINAL_VAR_PATTERN);
setPatternProperty(Defn.METHOD_PATTERN_PROP, METHOD_PATTERN);
setPatternProperty(Defn.IGNORE_LINE_LENGTH_PATTERN_PROP,
IGNORE_LINE_LENGTH_PATTERN);
@ -437,6 +443,18 @@ public class Configuration
return getRegexpProperty(Defn.LOCAL_VAR_PATTERN_PROP);
}
/** @return pattern to match local final variables **/
public String getLocalFinalVarPat()
{
return getPatternProperty(Defn.LOCAL_FINAL_VAR_PATTERN_PROP);
}
/** @return regexp to match local final variables **/
public RE getLocalFinalVarRegexp()
{
return getRegexpProperty(Defn.LOCAL_FINAL_VAR_PATTERN_PROP);
}
/** @return pattern to match method names **/
public String getMethodPat()
{

View File

@ -40,6 +40,8 @@ public interface Defn
String TYPE_PATTERN_PROP = "checkstyle.pattern.type";
/** property name for the method local variable pattern **/
String LOCAL_VAR_PATTERN_PROP = "checkstyle.pattern.localvar";
/** property name for the method local final variable pattern **/
String LOCAL_FINAL_VAR_PATTERN_PROP = "checkstyle.pattern.localfinalvar";
/** property name for the method local variable pattern **/
String METHOD_PATTERN_PROP = "checkstyle.pattern.method";
/** property name for the maximum line length **/

View File

@ -373,9 +373,16 @@ class Verifier
void verifyVariable(MyVariable aVar)
{
if (inMethodBlock()) {
checkVariable(aVar,
mConfig.getLocalVarRegexp(),
mConfig.getLocalVarPat());
if (aVar.getModifierSet().containsFinal()) {
checkVariable(aVar,
mConfig.getLocalFinalVarRegexp(),
mConfig.getLocalFinalVarPat());
}
else {
checkVariable(aVar,
mConfig.getLocalVarRegexp(),
mConfig.getLocalVarPat());
}
return;
}

View File

@ -461,6 +461,7 @@ public class CheckerTest
mConfig.setPatternProperty(Defn.MEMBER_PATTERN_PROP, "^m[A-Z][a-zA-Z0-9]*$");
mConfig.setPatternProperty(Defn.IGNORE_LINE_LENGTH_PATTERN_PROP,"^.*is OK.*regexp.*$");
mConfig.setPatternProperty(Defn.TODO_PATTERN_PROP, "FIXME:");
mConfig.setPatternProperty(Defn.LOCAL_FINAL_VAR_PATTERN_PROP, "[A-Z]+");
final Checker c = createChecker();
final String filepath = getPath("InputSimple.java");
assertNotNull(c);
@ -486,7 +487,7 @@ public class CheckerTest
filepath + ":80: Method length is 20 lines (max allowed is 19).",
filepath + ":103: Constructor length is 10 lines (max allowed is 9).",
filepath + ":119:13: variable name 'ABC' must match pattern '^[a-z][a-zA-Z0-9]*$'.",
filepath + ":123:19: variable name 'CDE' must match pattern '^[a-z][a-zA-Z0-9]*$'.",
filepath + ":122:19: variable name 'cde' must match pattern '[A-Z]+'.",
filepath + ":127:9: '{' should be on the previous line.",
filepath + ":130:18: variable name 'I' must match pattern '^[a-z][a-zA-Z0-9]*$'.",
filepath + ":131:9: '{' should be on the previous line.",