From d000ac3d7b73869d36d5c5b930b2c9aae412daa8 Mon Sep 17 00:00:00 2001 From: Oliver Burn Date: Tue, 29 Oct 2002 13:00:25 +0000 Subject: [PATCH] Finished port of Local Final name check - deleted old code --- .../puppycrawl/tools/checkstyle/Configuration.java | 14 -------------- .../com/puppycrawl/tools/checkstyle/Defn.java | 3 --- .../com/puppycrawl/tools/checkstyle/Verifier.java | 3 --- .../checks/LocalFinalVariableNameCheck.java | 2 +- .../puppycrawl/tools/checkstyle/CheckerTest.java | 2 -- .../LocalFinalVariableNameCheckTest.java | 14 ++++++++++++++ 6 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java index 428e3689f..cfd1cbde3 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java @@ -60,8 +60,6 @@ public class Configuration "^f[A-Z][a-zA-Z0-9]*$"); PATTERN_DEFAULTS.put(Defn.LOCAL_VAR_PATTERN_PROP, "^[a-z][a-zA-Z0-9]*$"); - PATTERN_DEFAULTS.put(Defn.LOCAL_FINAL_VAR_PATTERN_PROP, - "^[a-z][a-zA-Z0-9]*$"); } //////////////////////////////////////////////////////////////////////////// @@ -363,18 +361,6 @@ public class Configuration return getRegexpProperty(Defn.LOCAL_VAR_PATTERN_PROP); } - /** @return pattern to match local final variables **/ - String getLocalFinalVarPat() - { - return getPatternProperty(Defn.LOCAL_FINAL_VAR_PATTERN_PROP); - } - - /** @return regexp to match local final variables **/ - RE getLocalFinalVarRegexp() - { - return getRegexpProperty(Defn.LOCAL_FINAL_VAR_PATTERN_PROP); - } - /** @return the maximum constructor length **/ int getMaxConstructorLength() { diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java index c3cda3793..d92e86d2b 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java @@ -41,8 +41,6 @@ public interface Defn String PUBLIC_MEMBER_PATTERN_PROP = "checkstyle.pattern.publicmember"; /** 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 length of constructors **/ String MAX_CONSTRUCTOR_LENGTH_PROP = "checkstyle.maxconstructorlen"; /** property name for allowing protected data **/ @@ -104,7 +102,6 @@ public interface Defn MEMBER_PATTERN_PROP, PUBLIC_MEMBER_PATTERN_PROP, LOCAL_VAR_PATTERN_PROP, - LOCAL_FINAL_VAR_PATTERN_PROP, }; /** All the integer properties */ diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Verifier.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Verifier.java index c339fe905..d7717d89d 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Verifier.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Verifier.java @@ -254,9 +254,6 @@ class Verifier { if (inMethodBlock()) { if (aVar.getModifierSet().containsFinal()) { - checkVariable(aVar, - mConfig.getLocalFinalVarRegexp(), - mConfig.getLocalFinalVarPat()); } else { checkVariable(aVar, diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/LocalFinalVariableNameCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/LocalFinalVariableNameCheck.java index 6c41fd137..442def3fa 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/LocalFinalVariableNameCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/LocalFinalVariableNameCheck.java @@ -48,7 +48,7 @@ public class LocalFinalVariableNameCheck { final DetailAST modifiersAST = aAST.findFirstToken(TokenTypes.MODIFIERS); - final boolean isFinal = modifiersAST != null + final boolean isFinal = (modifiersAST != null) && modifiersAST.branchContains(TokenTypes.FINAL); return (isFinal && ScopeUtils.inCodeBlock(aAST)); diff --git a/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java b/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java index 02fe7ef3b..df304854f 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java @@ -298,7 +298,6 @@ public class CheckerTest mProps.setProperty(Defn.MEMBER_PATTERN_PROP, "^m[A-Z][a-zA-Z0-9]*$"); mProps.setProperty(Defn.TODO_PATTERN_PROP, "FIXME:"); mProps.setProperty(Defn.MEMBER_PATTERN_PROP, "^m[A-Z][a-zA-Z0-9]*$"); - mProps.setProperty(Defn.LOCAL_FINAL_VAR_PATTERN_PROP, "[A-Z]+"); final Checker c = createChecker(); final String filepath = getPath("InputSimple.java"); assertNotNull(c); @@ -309,7 +308,6 @@ public class CheckerTest filepath + ":71:30: ',' is not followed by whitespace.", filepath + ":103: Constructor length is 10 lines (max allowed is 9).", filepath + ":119:13: Name 'ABC' must match pattern '^[a-z][a-zA-Z0-9]*$'.", - filepath + ":122:19: Name 'cde' must match pattern '[A-Z]+'.", filepath + ":130:18: Name 'I' must match pattern '^[a-z][a-zA-Z0-9]*$'.", filepath + ":132:20: Name 'InnerBlockVariable' must match pattern '^[a-z][a-zA-Z0-9]*$'.", filepath + ":161: Comment matches to-do format 'FIXME:'.", diff --git a/src/tests/com/puppycrawl/tools/checkstyle/LocalFinalVariableNameCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/LocalFinalVariableNameCheckTest.java index 3ac1ca622..9b0edea81 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/LocalFinalVariableNameCheckTest.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/LocalFinalVariableNameCheckTest.java @@ -22,5 +22,19 @@ public class LocalFinalVariableNameCheckTest }; verify(c, fname, expected); } + + public void testSet() + throws Exception + { + final CheckConfiguration checkConfig = new CheckConfiguration(); + checkConfig.setClassname(LocalFinalVariableNameCheck.class.getName()); + checkConfig.addProperty("format", "[A-Z]+"); + final Checker c = createChecker(checkConfig); + final String fname = getPath("InputSimple.java"); + final String[] expected = { + "122:19: Name 'cde' must match pattern '[A-Z]+'.", + }; + verify(c, fname, expected); + } }