01: package org.acm.seguin.pmd.rules.design;
02:
03: import net.sourceforge.jrefactory.ast.SimpleNode;
04: import org.acm.seguin.pmd.stat.DataPoint;
05: import org.acm.seguin.pmd.stat.StatisticalRule;
06:
07: /**
08: * This is a common super class for things which
09: * have excessive length.
10: *
11: * i.e. LongMethod and LongClass rules.
12: *
13: * To implement an ExcessiveLength rule, you pass
14: * in the Class of node you want to check, and this
15: * does the rest for you.
16: */
17: public class ExcessiveLengthRule extends StatisticalRule {
18: private Class nodeClass;
19:
20: public ExcessiveLengthRule(Class nodeClass) {
21: this .nodeClass = nodeClass;
22: }
23:
24: public Object visit(SimpleNode node, Object data) {
25: if (nodeClass.isInstance(node)) {
26: DataPoint point = new DataPoint();
27: point.setLineNumber(node.getBeginLine());
28: point.setScore(1.0 * (node.getEndLine() - node
29: .getBeginLine()));
30: point.setRule(this);
31: point.setMessage(getMessage());
32: addDataPoint(point);
33: }
34:
35: return node.childrenAccept(this, data);
36: }
37: }
|