1 package net.sourceforge.pmd.rules.design;
2
3 import net.sourceforge.pmd.ast.SimpleNode;
4 import net.sourceforge.pmd.stat.DataPoint;
5 import net.sourceforge.pmd.stat.StatisticalRule;
6
7 /***
8 * This is a common super class for things which
9 * 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.getBeginLine()));
29 point.setRule(this);
30 point.setMessage(getMessage());
31 addDataPoint(point);
32 }
33
34 return node.childrenAccept(this, data);
35 }
36 }
37
38
This page was automatically generated by Maven