Patch from Rick Giles - also removed the dead code

This commit is contained in:
Oliver Burn 2002-10-29 13:30:30 +00:00
parent 50ffeeae38
commit 96abec9ddf
7 changed files with 88 additions and 32 deletions

View File

@ -55,7 +55,6 @@ public class Configuration
PATTERN_DEFAULTS.put(Defn.TODO_PATTERN_PROP, "TODO:");
PATTERN_DEFAULTS.put(Defn.STATIC_PATTERN_PROP, "^[a-z][a-zA-Z0-9]*$");
PATTERN_DEFAULTS.put(Defn.CONST_PATTERN_PROP, "^[A-Z](_?[A-Z0-9]+)*$");
PATTERN_DEFAULTS.put(Defn.MEMBER_PATTERN_PROP, "^[a-z][a-zA-Z0-9]*$");
PATTERN_DEFAULTS.put(Defn.PUBLIC_MEMBER_PATTERN_PROP,
"^f[A-Z][a-zA-Z0-9]*$");
}
@ -323,18 +322,6 @@ public class Configuration
return getRegexpProperty(Defn.CONST_PATTERN_PROP);
}
/** @return pattern to match member variables **/
String getMemberPat()
{
return getPatternProperty(Defn.MEMBER_PATTERN_PROP);
}
/** @return regexp to match member variables **/
RE getMemberRegexp()
{
return getRegexpProperty(Defn.MEMBER_PATTERN_PROP);
}
/** @return pattern to match public member variables **/
String getPublicMemberPat()
{

View File

@ -35,8 +35,6 @@ public interface Defn
String STATIC_PATTERN_PROP = "checkstyle.pattern.static";
/** property name for the static final variable pattern **/
String CONST_PATTERN_PROP = "checkstyle.pattern.const";
/** property name for the member variable pattern **/
String MEMBER_PATTERN_PROP = "checkstyle.pattern.member";
/** property name for the public member variable pattern **/
String PUBLIC_MEMBER_PATTERN_PROP = "checkstyle.pattern.publicmember";
/** property name for length of constructors **/
@ -97,7 +95,6 @@ public interface Defn
TODO_PATTERN_PROP,
STATIC_PATTERN_PROP,
CONST_PATTERN_PROP,
MEMBER_PATTERN_PROP,
PUBLIC_MEMBER_PATTERN_PROP,
};

View File

@ -302,9 +302,9 @@ class Verifier
|| (mConfig.isAllowPackage() && isPckg)
|| (mConfig.isAllowProtected() && isProt))
{
checkVariable(aVar,
mConfig.getMemberRegexp(),
mConfig.getMemberPat());
// checkVariable(aVar,
// mConfig.getMemberRegexp(),
// mConfig.getMemberPat());
}
}
}

View File

@ -0,0 +1,58 @@
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2002 Oliver Burn
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.checks;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.ScopeUtils;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
/**
* Checks that instance variable names conform to a specified format.
*
* @author Rick Giles
* @version 1.0
*/
public class MemberNameCheck
extends AbstractNameCheck
{
/** Creates a new <code>MemberNameCheck</code> instance. */
public MemberNameCheck()
{
super("^[a-z][a-zA-Z0-9]*$");
}
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {TokenTypes.VARIABLE_DEF};
}
/** @see com.puppycrawl.tools.checkstyle.check.AbstractNameCheck */
protected final boolean mustCheckName(DetailAST aAST)
{
DetailAST modifiersAST = aAST.findFirstToken(TokenTypes.MODIFIERS);
final boolean isStatic = (modifiersAST != null)
&& modifiersAST.branchContains(TokenTypes.LITERAL_STATIC);
final boolean isPublic = (modifiersAST != null)
&& modifiersAST.branchContains(TokenTypes.LITERAL_PUBLIC);
return (!isStatic && !isPublic && !ScopeUtils.inInterfaceBlock(aAST)
&& !ScopeUtils.inCodeBlock(aAST));
}
}

View File

@ -295,15 +295,12 @@ public class CheckerTest
{
mProps.setProperty(Defn.MAX_CONSTRUCTOR_LENGTH_PROP, "9");
mProps.setProperty(Defn.STATIC_PATTERN_PROP, "^s[A-Z][a-zA-Z0-9]*$");
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]*$");
final Checker c = createChecker();
final String filepath = getPath("InputSimple.java");
assertNotNull(c);
final String[] expected = {
filepath + ":30:24: Name 'badStatic' must match pattern '^s[A-Z][a-zA-Z0-9]*$'.",
filepath + ":35:17: Name 'badMember' must match pattern '^m[A-Z][a-zA-Z0-9]*$'.",
filepath + ":42:40: ',' is not followed by whitespace.",
filepath + ":71:30: ',' is not followed by whitespace.",
filepath + ":103: Constructor length is 10 lines (max allowed is 9).",

View File

@ -28,14 +28,4 @@ public class ConfigurationTest
final Configuration c = new Configuration(p, System.out);
assertNotNull(c);
}
public void testGetProperties() throws Exception
{
final Properties props = new Properties();
props.setProperty(Defn.MEMBER_PATTERN_PROP, "bulldogs");
final Configuration c = new Configuration(props, System.out);
assertEquals("bulldogs",
c.getProperties().getProperty(Defn.MEMBER_PATTERN_PROP));
}
}

View File

@ -0,0 +1,27 @@
package com.puppycrawl.tools.checkstyle;
import com.puppycrawl.tools.checkstyle.checks.MemberNameCheck;
public class MemberNameCheckTest
extends BaseCheckTestCase
{
public MemberNameCheckTest(String aName)
{
super(aName);
}
public void testSpecified()
throws Exception
{
final CheckConfiguration checkConfig = new CheckConfiguration();
checkConfig.setClassname(MemberNameCheck.class.getName());
checkConfig.addProperty("format", "^m[A-Z][a-zA-Z0-9]*$");
final Checker c = createChecker(checkConfig);
final String fname = getPath("InputSimple.java");
final String[] expected = {
"35:17: Name 'badMember' must match pattern '^m[A-Z][a-zA-Z0-9]*$'.",
};
verify(c, fname, expected);
}
}