Clover coverage report - PMD - 3.9 Coverage timestamp: Tue Dec 19 2006 09:38:44 EST FRAMES NO FRAMES |
file stats: | LOC: | 61 |  | Methods: | 4
| NCLOC: | 47 |  | Classes: | 1
Source file | Conditionals | Statements | Methods | TOTAL
MoreThanOneLogger.java | 60% | 89.5% | 75% | 78.8% |

1 |  | package net.sourceforge.pmd.rules;
2 |  |
3 |  | import java.util.Stack;
4 |  |
5 |  | import net.sourceforge.pmd.AbstractRule;
6 |  | import net.sourceforge.pmd.ast.ASTClassOrInterfaceDeclaration;
7 |  | import net.sourceforge.pmd.ast.ASTClassOrInterfaceType;
8 |  | import net.sourceforge.pmd.ast.ASTEnumDeclaration;
9 |  | import net.sourceforge.pmd.ast.ASTReferenceType;
10 |  | import net.sourceforge.pmd.ast.ASTType;
11 |  | import net.sourceforge.pmd.ast.ASTVariableDeclarator;
12 |  | import net.sourceforge.pmd.ast.SimpleJavaNode;
13 |  | import net.sourceforge.pmd.ast.SimpleNode;
14 |  |
15 |  | public class MoreThanOneLogger extends AbstractRule {
16 |  |
17 |  | private Stack stack = new Stack();
18 |  |
19 |  | private Integer count;
20 |  |
21 | 4 | public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
22 | 4 | return init (node, data);
23 |  | }
24 |  |
25 | 0 | public Object visit(ASTEnumDeclaration node, Object data) {
26 | 0 | return init (node, data);
27 |  | }
28 |  |
29 | 4 | private Object init(SimpleJavaNode node, Object data) {
30 | 4 | stack.push(count);
31 | 4 | count = new Integer(0);
32 |  |
33 | 4 | node.childrenAccept(this, data);
34 |  |
35 | 4 | if (count.intValue() > 1) {
36 | 1 | addViolation(data, node);
37 |  | }
38 | 4 | count = (Integer) stack.pop();
39 |  |
40 | 4 | return data;
41 |  | }
42 |  |
43 | 5 | public Object visit(ASTVariableDeclarator node, Object data) {
44 | 5 | if (count.intValue() > 1) {
45 | 0 | return super.visit(node, data);
46 |  | }
47 | 5 | SimpleNode type = (SimpleNode) ((SimpleNode) node.jjtGetParent()).getFirstChildOfType(ASTType.class);
48 | 5 | if (type != null) {
49 | 5 | SimpleNode reftypeNode = (SimpleNode) type.jjtGetChild(0);
50 | 5 | if (reftypeNode instanceof ASTReferenceType) {
51 | 5 | SimpleNode classOrIntType = (SimpleNode) reftypeNode.jjtGetChild(0);
52 | 5 | if (classOrIntType instanceof ASTClassOrInterfaceType && "Logger".equals(classOrIntType.getImage())) {
53 | 5 | count = new Integer(count.intValue()+1);
54 |  | }
55 |  | }
56 |  | }
57 |  |
58 | 5 | return super.visit(node, data);
59 |  | }
60 |  |
61 |  | }