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();
}
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;
}
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);
}
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);
}
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);
}
Aggregations