Search in sources :

Example 11 with DataPoint

use of net.sourceforge.pmd.stat.DataPoint in project pmd by pmd.

the class StatisticalRuleHelper method apply.

public void apply(RuleContext ctx) {
    double deviation;
    double minimum = 0.0;
    if (rule.getProperty(SIGMA_DESCRIPTOR) != null) {
        // TODO - need to come
        // up with a good
        // default value
        deviation = getStdDev();
        double sigma = rule.getProperty(SIGMA_DESCRIPTOR);
        minimum = getMean() + (sigma * deviation);
    }
    if (rule.getProperty(MINIMUM_DESCRIPTOR) != null) {
        // TODO - need to
        // come up with a
        // good default
        // value
        double mMin = rule.getProperty(MINIMUM_DESCRIPTOR);
        if (mMin > minimum) {
            minimum = mMin;
        }
    }
    SortedSet<DataPoint> newPoints = applyMinimumValue(dataPoints, minimum);
    if (rule.getProperty(TOP_SCORE_DESCRIPTOR) != null) {
        // TODO - need to
        // come up with a
        // good default
        // value
        int topScore = rule.getProperty(TOP_SCORE_DESCRIPTOR);
        if (newPoints.size() >= topScore) {
            newPoints = applyTopScore(newPoints, topScore);
        }
    }
    makeViolations(ctx, newPoints);
    double low = 0.0d;
    double high = 0.0d;
    if (!dataPoints.isEmpty()) {
        low = dataPoints.first().getScore();
        high = dataPoints.last().getScore();
    }
    ctx.getReport().addMetric(new Metric(rule.getName(), count, total, low, high, getMean(), getStdDev()));
    dataPoints.clear();
}
Also used : DataPoint(net.sourceforge.pmd.stat.DataPoint) Metric(net.sourceforge.pmd.stat.Metric) DataPoint(net.sourceforge.pmd.stat.DataPoint)

Example 12 with DataPoint

use of net.sourceforge.pmd.stat.DataPoint in project pmd by pmd.

the class SwitchDensityRule method visit.

public Object visit(ASTSwitchStatement node, Object data) {
    SwitchDensity oldData = null;
    if (data instanceof SwitchDensity) {
        oldData = (SwitchDensity) data;
    }
    SwitchDensity density = new SwitchDensity();
    node.childrenAccept(this, density);
    DataPoint point = new DataPoint();
    point.setNode(node);
    point.setScore(density.getDensity());
    point.setMessage(getMessage());
    addDataPoint(point);
    if (data instanceof SwitchDensity) {
        ((SwitchDensity) data).addStatements(density.getStatementCount());
    }
    return oldData;
}
Also used : DataPoint(net.sourceforge.pmd.stat.DataPoint)

Example 13 with DataPoint

use of net.sourceforge.pmd.stat.DataPoint in project pmd by pmd.

the class ExcessiveNodeCountRule method visit.

@Override
public Object visit(JavaNode node, Object data) {
    int numNodes = 0;
    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
        Integer treeSize = (Integer) ((JavaNode) node.jjtGetChild(i)).jjtAccept(this, data);
        numNodes += treeSize;
    }
    if (nodeClass.isInstance(node)) {
        DataPoint point = new DataPoint();
        point.setNode(node);
        point.setScore(1.0 * numNodes);
        point.setMessage(getMessage());
        addDataPoint(point);
    }
    return Integer.valueOf(numNodes);
}
Also used : DataPoint(net.sourceforge.pmd.stat.DataPoint) DataPoint(net.sourceforge.pmd.stat.DataPoint)

Example 14 with DataPoint

use of net.sourceforge.pmd.stat.DataPoint in project pmd by pmd.

the class ExcessiveTemplateLengthRule method visit.

@Override
public Object visit(final ASTprocess node, final Object data) {
    final DataPoint point = new DataPoint();
    point.setNode(node);
    point.setScore(1.0 * (node.getEndLine() - node.getBeginLine()));
    point.setMessage(getMessage());
    addDataPoint(point);
    return node.childrenAccept(this, data);
}
Also used : DataPoint(net.sourceforge.pmd.stat.DataPoint)

Example 15 with DataPoint

use of net.sourceforge.pmd.stat.DataPoint in project pmd by pmd.

the class AbstractNcssCountRule method visit.

@Override
public Object visit(ApexNode<?> node, Object data) {
    int numNodes = 0;
    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
        ApexNode<?> n = (ApexNode<?>) node.jjtGetChild(i);
        Integer treeSize = (Integer) n.jjtAccept(this, data);
        numNodes += treeSize.intValue();
    }
    if (this.nodeClass.isInstance(node)) {
        // Add 1 to account for base node
        numNodes++;
        DataPoint point = new DataPoint();
        point.setNode(node);
        point.setScore(1.0 * numNodes);
        point.setMessage(getMessage());
        addDataPoint(point);
    }
    return Integer.valueOf(numNodes);
}
Also used : DataPoint(net.sourceforge.pmd.stat.DataPoint) ApexNode(net.sourceforge.pmd.lang.apex.ast.ApexNode) DataPoint(net.sourceforge.pmd.stat.DataPoint)

Aggregations

DataPoint (net.sourceforge.pmd.stat.DataPoint)21 TreeSet (java.util.TreeSet)2 PLSQLNode (net.sourceforge.pmd.lang.plsql.ast.PLSQLNode)2 ApexNode (net.sourceforge.pmd.lang.apex.ast.ApexNode)1 JavaNode (net.sourceforge.pmd.lang.java.ast.JavaNode)1 ASTGlobal (net.sourceforge.pmd.lang.plsql.ast.ASTGlobal)1 OracleObject (net.sourceforge.pmd.lang.plsql.ast.OracleObject)1 Metric (net.sourceforge.pmd.stat.Metric)1