1 4 package net.sourceforge.pmd.rules.design; 5 6 import net.sourceforge.pmd.AbstractRule; 7 import net.sourceforge.pmd.ast.ASTClassOrInterfaceType; 8 import net.sourceforge.pmd.ast.ASTFieldDeclaration; 9 import net.sourceforge.pmd.ast.ASTFormalParameter; 10 import net.sourceforge.pmd.ast.ASTResultType; 11 import net.sourceforge.pmd.ast.Node; 12 import net.sourceforge.pmd.util.CollectionUtil; 13 14 public class LooseCoupling extends AbstractRule { 15 16 24 public LooseCoupling() { 25 super(); 26 } 27 28 public Object visit(ASTClassOrInterfaceType node, Object data) { 29 Node parent = node.jjtGetParent().jjtGetParent().jjtGetParent(); 30 String typeName = node.getImage(); 31 if (CollectionUtil.isCollectionType(typeName, false) && (parent instanceof ASTFieldDeclaration || parent instanceof ASTFormalParameter || parent instanceof ASTResultType)) { 32 addViolation(data, node, typeName); 33 } 34 return data; 35 } 36 } 37 | Popular Tags |