Search in sources :

Example 6 with ASTExpression

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

the class StatementAndBraceFinderTest method testWhileStmtHasCorrectTypes.

@Test
public void testWhileStmtHasCorrectTypes() {
    ASTExpression exp = getOrderedNodes(ASTExpression.class, TEST4).get(0);
    DataFlowNode dfn = exp.getDataFlowNode().getFlow().get(2);
    assertTrue(dfn.isType(NodeType.WHILE_EXPR));
    dfn = exp.getDataFlowNode().getFlow().get(3);
    assertTrue(dfn.isType(NodeType.WHILE_LAST_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 7 with ASTExpression

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

the class StatementAndBraceFinderTest method testIfStmtHasCorrectTypes.

@Test
public void testIfStmtHasCorrectTypes() {
    ASTExpression exp = getOrderedNodes(ASTExpression.class, TEST3).get(0);
    assertEquals(5, exp.getDataFlowNode().getFlow().size());
    DataFlowNode dfn = exp.getDataFlowNode().getFlow().get(2);
    assertTrue(dfn.isType(NodeType.IF_EXPR));
    assertEquals(3, dfn.getLine());
    dfn = exp.getDataFlowNode().getFlow().get(3);
    assertTrue(dfn.isType(NodeType.IF_LAST_STATEMENT_WITHOUT_ELSE));
    assertEquals(3, dfn.getLine());
}
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 8 with ASTExpression

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

the class StatementAndBraceFinderTest method testExpressionParentChildLinks.

/**
 * Java ASTStatementExpression equivalent is inferred as an Expression()
 * which has an UnlabelledStatement as a parent.
 */
@Test
public void testExpressionParentChildLinks() {
    ASTExpression ex = getOrderedNodes(ASTExpression.class, TEST1).get(0);
    DataFlowNode dfn = ex.getDataFlowNode();
    assertEquals(3, dfn.getLine());
    assertTrue(dfn.getNode() instanceof ASTExpression);
    List<DataFlowNode> dfns = dfn.getParents();
    assertEquals(1, dfns.size());
    DataFlowNode parentDfn = dfns.get(0);
    assertEquals(2, parentDfn.getLine());
    assertTrue(parentDfn.getNode() instanceof ASTProgramUnit);
    ASTProgramUnit exParent = (ASTProgramUnit) parentDfn.getNode();
    // Validate the two-way link between Program Unit and Statement
    assertEquals(ex, exParent.getDataFlowNode().getChildren().get(0).getNode());
    assertEquals(exParent, ex.getDataFlowNode().getParents().get(0).getNode());
}
Also used : 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)

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