Search in sources :

Example 1 with ASTProgramUnit

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

the class StatementAndBraceFinder method buildDataFlowFor.

public void buildDataFlowFor(PLSQLNode node) {
    LOGGER.entering(this.getClass().getCanonicalName(), "buildDataFlowFor");
    if (LOGGER.isLoggable(Level.FINEST)) {
        LOGGER.finest("buildDataFlowFor: node class " + node.getClass().getCanonicalName() + " @ line " + node.getBeginLine() + ", column " + node.getBeginColumn() + " --- " + new Throwable().getStackTrace());
    }
    if (!(node instanceof ASTMethodDeclaration) && !(node instanceof ASTProgramUnit) && !(node instanceof ASTTypeMethod) && !(node instanceof ASTTriggerUnit) && !(node instanceof ASTTriggerTimingPointSection)) {
        throw new RuntimeException("Can't build a data flow for anything other than a Method or a Trigger");
    }
    this.dataFlow = new Structure(dataFlowHandler);
    this.dataFlow.createStartNode(node.getBeginLine());
    this.dataFlow.createNewNode(node);
    node.jjtAccept(this, dataFlow);
    this.dataFlow.createEndNode(node.getEndLine());
    if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.fine("DataFlow is " + this.dataFlow.dump());
    }
    Linker linker = new Linker(dataFlowHandler, dataFlow.getBraceStack(), dataFlow.getContinueBreakReturnStack());
    try {
        linker.computePaths();
    } catch (LinkerException e) {
        LOGGER.severe("LinkerException");
        e.printStackTrace();
    } catch (SequenceException e) {
        LOGGER.severe("SequenceException");
        e.printStackTrace();
    }
    LOGGER.exiting(this.getClass().getCanonicalName(), "buildDataFlowFor");
}
Also used : ASTTypeMethod(net.sourceforge.pmd.lang.plsql.ast.ASTTypeMethod) LinkerException(net.sourceforge.pmd.lang.dfa.LinkerException) ASTTriggerUnit(net.sourceforge.pmd.lang.plsql.ast.ASTTriggerUnit) ASTMethodDeclaration(net.sourceforge.pmd.lang.plsql.ast.ASTMethodDeclaration) SequenceException(net.sourceforge.pmd.lang.dfa.SequenceException) ASTTriggerTimingPointSection(net.sourceforge.pmd.lang.plsql.ast.ASTTriggerTimingPointSection) Structure(net.sourceforge.pmd.lang.dfa.Structure) Linker(net.sourceforge.pmd.lang.dfa.Linker) ASTProgramUnit(net.sourceforge.pmd.lang.plsql.ast.ASTProgramUnit)

Example 2 with ASTProgramUnit

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

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

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

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

the class StatementAndBraceFinderTest method testVariableOrConstantDeclaratorParentChildLinks.

@Test
public void testVariableOrConstantDeclaratorParentChildLinks() {
    ASTVariableOrConstantDeclarator vd = getOrderedNodes(ASTVariableOrConstantDeclarator.class, TEST2).get(0);
    // ASTMethodDeclaration vdParent = (ASTMethodDeclaration)
    // ((DataFlowNode) vd.getDataFlowNode().getParents().get(0)).getNode();
    ASTProgramUnit vdParent = (ASTProgramUnit) vd.getDataFlowNode().getParents().get(0).getNode();
    // Validate the two-way link between Program Unit and Variable
    assertEquals(vd, vdParent.getDataFlowNode().getChildren().get(0).getNode());
    assertEquals(vdParent, vd.getDataFlowNode().getParents().get(0).getNode());
}
Also used : ASTVariableOrConstantDeclarator(net.sourceforge.pmd.lang.plsql.ast.ASTVariableOrConstantDeclarator) ASTProgramUnit(net.sourceforge.pmd.lang.plsql.ast.ASTProgramUnit) 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