refactored, new isQualifiedName(SimpleNode) method

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4609 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Brian Remedios
2006-10-10 04:12:21 +00:00
parent 1fab9a1a41
commit 5f6dd18214
3 changed files with 8 additions and 4 deletions

View File

@ -242,4 +242,8 @@ public abstract class AbstractRule extends JavaParserVisitorAdapter implements R
return c.getImage();
return null;
}
public static boolean isQualifiedName(SimpleNode node) {
return node.getImage().indexOf('.') != -1;
}
}

View File

@ -13,7 +13,7 @@ public class CompareObjectsWithEquals extends AbstractRule {
private boolean hasName(Node n) {
return n.jjtGetNumChildren() > 0 && n.jjtGetChild(0) instanceof ASTName;
}
public Object visit(ASTEqualityExpression node, Object data) {
// skip if either child is not a simple name
if (!hasName(((SimpleNode) node.jjtGetChild(0)).jjtGetChild(0)) || !hasName(((SimpleNode) node.jjtGetChild(1)).jjtGetChild(0))) {
@ -21,8 +21,8 @@ public class CompareObjectsWithEquals extends AbstractRule {
}
// skip if either is a qualified name
if (((SimpleNode) node.jjtGetChild(0).jjtGetChild(0).jjtGetChild(0)).getImage().indexOf('.') != -1
|| ((SimpleNode) node.jjtGetChild(1).jjtGetChild(0).jjtGetChild(0)).getImage().indexOf('.') != -1) {
if (isQualifiedName((SimpleNode) node.jjtGetChild(0).jjtGetChild(0).jjtGetChild(0))
|| isQualifiedName((SimpleNode) node.jjtGetChild(1).jjtGetChild(0).jjtGetChild(0))) {
return data;
}

View File

@ -49,7 +49,7 @@ public class PositionalIteratorRule extends AbstractRule {
if (child.jjtGetNumChildren() > 0) {
collectNames(target, names, child);
} else {
if (child instanceof ASTName && child.getImage().indexOf('.') != -1 && target.equals(getVariableName(child.getImage()))) {
if (child instanceof ASTName && isQualifiedName(child) && target.equals(getVariableName(child.getImage()))) {
names.add(child.getImage());
}
}