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