1
2
3
4 package net.sourceforge.pmd.lang.java.rule.coupling;
5
6 import net.sourceforge.pmd.lang.ast.Node;
7 import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType;
8 import net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration;
9 import net.sourceforge.pmd.lang.java.ast.ASTFormalParameter;
10 import net.sourceforge.pmd.lang.java.ast.ASTResultType;
11 import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
12 import net.sourceforge.pmd.util.CollectionUtil;
13
14 public class LooseCouplingRule extends AbstractJavaRule {
15
16
17
18
19
20
21
22
23
24 public Object visit(ASTClassOrInterfaceType node, Object data) {
25 Node parent = node.jjtGetParent().jjtGetParent().jjtGetParent();
26 String typeName = node.getImage();
27 if (CollectionUtil.isCollectionType(typeName, false) && (parent instanceof ASTFieldDeclaration || parent instanceof ASTFormalParameter || parent instanceof ASTResultType)) {
28 addViolation(data, node, typeName);
29 }
30 return data;
31 }
32 }