Search in sources :

Example 1 with PLSQLNode

use of net.sourceforge.pmd.lang.plsql.ast.PLSQLNode in project pmd by pmd.

the class PLSQLRuleChainVisitor method indexNodes.

@Override
protected void indexNodes(List<Node> nodes, RuleContext ctx) {
    LOGGER.entering(CLASS_NAME, "indexNodes");
    PLSQLParserVisitor plsqlParserVistor = new PLSQLParserVisitorAdapter() {

        // Perform a visitation of the AST to index nodes which need
        // visiting by type
        @Override
        public Object visit(PLSQLNode node, Object data) {
            indexNode(node);
            return super.visit(node, data);
        }
    };
    for (int i = 0; i < nodes.size(); i++) {
        plsqlParserVistor.visit((ASTInput) nodes.get(i), ctx);
    }
    LOGGER.exiting(CLASS_NAME, "indexNodes");
}
Also used : PLSQLParserVisitor(net.sourceforge.pmd.lang.plsql.ast.PLSQLParserVisitor) PLSQLNode(net.sourceforge.pmd.lang.plsql.ast.PLSQLNode) PLSQLParserVisitorAdapter(net.sourceforge.pmd.lang.plsql.ast.PLSQLParserVisitorAdapter)

Example 2 with PLSQLNode

use of net.sourceforge.pmd.lang.plsql.ast.PLSQLNode in project pmd by pmd.

the class AbstractNcssCountRule method countNodeChildren.

/**
 * Count the number of children of the given PLSQL node. Adds one to count
 * the node itself.
 *
 * @param node
 *            PLSQL 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 = null;
    int lineCount = 0;
    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
        nodeCount = (Integer) ((PLSQLNode) node.jjtGetChild(i)).jjtAccept(this, data);
        lineCount += nodeCount.intValue();
    }
    return ++lineCount;
}
Also used : PLSQLNode(net.sourceforge.pmd.lang.plsql.ast.PLSQLNode) DataPoint(net.sourceforge.pmd.stat.DataPoint)

Example 3 with PLSQLNode

use of net.sourceforge.pmd.lang.plsql.ast.PLSQLNode in project pmd by pmd.

the class AbstractNcssCountRule method visit.

@Override
public Object visit(PLSQLNode node, Object data) {
    int numNodes = 0;
    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
        PLSQLNode n = (PLSQLNode) node.jjtGetChild(i);
        Integer treeSize = (Integer) n.jjtAccept(this, data);
        numNodes += treeSize.intValue();
    }
    if (LOGGER.isLoggable(Level.FINER)) {
        LOGGER.finer("Checking candidate " + node.getClass().getCanonicalName() + " against target class " + nodeClass.getCanonicalName() + " with " + numNodes + " nodes");
    }
    if (this.nodeClass.isInstance(node)) {
        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.fine("Matched candidate " + node.getClass().getCanonicalName() + " against target class " + nodeClass.getCanonicalName());
        }
        // 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);
        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.fine("Running score is " + point.getScore());
        }
    }
    return Integer.valueOf(numNodes);
}
Also used : DataPoint(net.sourceforge.pmd.stat.DataPoint) PLSQLNode(net.sourceforge.pmd.lang.plsql.ast.PLSQLNode) DataPoint(net.sourceforge.pmd.stat.DataPoint)

Example 4 with PLSQLNode

use of net.sourceforge.pmd.lang.plsql.ast.PLSQLNode in project pmd by pmd.

the class NcssObjectCountRule method visit.

/**
 * Override super.visit(PLSQLNode, Object) for ASTProgramUnit nodes, only
 * adding DataPoints for Schema-level Functions and Procedures
 */
@Override
public Object visit(ASTProgramUnit node, Object data) {
    int numNodes = 0;
    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
        PLSQLNode n = (PLSQLNode) node.jjtGetChild(i);
        Integer treeSize = (Integer) n.jjtAccept(this, data);
        numNodes += treeSize.intValue();
    }
    // instances should result in DataPoints
    if (node instanceof OracleObject && node.jjtGetParent() instanceof ASTGlobal) {
        // 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);
        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.fine("Running score is " + point.getScore());
        }
    }
    return Integer.valueOf(numNodes);
}
Also used : OracleObject(net.sourceforge.pmd.lang.plsql.ast.OracleObject) DataPoint(net.sourceforge.pmd.stat.DataPoint) PLSQLNode(net.sourceforge.pmd.lang.plsql.ast.PLSQLNode) DataPoint(net.sourceforge.pmd.stat.DataPoint) ASTGlobal(net.sourceforge.pmd.lang.plsql.ast.ASTGlobal)

Example 5 with PLSQLNode

use of net.sourceforge.pmd.lang.plsql.ast.PLSQLNode in project pmd by pmd.

the class NameFinder method checkForNameChild.

private void checkForNameChild(Node node) {
    if (node.getImage() != null) {
        add(new PLSQLNameOccurrence((PLSQLNode) node, node.getImage()));
    }
    if (node.jjtGetNumChildren() > 0 && node.jjtGetChild(0) instanceof ASTName) {
        ASTName grandchild = (ASTName) node.jjtGetChild(0);
        for (StringTokenizer st = new StringTokenizer(grandchild.getImage(), "."); st.hasMoreTokens(); ) {
            add(new PLSQLNameOccurrence(grandchild, st.nextToken()));
        }
    }
    if (node instanceof ASTPrimarySuffix) {
        ASTPrimarySuffix suffix = (ASTPrimarySuffix) node;
        if (suffix.isArguments()) {
            PLSQLNameOccurrence occurrence = names.get(names.size() - 1);
            occurrence.setIsMethodOrConstructorInvocation();
            ASTArguments args = (ASTArguments) ((ASTPrimarySuffix) node).jjtGetChild(0);
            occurrence.setArgumentCount(args.getArgumentCount());
        }
    // else if (suffix.jjtGetNumChildren() == 1
    // && suffix.jjtGetChild(0) instanceof ASTMemberSelector)
    // {
    // add(new NameOccurrence((SimpleNode)suffix.jjtGetChild(0),
    // suffix.jjtGetChild(0).getImage()));
    // }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) ASTName(net.sourceforge.pmd.lang.plsql.ast.ASTName) PLSQLNode(net.sourceforge.pmd.lang.plsql.ast.PLSQLNode) ASTArguments(net.sourceforge.pmd.lang.plsql.ast.ASTArguments) ASTPrimarySuffix(net.sourceforge.pmd.lang.plsql.ast.ASTPrimarySuffix)

Aggregations

PLSQLNode (net.sourceforge.pmd.lang.plsql.ast.PLSQLNode)17 DataPoint (net.sourceforge.pmd.stat.DataPoint)9 ArrayList (java.util.ArrayList)4 ASTExpression (net.sourceforge.pmd.lang.plsql.ast.ASTExpression)4 Scope (net.sourceforge.pmd.lang.symboltable.Scope)4 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1 AbstractNode (net.sourceforge.pmd.lang.ast.AbstractNode)1 DataFlowNode (net.sourceforge.pmd.lang.dfa.DataFlowNode)1 StartOrEndDataFlowNode (net.sourceforge.pmd.lang.dfa.StartOrEndDataFlowNode)1 ASTArguments (net.sourceforge.pmd.lang.plsql.ast.ASTArguments)1 ASTElseClause (net.sourceforge.pmd.lang.plsql.ast.ASTElseClause)1 ASTGlobal (net.sourceforge.pmd.lang.plsql.ast.ASTGlobal)1 ASTMethodDeclaration (net.sourceforge.pmd.lang.plsql.ast.ASTMethodDeclaration)1 ASTName (net.sourceforge.pmd.lang.plsql.ast.ASTName)1 ASTPrimarySuffix (net.sourceforge.pmd.lang.plsql.ast.ASTPrimarySuffix)1 ASTProgramUnit (net.sourceforge.pmd.lang.plsql.ast.ASTProgramUnit)1 OracleObject (net.sourceforge.pmd.lang.plsql.ast.OracleObject)1