Search in sources :

Example 1 with ApexNode

use of net.sourceforge.pmd.lang.apex.ast.ApexNode in project pmd by pmd.

the class AbstractNcssCountRule method countNodeChildren.

/**
 * Count the number of children of the given node. Adds one to count the
 * node itself.
 *
 * @param node
 *            node having children counted
 * @param data
 *            node data
 * @return count of the number of children of the node, plus one
 */
protected Integer countNodeChildren(Node node, Object data) {
    Integer nodeCount;
    int lineCount = 0;
    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
        nodeCount = (Integer) ((ApexNode<?>) node.jjtGetChild(i)).jjtAccept(this, data);
        lineCount += nodeCount.intValue();
    }
    return ++lineCount;
}
Also used : ApexNode(net.sourceforge.pmd.lang.apex.ast.ApexNode) DataPoint(net.sourceforge.pmd.stat.DataPoint)

Example 2 with ApexNode

use of net.sourceforge.pmd.lang.apex.ast.ApexNode 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

ApexNode (net.sourceforge.pmd.lang.apex.ast.ApexNode)2 DataPoint (net.sourceforge.pmd.stat.DataPoint)2