1
2
3
4 package net.sourceforge.pmd.lang.plsql.rule.design;
5
6 import java.util.logging.Logger;
7
8 import net.sourceforge.pmd.lang.plsql.ast.PLSQLNode;
9 import net.sourceforge.pmd.lang.plsql.rule.AbstractStatisticalPLSQLRule;
10 import net.sourceforge.pmd.stat.DataPoint;
11
12
13
14
15
16
17
18
19
20
21
22 public class ExcessiveLengthRule extends AbstractStatisticalPLSQLRule {
23 private final static Logger LOGGER = Logger.getLogger(ExcessiveLengthRule.class.getName());
24 private Class<?> nodeClass;
25
26 public ExcessiveLengthRule(Class<?> nodeClass) {
27 this.nodeClass = nodeClass;
28 }
29
30 @Override
31 public Object visit(PLSQLNode node, Object data) {
32
33 LOGGER.finest("SimpleNode: line " + node.getBeginLine() +", column " + node.getBeginColumn()
34 + " - is node " + node.getClass().getCanonicalName()
35 + " instanceof " + this.nodeClass.getClass().getCanonicalName()
36 );
37 if (nodeClass.isInstance(node)) {
38 LOGGER.finest("SimpleNode: YES node " + node.getClass().getCanonicalName()
39 + " IS instanceof " + this.nodeClass.getClass().getCanonicalName()
40 + " with length == (" + node.getEndLine() + " - " + node.getBeginLine()
41 + " == " + (node.getEndLine() - node.getBeginLine())
42 );
43 DataPoint point = new DataPoint();
44 point.setNode(node);
45 point.setScore(1.0 * (node.getEndLine() - node.getBeginLine()));
46 point.setMessage(getMessage());
47 addDataPoint(point);
48 LOGGER.fine("SimpleNode: Score " + point.getScore() + " for " + this.nodeClass.getCanonicalName() ) ;
49 }
50
51
52 return node.childrenAccept(this, data);
53 }
54
55 @Override
56 public Object[] getViolationParameters(DataPoint point) {
57 return new String[] { String.valueOf((int) point.getScore()) };
58 }
59 }