forked from phoedos/pmd
Fixed bug 1592710 - VariableNamingConventions no longers reports false positives on certain enum declarations. This was actually a bug in ASTFieldDeclaration.isInterfaceMember()
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4782 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -7,4 +7,4 @@ that contains that fix.
|
||||
Thanks,
|
||||
|
||||
Tom
|
||||
Using PMD? Get the book - http://pmdapplied.com/
|
||||
The PMD book for $20: http://pmdapplied.com/
|
||||
|
@ -14,6 +14,7 @@ Fixed bugs 1060761 / 1433119 & RFE 1196954 - CloseResource now takes an optional
|
||||
Fixed bug 1579615 - OverrideBothEqualsAndHashcode no longer throws an Exception on equals methods that don't have Object as a parameter type.
|
||||
Fixed bug 1580859 - AvoidDecimalLiteralsInBigDecimalConstructor now catches more cases.
|
||||
Fixed bug 1581123 - False +: UnnecessaryWrapperObjectCreation.
|
||||
Fixed bug 1592710 - VariableNamingConventions no longers reports false positives on certain enum declarations.
|
||||
Applied patch 1551189 - SingularField false + for initialization blocks
|
||||
Applied patch 1573981 - false + in CloneMethodMustImplementCloneable
|
||||
Applied patch 1574988 - false + in OverrideBothEqualsAndHashcode
|
||||
@ -22,7 +23,7 @@ Implemented RFE 1566313 - Command Line now takes minimumpriority attribute to fi
|
||||
PMD now requires JDK 1.4 to run
|
||||
- PMD will still analyze code from earlier JDKs
|
||||
- PMD now uses the built-in JDK 1.4 regex utils vs Jakarta ORO
|
||||
- PMD now uses the JDK javax.xml APIs rather than being hardcoded to use Xerces and Xalan
|
||||
- PMD now uses the JDK javax.xml APIs rather than being hardcoded to use Xerces and Xalan
|
||||
SummaryHTML Report changes from Brent Fisher - now contains linePrefix to support source output from javadoc using "linksource"
|
||||
Fixed CSVRenderer - had flipped line and priority columns
|
||||
Fixed bug in Ant task - CSV reports were being output as text.
|
||||
|
@ -74,6 +74,9 @@ public class ASTFieldDeclaration extends AccessNode implements Dimensionable {
|
||||
}
|
||||
|
||||
public boolean isInterfaceMember() {
|
||||
if (jjtGetParent().jjtGetParent() instanceof ASTEnumBody) {
|
||||
return false;
|
||||
}
|
||||
ASTClassOrInterfaceDeclaration n = (ASTClassOrInterfaceDeclaration)getFirstParentOfType(ASTClassOrInterfaceDeclaration.class);
|
||||
return n instanceof ASTClassOrInterfaceDeclaration && n.isInterface();
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ public class VariableNamingConventions extends AbstractRule {
|
||||
return checkNames(node, data);
|
||||
}
|
||||
|
||||
public Object checkNames(AccessNode node, Object data) {
|
||||
private Object checkNames(ASTFieldDeclaration node, Object data) {
|
||||
ASTType childNodeType = (ASTType) node.jjtGetChild(0);
|
||||
String varType = "";
|
||||
if (childNodeType.jjtGetChild(0) instanceof ASTName) {
|
||||
@ -83,25 +83,15 @@ public class VariableNamingConventions extends AbstractRule {
|
||||
ASTVariableDeclaratorId childNodeId = (ASTVariableDeclaratorId) childNodeName.jjtGetChild(0);
|
||||
String varName = childNodeId.getImage();
|
||||
|
||||
if (varName.equals("serialVersionUID")) {
|
||||
if (varName.equals("serialVersionUID") || (node.isFinal() && !node.isStatic() && !node.isInterfaceMember())) {
|
||||
return data;
|
||||
}
|
||||
|
||||
// non static final class fields are OK
|
||||
if (node.isFinal() && !node.isStatic()) {
|
||||
if (node.jjtGetParent().jjtGetParent().jjtGetParent() instanceof ASTClassOrInterfaceDeclaration) {
|
||||
ASTClassOrInterfaceDeclaration c = (ASTClassOrInterfaceDeclaration) node.jjtGetParent().jjtGetParent().jjtGetParent();
|
||||
if (!c.isInterface()) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// static finals (and interface fields, which are implicitly static and final) are
|
||||
// checked for uppercase
|
||||
if ((node.isStatic() && node.isFinal()) || (node.jjtGetParent().jjtGetParent().jjtGetParent() instanceof ASTClassOrInterfaceDeclaration && ((ASTClassOrInterfaceDeclaration) node.jjtGetParent().jjtGetParent().jjtGetParent()).isInterface())) {
|
||||
if (!varName.equals(varName.toUpperCase())) {
|
||||
addViolation(data, childNodeName, "Variables that are final and static should be in all caps.");
|
||||
addViolationWithMessage(data, childNodeName, "Variables that are final and static should be in all caps.");
|
||||
}
|
||||
return data;
|
||||
}
|
||||
@ -114,10 +104,10 @@ public class VariableNamingConventions extends AbstractRule {
|
||||
}
|
||||
|
||||
if (strippedVarName.indexOf('_') >= 0) {
|
||||
addViolation(data, childNodeName, "Variables that are not final should not contain underscores (except for underscores in standard prefix/suffix).");
|
||||
addViolationWithMessage(data, childNodeName, "Variables that are not final should not contain underscores (except for underscores in standard prefix/suffix).");
|
||||
}
|
||||
if (Character.isUpperCase(varName.charAt(0))) {
|
||||
addViolation(data, childNodeName, "Variables should start with a lowercase character");
|
||||
addViolationWithMessage(data, childNodeName, "Variables should start with a lowercase character");
|
||||
}
|
||||
}
|
||||
return data;
|
||||
|
Reference in New Issue
Block a user