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