01: /**
02: * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
03: */package net.sourceforge.pmd.rules.design;
04:
05: import net.sourceforge.pmd.AbstractRule;
06: import net.sourceforge.pmd.ast.ASTClassOrInterfaceType;
07: import net.sourceforge.pmd.ast.ASTFieldDeclaration;
08: import net.sourceforge.pmd.ast.ASTFormalParameter;
09: import net.sourceforge.pmd.ast.ASTResultType;
10: import net.sourceforge.pmd.ast.Node;
11: import net.sourceforge.pmd.util.CollectionUtil;
12:
13: public class LooseCoupling extends AbstractRule {
14:
15: // TODO - these should be brought in via external properties
16: // private static final Set implClassNames = CollectionUtil.asSet( new Object[] {
17: // "ArrayList", "HashSet", "HashMap", "LinkedHashMap", "LinkedHashSet", "TreeSet", "TreeMap", "Vector",
18: // "java.util.ArrayList", "java.util.HashSet", "java.util.HashMap",
19: // "java.util.LinkedHashMap", "java.util.LinkedHashSet", "java.util.TreeSet",
20: // "java.util.TreeMap", "java.util.Vector"
21: // });
22:
23: public LooseCoupling() {
24: super ();
25: }
26:
27: public Object visit(ASTClassOrInterfaceType node, Object data) {
28: Node parent = node.jjtGetParent().jjtGetParent().jjtGetParent();
29: String typeName = node.getImage();
30: if (CollectionUtil.isCollectionType(typeName, false)
31: && (parent instanceof ASTFieldDeclaration
32: || parent instanceof ASTFormalParameter || parent instanceof ASTResultType)) {
33: addViolation(data, node, typeName);
34: }
35: return data;
36: }
37: }
|