minor refactoring

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1127 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2002-10-17 13:07:42 +00:00
parent 2514424643
commit fb0a00e45e

View File

@ -7,10 +7,7 @@ package net.sourceforge.pmd.rules.design;
import net.sourceforge.pmd.AbstractRule; import net.sourceforge.pmd.AbstractRule;
import net.sourceforge.pmd.RuleContext; import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.ast.ASTResultType; import net.sourceforge.pmd.ast.*;
import net.sourceforge.pmd.ast.SimpleNode;
import net.sourceforge.pmd.ast.ASTFieldDeclaration;
import net.sourceforge.pmd.ast.ASTFormalParameter;
import java.util.Set; import java.util.Set;
import java.util.HashSet; import java.util.HashSet;
@ -40,26 +37,11 @@ public class LooseCouplingRule extends AbstractRule {
implClassNames.add("java.util.TreeMap"); implClassNames.add("java.util.TreeMap");
} }
public Object visit(ASTResultType node, Object data) { public Object visit(ASTName node, Object data) {
if (node.isVoid()) { Node parent = node.jjtGetParent().jjtGetParent();
return data; if (implClassNames.contains(node.getImage()) && (parent instanceof ASTFieldDeclaration || parent instanceof ASTFormalParameter || parent instanceof ASTResultType)) {
}
return checkType(node, data);
}
public Object visit(ASTFieldDeclaration node, Object data) {
return checkType(node, data);
}
public Object visit(ASTFormalParameter node, Object data) {
return checkType(node, data);
}
private Object checkType(SimpleNode node, Object data) {
SimpleNode name = (SimpleNode)node.jjtGetChild(0).jjtGetChild(0);
if (implClassNames.contains(name.getImage())) {
RuleContext ctx = (RuleContext)data; RuleContext ctx = (RuleContext)data;
ctx.getReport().addRuleViolation(createRuleViolation(ctx, name.getBeginLine(), MessageFormat.format(getMessage(), new Object[] {name.getImage()}))); ctx.getReport().addRuleViolation(createRuleViolation(ctx, node.getBeginLine(), MessageFormat.format(getMessage(), new Object[] {node.getImage()})));
} }
return data; return data;
} }