Clover coverage report - PMD - 3.7
Coverage timestamp: Wed May 31 2006 09:25:59 EDT

file stats: | LOC: | 50 |  | Methods: | 2
| NCLOC: | 25 |  | Classes: | 1

Source file | Conditionals | Statements | Methods | TOTAL

ExcessiveNodeCountRule.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.ast.SimpleJavaNode;
7 |  | import net.sourceforge.pmd.stat.DataPoint;
8 |  | import net.sourceforge.pmd.stat.StatisticalRule;
9 |  |
10 |  | /**
11 |  | * This is a common super class for things which
12 |  | * shouldn't have excessive nodes underneath.
13 |  | * <p/>
14 |  | * It expects all "visit" calls to return an
15 |  | * Integer. It will sum all the values it gets,
16 |  | * and use that as its score.
17 |  | * <p/>
18 |  | * To use it, override the "visit" for the nodes that
19 |  | * need to be counted. On those return "new Integer(1)"
20 |  | * <p/>
21 |  | * All others will return 0 (or the sum of counted nodes
22 |  | * underneath.)
23 |  | */
24 |  |
25 |  | public class ExcessiveNodeCountRule extends StatisticalRule {
26 |  | private Class nodeClass;
27 |  |
28 | 31 | public ExcessiveNodeCountRule(Class nodeClass) {
29 | 31 | this.nodeClass = nodeClass;
30 |  | }
31 |  |
32 | 47 | public Object visit(SimpleJavaNode node, Object data) {
33 | 47 | int numNodes = 0;
34 |  |
35 | 47 | for (int i = 0; i < node.jjtGetNumChildren(); i++) {
36 | 66 | Integer treeSize = (Integer) ((SimpleJavaNode) node.jjtGetChild(i)).jjtAccept(this, data);
37 | 66 | numNodes += treeSize.intValue();
38 |  | }
39 |  |
40 | 47 | if (nodeClass.isInstance(node)) {
41 | 7 | DataPoint point = new DataPoint();
42 | 7 | point.setNode(node);
43 | 7 | point.setScore(1.0 * numNodes);
44 | 7 | point.setMessage(getMessage());
45 | 7 | addDataPoint(point);
46 |  | }
47 |  |
48 | 47 | return new Integer(numNodes);
49 |  | }
50 |  | }