Clover coverage report - PMD - 3.7 Coverage timestamp: Wed May 31 2006 09:25:59 EDT FRAMES NO FRAMES |
file stats: | LOC: | 45 |  | Methods: | 2
| NCLOC: | 36 |  | Classes: | 1
Source file | Conditionals | Statements | Methods | TOTAL
LooseCoupling.java | 100% | 100% | 100% | 100% |

1 |  | /**
2 |  | * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3 |  | */
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 |  |
13 |  | import java.util.HashSet;
14 |  | import java.util.Set;
15 |  |
16 |  | public class LooseCoupling extends AbstractRule {
17 |  |
18 |  | private Set implClassNames = new HashSet();
19 |  |
20 | 2 | public LooseCoupling() {
21 | 2 | super();
22 | 2 | implClassNames.add("HashSet");
23 | 2 | implClassNames.add("HashMap");
24 | 2 | implClassNames.add("LinkedHashMap");
25 | 2 | implClassNames.add("LinkedHashSet");
26 | 2 | implClassNames.add("TreeSet");
27 | 2 | implClassNames.add("TreeMap");
28 | 2 | implClassNames.add("Vector");
29 | 2 | implClassNames.add("java.util.HashSet");
30 | 2 | implClassNames.add("java.util.HashMap");
31 | 2 | implClassNames.add("java.util.LinkedHashMap");
32 | 2 | implClassNames.add("java.util.LinkedHashSet");
33 | 2 | implClassNames.add("java.util.TreeSet");
34 | 2 | implClassNames.add("java.util.TreeMap");
35 | 2 | implClassNames.add("java.util.Vector");
36 |  | }
37 |  |
38 | 18 | public Object visit(ASTClassOrInterfaceType node, Object data) {
39 | 18 | Node parent = node.jjtGetParent().jjtGetParent().jjtGetParent();
40 | 18 | if (implClassNames.contains(node.getImage()) && (parent instanceof ASTFieldDeclaration || parent instanceof ASTFormalParameter || parent instanceof ASTResultType)) {
41 | 8 | addViolation(data, node, node.getImage());
42 |  | }
43 | 18 | return data;
44 |  | }
45 |  | }