Removed old constant name check
This commit is contained in:
parent
e44cd4ec43
commit
4bbe4acd31
|
|
@ -338,16 +338,7 @@ class Verifier
|
|||
final boolean isProt = Scope.PROTECTED.equals(variableScope);
|
||||
|
||||
if (mods.containsStatic()) {
|
||||
if (mods.containsFinal()) {
|
||||
// Handle the serialVersionUID constant which is used for
|
||||
// Serialization. Cannot enforce rules on it. :-)
|
||||
if (!"serialVersionUID".equals(aVar.getText())) {
|
||||
checkVariable(aVar,
|
||||
mConfig.getStaticFinalRegexp(),
|
||||
mConfig.getStaticFinalPat());
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!mods.containsFinal()) {
|
||||
if (Scope.PRIVATE.equals(variableScope)
|
||||
|| (mConfig.isAllowPackage() && isPckg)
|
||||
|| (mConfig.isAllowProtected() && isProt))
|
||||
|
|
|
|||
|
|
@ -46,39 +46,32 @@ public class ConstantNameCheck
|
|||
/** @see com.puppycrawl.tools.checkstyle.api.Check */
|
||||
public void visitToken(DetailAST aAST)
|
||||
{
|
||||
//precondition
|
||||
if (aAST.getType() != TokenTypes.VARIABLE_DEF) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Need to consider the case of being in an interface! In that
|
||||
// case, does not matter if "static" and "final" keywords are there.
|
||||
|
||||
//constant?
|
||||
final DetailAST modifiers =
|
||||
Utils.findFirstToken(aAST.getFirstChild(),
|
||||
TokenTypes.MODIFIERS);
|
||||
if (modifiers == null
|
||||
|| !modifiers.branchContains(TokenTypes.LITERAL_STATIC)
|
||||
|| !modifiers.branchContains(TokenTypes.FINAL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
//name check
|
||||
final DetailAST name = Utils.findFirstToken(aAST.getFirstChild(),
|
||||
TokenTypes.IDENT);
|
||||
if (name == null) {
|
||||
return;
|
||||
}
|
||||
// Handle the serialVersionUID constant which is used for
|
||||
// Serialization. Cannot enforce rules on it. :-)
|
||||
if ("serialVersionUID".equals(name.getText())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!getRegexp().match(name.getText())) {
|
||||
log(name.getLineNo(),
|
||||
name.getColumnNo(),
|
||||
"name.invalidPattern",
|
||||
name.getText(),
|
||||
getFormat());
|
||||
if ((modifiers != null)
|
||||
&& modifiers.branchContains(TokenTypes.LITERAL_STATIC)
|
||||
&& modifiers.branchContains(TokenTypes.FINAL))
|
||||
{
|
||||
//name check
|
||||
final DetailAST name =
|
||||
Utils.findFirstToken(aAST.getFirstChild(), TokenTypes.IDENT);
|
||||
|
||||
// Handle the serialVersionUID constant which is used for
|
||||
// Serialization. Cannot enforce rules on it. :-)
|
||||
if (!"serialVersionUID".equals(name.getText())
|
||||
&& !getRegexp().match(name.getText()))
|
||||
{
|
||||
log(name.getLineNo(),
|
||||
name.getColumnNo(),
|
||||
"name.invalidPattern",
|
||||
name.getText(),
|
||||
getFormat());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -324,7 +324,6 @@ public class CheckerTest
|
|||
final String filepath = getPath("InputSimple.java");
|
||||
assertNotNull(c);
|
||||
final String[] expected = {
|
||||
filepath + ":25:29: Name 'badConstant' must match pattern '^[A-Z](_?[A-Z0-9]+)*$'.",
|
||||
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.",
|
||||
|
|
@ -334,7 +333,6 @@ public class CheckerTest
|
|||
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 + ":142:30: Name 'BAD__NAME' must match pattern '^[A-Z](_?[A-Z0-9]+)*$'.",
|
||||
filepath + ":161: Comment matches to-do format 'FIXME:'.",
|
||||
filepath + ":162: Comment matches to-do format 'FIXME:'.",
|
||||
filepath + ":163: Comment matches to-do format 'FIXME:'.",
|
||||
|
|
|
|||
Loading…
Reference in New Issue