Search in sources :

Example 1 with ASTExpression

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

the class StatementAndBraceFinder method addForExpressionNode.

/*
     * The method handles the special "for" loop. It creates always an
     * expression node even if the loop looks like for(;;).
     */
// TODO: dfa implementation in plsql is incomplete
@SuppressWarnings("PMD.UnusedFormalParameter")
private void addForExpressionNode(Node node, Structure dataFlow) {
    ASTForStatement parent = (ASTForStatement) node.jjtGetParent();
    boolean hasExpressionChild = false;
    for (int i = 0; i < parent.jjtGetNumChildren(); i++) {
        if (parent.jjtGetChild(i) instanceof ASTExpression) {
            hasExpressionChild = true;
        }
    }
    if (!hasExpressionChild) {
        if (node instanceof ASTStatement) {
        /*
                 * if (!hasForInitNode && !hasForUpdateNode) {
                 * dataFlow.createNewNode(node);
                 * dataFlow.pushOnStack(NodeType.FOR_EXPR, dataFlow.getLast());
                 * }
                 */
        }
    }
}
Also used : ASTForStatement(net.sourceforge.pmd.lang.plsql.ast.ASTForStatement) ASTStatement(net.sourceforge.pmd.lang.plsql.ast.ASTStatement) ASTExpression(net.sourceforge.pmd.lang.plsql.ast.ASTExpression)

Example 2 with ASTExpression

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

the class StatementAndBraceFinderTest method testSimpleCaseStmtHasCorrectTypes.

@Test
public void testSimpleCaseStmtHasCorrectTypes() {
    ASTExpression exp = getOrderedNodes(ASTExpression.class, TEST6).get(0);
    DataFlowNode dfn = null;
    dfn = exp.getDataFlowNode().getFlow().get(0);
    assertTrue(dfn instanceof StartOrEndDataFlowNode);
    dfn = exp.getDataFlowNode().getFlow().get(1);
    assertEquals(2, dfn.getLine());
    assertTrue(dfn.getNode() instanceof ASTProgramUnit);
    dfn = exp.getDataFlowNode().getFlow().get(2);
    assertEquals(4, dfn.getLine());
    assertTrue(dfn.isType(NodeType.SWITCH_START));
    assertTrue(dfn.isType(NodeType.CASE_LAST_STATEMENT));
    dfn = exp.getDataFlowNode().getFlow().get(3);
    assertEquals(5, dfn.getLine());
    assertTrue(dfn.isType(NodeType.CASE_LAST_STATEMENT));
    assertTrue(dfn.isType(NodeType.BREAK_STATEMENT));
    dfn = exp.getDataFlowNode().getFlow().get(4);
    assertEquals(6, dfn.getLine());
    assertTrue(dfn.isType(NodeType.SWITCH_LAST_DEFAULT_STATEMENT));
    assertTrue(dfn.isType(NodeType.BREAK_STATEMENT));
    dfn = exp.getDataFlowNode().getFlow().get(5);
    assertEquals(7, dfn.getLine());
    assertTrue(dfn.isType(NodeType.SWITCH_END));
}
Also used : StartOrEndDataFlowNode(net.sourceforge.pmd.lang.dfa.StartOrEndDataFlowNode) DataFlowNode(net.sourceforge.pmd.lang.dfa.DataFlowNode) StartOrEndDataFlowNode(net.sourceforge.pmd.lang.dfa.StartOrEndDataFlowNode) ASTProgramUnit(net.sourceforge.pmd.lang.plsql.ast.ASTProgramUnit) ASTExpression(net.sourceforge.pmd.lang.plsql.ast.ASTExpression) Test(org.junit.Test)

Example 3 with ASTExpression

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

the class StatementAndBraceFinderTest method testLabelledStmtHasCorrectTypes.

/*
     * @Test public void testSearchedCaseStmtHasCorrectTypes()
     * { List<ASTStatement> statements = getOrderedNodes(ASTStatement.class,
     * TEST7); List<ASTExpression> expressions =
     * getOrderedNodes(ASTExpression.class, TEST7);
     * 
     * ASTStatement st = statements.get(0); ASTStatement st1 =
     * statements.get(1); ASTStatement st2 = statements.get(2); ASTStatement st3
     * = statements.get(3);
     * System.err.println("testSearchedCaseStmtHasCorrectTypes-st(0)="+st.
     * getBeginLine());
     * 
     * ASTExpression ex = expressions.get(0); ASTExpression ex1 =
     * expressions.get(1); ASTExpression ex2 = expressions.get(2); ASTExpression
     * ex3 = expressions.get(3); ASTExpression ex4 = expressions.get(4);
     * System.err.println("ASTExpression="+ex );
     * 
     * DataFlowNode dfn = null; //dfn = ex.getDataFlowNode().getFlow().get(0);
     * //dfn = st.getDataFlowNode().getFlow().get(0); dfn = (DataFlowNode)
     * st.getDataFlowNode(); System.err.println("DataFlowNode(st-0)="+dfn ) ;
     * System.err.println("DataFlowNode(st-1)="+st1.getDataFlowNode() ) ;
     * System.err.println("DataFlowNode(st-2)="+st2.getDataFlowNode() ) ;
     * System.err.println("DataFlowNode(st-3)="+st3.getDataFlowNode() ) ;
     * 
     * System.err.println("DataFlowNode(ex-0)="+ex.getDataFlowNode() ) ;
     * System.err.println("DataFlowNode(ex-1)="+ex1.getDataFlowNode() ) ;
     * System.err.println("DataFlowNode(ex-2)="+ex2.getDataFlowNode() ) ;
     * System.err.println("DataFlowNode(ex-3)="+ex3.getDataFlowNode() ) ;
     * System.err.println("DataFlowNode(ex-4)="+ex4.getDataFlowNode() ) ;
     * List<DataFlowNode> dfns = dfn.getFlow();
     * System.err.println("DataFlowNodes List size="+dfns.size()) ; DataFlowNode
     * firstDfn = dfns.get(0); System.err.println("firstDataFlowNode="+firstDfn
     * ) ;
     * System.err.println("testSearchedCaseStmtHasCorrectTypes-dfn(0)="+dfn);
     * dfn = st.getDataFlowNode().getFlow().get(1);
     * System.err.println("testSearchedCaseStmtHasCorrectTypes-dfn(1)="+dfn);
     * dfn = st.getDataFlowNode().getFlow().get(2);
     * System.err.println("testSearchedCaseStmtHasCorrectTypes-dfn(2)="+dfn);
     * assertTrue(dfn.isType(NodeType.SWITCH_START)); dfn =
     * st.getDataFlowNode().getFlow().get(3);
     * System.err.println("testSearchedCaseStmtHasCorrectTypes-dfn(3)="+dfn);
     * assertTrue(dfn.isType(NodeType.CASE_LAST_STATEMENT)); //dfn =
     * st.getDataFlowNode().getFlow().get(4);
     * System.err.println("testSearchedCaseStmtHasCorrectTypes-dfn(5)="+dfn);
     * assertTrue(dfn.isType(NodeType.CASE_LAST_STATEMENT)); dfn =
     * st.getDataFlowNode().getFlow().get(5);
     * System.err.println("testSearchedCaseStmtHasCorrectTypes-dfn(7)="+dfn);
     * assertTrue(dfn.isType(NodeType.SWITCH_LAST_DEFAULT_STATEMENT)); dfn =
     * st.getDataFlowNode().getFlow().get(6);
     * System.err.println("testSearchedCaseStmtHasCorrectTypes-dfn(8)="+dfn);
     * assertTrue(dfn.isType(NodeType.SWITCH_END)); }
     */
@Test
public void testLabelledStmtHasCorrectTypes() {
    ASTExpression exp = getOrderedNodes(ASTExpression.class, TEST8).get(0);
    DataFlowNode dfn = exp.getDataFlowNode().getFlow().get(2);
    assertEquals(3, dfn.getLine());
    assertTrue(dfn.isType(NodeType.LABEL_STATEMENT));
}
Also used : DataFlowNode(net.sourceforge.pmd.lang.dfa.DataFlowNode) StartOrEndDataFlowNode(net.sourceforge.pmd.lang.dfa.StartOrEndDataFlowNode) ASTExpression(net.sourceforge.pmd.lang.plsql.ast.ASTExpression) Test(org.junit.Test)

Example 4 with ASTExpression

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

the class StatementAndBraceFinderTest method testForStmtHasCorrectTypes.

@Test
public void testForStmtHasCorrectTypes() {
    ASTExpression exp = getOrderedNodes(ASTExpression.class, TEST5).get(0);
    DataFlowNode dfn = null;
    dfn = exp.getDataFlowNode().getFlow().get(0);
    assertTrue(dfn instanceof StartOrEndDataFlowNode);
    dfn = exp.getDataFlowNode().getFlow().get(1);
    assertTrue(dfn.getNode() instanceof ASTProgramUnit);
    assertEquals(2, dfn.getLine());
    dfn = exp.getDataFlowNode().getFlow().get(2);
    assertEquals(3, dfn.getLine());
    assertTrue(dfn.isType(NodeType.FOR_EXPR));
    assertTrue(dfn.isType(NodeType.FOR_BEFORE_FIRST_STATEMENT));
    dfn = exp.getDataFlowNode().getFlow().get(3);
    assertEquals(3, dfn.getLine());
    assertTrue(dfn.isType(NodeType.FOR_END));
}
Also used : StartOrEndDataFlowNode(net.sourceforge.pmd.lang.dfa.StartOrEndDataFlowNode) DataFlowNode(net.sourceforge.pmd.lang.dfa.DataFlowNode) StartOrEndDataFlowNode(net.sourceforge.pmd.lang.dfa.StartOrEndDataFlowNode) ASTProgramUnit(net.sourceforge.pmd.lang.plsql.ast.ASTProgramUnit) ASTExpression(net.sourceforge.pmd.lang.plsql.ast.ASTExpression) Test(org.junit.Test)

Example 5 with ASTExpression

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

the class NPathComplexityRule method visit.

@Override
public Object visit(ASTReturnStatement node, Object data) {
    LOGGER.entering(CLASS_NAME, "visit(ASTReturnStatement)");
    // return statements are valued at 1, or the value of the boolean
    // expression
    ASTExpression expr = node.getFirstChildOfType(ASTExpression.class);
    if (expr == null) {
        return NumericConstants.ONE;
    }
    int boolCompReturn = sumExpressionComplexity(expr);
    int conditionalExpressionComplexity = complexityMultipleOf(expr, 1, data);
    if (conditionalExpressionComplexity > 1) {
        boolCompReturn += conditionalExpressionComplexity;
    }
    if (boolCompReturn > 0) {
        return Integer.valueOf(boolCompReturn);
    }
    LOGGER.entering(CLASS_NAME, "visit(ASTReturnStatement)", NumericConstants.ONE);
    return NumericConstants.ONE;
}
Also used : DataPoint(net.sourceforge.pmd.stat.DataPoint) ASTExpression(net.sourceforge.pmd.lang.plsql.ast.ASTExpression)

Aggregations

ASTExpression (net.sourceforge.pmd.lang.plsql.ast.ASTExpression)8 DataFlowNode (net.sourceforge.pmd.lang.dfa.DataFlowNode)6 StartOrEndDataFlowNode (net.sourceforge.pmd.lang.dfa.StartOrEndDataFlowNode)6 Test (org.junit.Test)6 ASTProgramUnit (net.sourceforge.pmd.lang.plsql.ast.ASTProgramUnit)3 ASTForStatement (net.sourceforge.pmd.lang.plsql.ast.ASTForStatement)1 ASTStatement (net.sourceforge.pmd.lang.plsql.ast.ASTStatement)1 DataPoint (net.sourceforge.pmd.stat.DataPoint)1