Search in sources :

Example 11 with PLSQLNode

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

the class VariableAccessVisitor method collectDeclarations.

private Set<Map<NameDeclaration, List<NameOccurrence>>> collectDeclarations(DataFlowNode inode) {
    Set<Map<NameDeclaration, List<NameOccurrence>>> decls = new HashSet<>();
    Map<NameDeclaration, List<NameOccurrence>> varDecls;
    for (int i = 0; i < inode.getFlow().size(); i++) {
        DataFlowNode n = inode.getFlow().get(i);
        if (n instanceof StartOrEndDataFlowNode) {
            continue;
        }
        varDecls = ((PLSQLNode) n.getNode()).getScope().getDeclarations();
        if (!decls.contains(varDecls)) {
            decls.add(varDecls);
        }
    }
    return decls;
}
Also used : StartOrEndDataFlowNode(net.sourceforge.pmd.lang.dfa.StartOrEndDataFlowNode) DataFlowNode(net.sourceforge.pmd.lang.dfa.DataFlowNode) StartOrEndDataFlowNode(net.sourceforge.pmd.lang.dfa.StartOrEndDataFlowNode) PLSQLNode(net.sourceforge.pmd.lang.plsql.ast.PLSQLNode) ArrayList(java.util.ArrayList) List(java.util.List) NameDeclaration(net.sourceforge.pmd.lang.symboltable.NameDeclaration) Map(java.util.Map) PLSQLNameOccurrence(net.sourceforge.pmd.lang.plsql.symboltable.PLSQLNameOccurrence) NameOccurrence(net.sourceforge.pmd.lang.symboltable.NameOccurrence) HashSet(java.util.HashSet)

Example 12 with PLSQLNode

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

the class NPathComplexityRule method complexityMultipleOf.

private int complexityMultipleOf(PLSQLNode node, int npathStart, Object data) {
    LOGGER.entering(CLASS_NAME, "complexityMultipleOf(SimpleNode)");
    int npath = npathStart;
    PLSQLNode n;
    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
        n = (PLSQLNode) node.jjtGetChild(i);
        npath *= (Integer) n.jjtAccept(this, data);
    }
    LOGGER.exiting(CLASS_NAME, "complexityMultipleOf(SimpleNode)", npath);
    return npath;
}
Also used : PLSQLNode(net.sourceforge.pmd.lang.plsql.ast.PLSQLNode) DataPoint(net.sourceforge.pmd.stat.DataPoint)

Example 13 with PLSQLNode

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

the class NPathComplexityRule method visit.

@Override
public Object visit(ASTElseClause node, Object data) {
    LOGGER.entering(CLASS_NAME, "visit(ASTElseClause)");
    // (npath of if + npath of else (or 1) + bool_comp of if) * npath of
    // next
    int complexity = 0;
    List<PLSQLNode> statementChildren = new ArrayList<>();
    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
        if (node.jjtGetChild(i).getClass() == ASTStatement.class) {
            statementChildren.add((PLSQLNode) node.jjtGetChild(i));
        }
    }
    if (LOGGER.isLoggable(Level.FINEST)) {
        LOGGER.finest(statementChildren.size() + " statementChildren found for ELSE clause statement " + node.getBeginLine() + ", column " + node.getBeginColumn());
    }
    for (PLSQLNode element : statementChildren) {
        complexity += (Integer) element.jjtAccept(this, data);
    }
    LOGGER.exiting(CLASS_NAME, "visit(ASTElseClause)", complexity);
    return Integer.valueOf(complexity);
}
Also used : ArrayList(java.util.ArrayList) PLSQLNode(net.sourceforge.pmd.lang.plsql.ast.PLSQLNode) DataPoint(net.sourceforge.pmd.stat.DataPoint)

Example 14 with PLSQLNode

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

the class NPathComplexityRule method visit.

@Override
public Object visit(ASTCaseStatement node, Object data) {
    LOGGER.entering(CLASS_NAME, "visit(ASTCaseStatement)");
    // bool_comp of switch + sum(npath(case_range))
    int boolCompSwitch = sumExpressionComplexity(node.getFirstChildOfType(ASTExpression.class));
    int npath = 0;
    int caseRange = 0;
    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
        PLSQLNode n = (PLSQLNode) node.jjtGetChild(i);
        // Fall-through labels count as 1 for complexity
        Integer complexity = (Integer) n.jjtAccept(this, data);
        caseRange *= complexity;
    }
    // add in npath of last label
    npath += caseRange;
    LOGGER.exiting(CLASS_NAME, "visit(ASTCaseStatement)", boolCompSwitch + npath);
    return Integer.valueOf(boolCompSwitch + npath);
}
Also used : PLSQLNode(net.sourceforge.pmd.lang.plsql.ast.PLSQLNode) DataPoint(net.sourceforge.pmd.stat.DataPoint) ASTExpression(net.sourceforge.pmd.lang.plsql.ast.ASTExpression)

Example 15 with PLSQLNode

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

the class ScopeAndDeclarationFinder method visit.

@Override
public Object visit(ASTPackageSpecification node, Object data) {
    createClassScope(node);
    Scope s = ((PLSQLNode) node.jjtGetParent()).getScope();
    s.addDeclaration(new ClassNameDeclaration(node));
    cont(node);
    return data;
}
Also used : Scope(net.sourceforge.pmd.lang.symboltable.Scope) PLSQLNode(net.sourceforge.pmd.lang.plsql.ast.PLSQLNode)

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