Patch for Rick Giles

This commit is contained in:
Oliver Burn 2002-10-29 13:37:20 +00:00
parent 96abec9ddf
commit cbce85c08c
3 changed files with 83 additions and 11 deletions

View File

@ -296,17 +296,6 @@ class Verifier
}
}
}
else {
// These are the non-static variables
if (Scope.PRIVATE.equals(variableScope)
|| (mConfig.isAllowPackage() && isPckg)
|| (mConfig.isAllowProtected() && isProt))
{
// checkVariable(aVar,
// mConfig.getMemberRegexp(),
// mConfig.getMemberPat());
}
}
}
}

View File

@ -0,0 +1,57 @@
////////////////////////////////////////////////////////////////////////////////
// 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 public, non-static variable names conform to a specified format.
*
* @author Rick Giles
* @version 1.0
*/
public class PublicMemberNameCheck
extends AbstractNameCheck
{
/** Creates a new <code>PublicMemberNameCheck</code> instance. */
public PublicMemberNameCheck()
{
super("^f[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));
}
}

View File

@ -0,0 +1,26 @@
package com.puppycrawl.tools.checkstyle;
import com.puppycrawl.tools.checkstyle.checks.PublicMemberNameCheck;
public class PublicMemberNameCheckTest
extends BaseCheckTestCase
{
public PublicMemberNameCheckTest(String aName)
{
super(aName);
}
public void testDefault()
throws Exception
{
final CheckConfiguration checkConfig = new CheckConfiguration();
checkConfig.setClassname(PublicMemberNameCheck.class.getName());
final Checker c = createChecker(checkConfig);
final String fname = getPath("InputSimple.java");
final String[] expected = {
"58:16: Name 'mTest2' must match pattern '^f[A-Z][a-zA-Z0-9]*$'.",
};
verify(c, fname, expected);
}
}