|
1 |
| |
|
2 |
| |
|
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 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| public class ExcessiveNodeCountRule extends StatisticalRule { |
|
26 |
| private Class nodeClass; |
|
27 |
| |
|
28 |
30
| public ExcessiveNodeCountRule(Class nodeClass) {
|
|
29 |
30
| this.nodeClass = nodeClass;
|
|
30 |
| } |
|
31 |
| |
|
32 |
192
| public Object visit(SimpleJavaNode node, Object data) {
|
|
33 |
192
| int numNodes = 0;
|
|
34 |
| |
|
35 |
192
| for (int i = 0; i < node.jjtGetNumChildren(); i++) {
|
|
36 |
223
| Integer treeSize = (Integer) ((SimpleJavaNode) node.jjtGetChild(i)).jjtAccept(this, data);
|
|
37 |
223
| numNodes += treeSize.intValue();
|
|
38 |
| } |
|
39 |
| |
|
40 |
192
| if (nodeClass.isInstance(node)) {
|
|
41 |
12
| DataPoint point = new DataPoint();
|
|
42 |
12
| point.setNode(node);
|
|
43 |
12
| point.setScore(1.0 * numNodes);
|
|
44 |
12
| point.setMessage(getMessage());
|
|
45 |
12
| addDataPoint(point);
|
|
46 |
| } |
|
47 |
| |
|
48 |
192
| return new Integer(numNodes);
|
|
49 |
| } |
|
50 |
| } |