View Javadoc

    1   /***
    2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
    3    */
    4   package net.sourceforge.pmd.typeresolution.rules;
    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  /***
    15   * This is a separate rule, uses the type resolution facade
    16   */
    17  public class LooseCoupling extends AbstractRule {
    18
    19  	public LooseCoupling() {
    20  		super();
    21  	}
    22
    23  	public Object visit(ASTClassOrInterfaceType node, Object data) {
    24  		Node parent = node.jjtGetParent().jjtGetParent().jjtGetParent();
    25  		Class clazzType = node.getType();
    26  		boolean isType = CollectionUtil.isCollectionType(clazzType, false);
    27  		if (isType
    28  				&& (parent instanceof ASTFieldDeclaration || parent instanceof ASTFormalParameter || parent instanceof ASTResultType)) {
    29  			addViolation(data, node, node.getImage());
    30  		}
    31  		return data;
    32  	}
    33  }