Search in sources :

Example 6 with PLSQLNode

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

the class StatementAndBraceFinderTest method testOnlyWorksForMethodsAndConstructors.

@Test
public void testOnlyWorksForMethodsAndConstructors() {
    StatementAndBraceFinder sbf = new StatementAndBraceFinder(LanguageRegistry.getLanguage(PLSQLLanguageModule.NAME).getDefaultVersion().getLanguageVersionHandler().getDataFlowHandler());
    PLSQLNode node = new ASTMethodDeclaration(1);
    ((AbstractNode) node).testingOnlySetBeginColumn(1);
    sbf.buildDataFlowFor(node);
    // sbf.buildDataFlowFor(new ASTConstructorDeclaration(1));
    node = new ASTProgramUnit(1);
    ((AbstractNode) node).testingOnlySetBeginColumn(1);
    sbf.buildDataFlowFor(node);
}
Also used : ASTMethodDeclaration(net.sourceforge.pmd.lang.plsql.ast.ASTMethodDeclaration) AbstractNode(net.sourceforge.pmd.lang.ast.AbstractNode) PLSQLNode(net.sourceforge.pmd.lang.plsql.ast.PLSQLNode) ASTProgramUnit(net.sourceforge.pmd.lang.plsql.ast.ASTProgramUnit) Test(org.junit.Test)

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

Example 8 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(ASTElsifClause node, Object data) {
    LOGGER.entering(CLASS_NAME, "visit(ASTElsifClause)");
    // (npath of if + npath of else (or 1) + bool_comp of if) * npath of
    // next
    int boolCompIf = sumExpressionComplexity(node.getFirstChildOfType(ASTExpression.class));
    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 ELSIF statement " + node.getBeginLine() + ", column " + node.getBeginColumn());
    }
    for (PLSQLNode element : statementChildren) {
        complexity += (Integer) element.jjtAccept(this, data);
    }
    LOGGER.exiting(CLASS_NAME, "visit(ASTElsifClause)", boolCompIf + complexity);
    return Integer.valueOf(boolCompIf + complexity);
}
Also used : ArrayList(java.util.ArrayList) PLSQLNode(net.sourceforge.pmd.lang.plsql.ast.PLSQLNode) DataPoint(net.sourceforge.pmd.stat.DataPoint) ASTExpression(net.sourceforge.pmd.lang.plsql.ast.ASTExpression)

Example 9 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(ASTCaseWhenClause node, Object data) {
    LOGGER.entering(CLASS_NAME, "visit(ASTCaseWhenClause)");
    // bool_comp of switch + sum(npath(case_range))
    int boolCompSwitch = sumExpressionComplexity(node.getFirstChildOfType(ASTExpression.class));
    int npath = 1;
    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(ASTCaseWhenClause)", 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 10 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(ASTPackageBody 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