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