diff --git a/docs/anttask.html b/docs/anttask.html
index 3ea44f92b..a60ff8974 100644
--- a/docs/anttask.html
+++ b/docs/anttask.html
@@ -202,6 +202,13 @@ This task is included in the checkstyle distribution.
Specifies the regular expression to match against local variable names. Default value is defined here. |
No |
+
+
+ | localFinalVarPattern |
+ Specifies the regular expression to match against local final variable names. Default value is defined here. |
+ No |
+
+
| headerFile |
Specifies the file containing the header lines. Default is to not check. |
diff --git a/docs/cmdline.html b/docs/cmdline.html
index c04ea6dda..3e22f7168 100644
--- a/docs/cmdline.html
+++ b/docs/cmdline.html
@@ -168,10 +168,17 @@ This command line tool is included in the checkstyle distribution.
checkstyle.pattern.method |
Specifies the regular expression to match against method names. Default value is defined here. |
+
| checkstyle.pattern.localvar |
Specifies the regular expression to match against local variable names. Default value is defined here. |
+
+
+ | checkstyle.pattern.localfinalvar |
+ Specifies the regular expression to match against local final variable names. Default value is defined here. |
+
+
| checkstyle.header.file |
Specifies the file containing the header lines. Default is to not check. |
diff --git a/docs/releasenotes.html b/docs/releasenotes.html
index a78fcbee1..bdf964e60 100644
--- a/docs/releasenotes.html
+++ b/docs/releasenotes.html
@@ -45,6 +45,7 @@
Detect the number of parameters in a declaration exceeding a specified amount (request 582144).
Inspired by patch 580410 from Shinya Ohnuma, now the error message are localised.
Support checking to determine if an unused @throws exception is a subclass of java.lang.Error (request 583719).
+ Incorporate patch 555878 from Rick Giles to allow pattern for local final variables to be specified.
Incorporate patch 566855 from Rob Worth to optionally check that parenthesis are padded with spaces.
Incorporate patch 590931 from Vijay Aravamudhan to improve documentation of the build.xml file.
Incorporate patch from Vijay Aravamudhan to enforce requiring @version tag (request 543964).
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckStyleTask.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckStyleTask.java
index 94092d51d..ab53d58c2 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckStyleTask.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckStyleTask.java
@@ -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)
{
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java
index 999da85e1..19722ab4b 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java
@@ -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()
{
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java
index c1a451d5d..1543986c7 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java
@@ -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 **/
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Verifier.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Verifier.java
index bec87ef1a..866e300f8 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Verifier.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Verifier.java
@@ -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;
}
diff --git a/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java b/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java
index f16ec5d4a..df980ad65 100644
--- a/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java
+++ b/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java
@@ -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.",