Search in sources :

Example 6 with ASTProgramUnit

use of net.sourceforge.pmd.lang.plsql.ast.ASTProgramUnit 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

ASTProgramUnit (net.sourceforge.pmd.lang.plsql.ast.ASTProgramUnit)6 Test (org.junit.Test)5 DataFlowNode (net.sourceforge.pmd.lang.dfa.DataFlowNode)3 StartOrEndDataFlowNode (net.sourceforge.pmd.lang.dfa.StartOrEndDataFlowNode)3 ASTExpression (net.sourceforge.pmd.lang.plsql.ast.ASTExpression)3 ASTMethodDeclaration (net.sourceforge.pmd.lang.plsql.ast.ASTMethodDeclaration)2 AbstractNode (net.sourceforge.pmd.lang.ast.AbstractNode)1 Linker (net.sourceforge.pmd.lang.dfa.Linker)1 LinkerException (net.sourceforge.pmd.lang.dfa.LinkerException)1 SequenceException (net.sourceforge.pmd.lang.dfa.SequenceException)1 Structure (net.sourceforge.pmd.lang.dfa.Structure)1 ASTTriggerTimingPointSection (net.sourceforge.pmd.lang.plsql.ast.ASTTriggerTimingPointSection)1 ASTTriggerUnit (net.sourceforge.pmd.lang.plsql.ast.ASTTriggerUnit)1 ASTTypeMethod (net.sourceforge.pmd.lang.plsql.ast.ASTTypeMethod)1 ASTVariableOrConstantDeclarator (net.sourceforge.pmd.lang.plsql.ast.ASTVariableOrConstantDeclarator)1 PLSQLNode (net.sourceforge.pmd.lang.plsql.ast.PLSQLNode)1