Search in sources :

Example 11 with DataFlowNode

use of net.sourceforge.pmd.lang.dfa.DataFlowNode in project pmd by pmd.

the class DAAPathFinder method addNodeToTree.

// ----------------------------------------------------------------------------
// TREE FUNCTIONS
/*
     * Adds a PathElement to a Tree, which contains information about loops and
     * "local scopes - encapsulation".
     */
private void addNodeToTree() {
    if (currentPath.isFirstDoStatement()) {
        DefaultMutableTreeNode level = stack;
        DataFlowNode doBranch = currentPath.getDoBranchNodeFromFirstDoStatement();
        while (true) {
            if (level.getChildCount() != 0) {
                PathElement ref = this.isNodeInLevel(level);
                if (ref != null) {
                    this.addRefPseudoPathElement(level, ref);
                    break;
                } else {
                    level = this.getLastChildNode(level);
                    continue;
                }
            } else {
                this.addNewPseudoPathElement(level, doBranch);
                break;
            }
        }
    }
    if (currentPath.isBranch()) {
        DefaultMutableTreeNode level = stack;
        if (currentPath.isDoBranchNode()) {
            while (!this.equalsPseudoPathElementWithDoBranchNodeInLevel(level)) {
                level = this.getLastChildNode(level);
                if (level.getChildCount() == 0) {
                    break;
                }
            }
            PathElement ref = this.getDoBranchNodeInLevel(level);
            if (ref != null) {
                addNode(level, ref);
            } else {
                this.addNewPathElement(level);
            }
        } else {
            while (true) {
                if (level.getChildCount() != 0) {
                    PathElement ref = this.isNodeInLevel(level);
                    if (ref != null) {
                        addNode(level, ref);
                        break;
                    } else {
                        level = this.getLastChildNode(level);
                        continue;
                    }
                } else {
                    this.addNewPathElement(level);
                    break;
                }
            }
        }
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DataFlowNode(net.sourceforge.pmd.lang.dfa.DataFlowNode)

Example 12 with DataFlowNode

use of net.sourceforge.pmd.lang.dfa.DataFlowNode 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));
    assertTrue(dfn.isType(NodeType.WHILE_LAST_STATEMENT));
}
Also used : DataFlowNode(net.sourceforge.pmd.lang.dfa.DataFlowNode) ASTExpression(net.sourceforge.pmd.lang.java.ast.ASTExpression) Test(org.junit.Test)

Example 13 with DataFlowNode

use of net.sourceforge.pmd.lang.dfa.DataFlowNode in project pmd by pmd.

the class DataFlowNodeTest method testSetType.

@Test
public void testSetType() {
    DataFlowNode node = new StartOrEndDataFlowNode(new LinkedList<DataFlowNode>(), 10, false);
    node.setType(NodeType.BREAK_STATEMENT);
    assertTrue(node.isType(NodeType.BREAK_STATEMENT));
    assertFalse(node.isType(NodeType.CASE_LAST_STATEMENT));
}
Also used : StartOrEndDataFlowNode(net.sourceforge.pmd.lang.dfa.StartOrEndDataFlowNode) StartOrEndDataFlowNode(net.sourceforge.pmd.lang.dfa.StartOrEndDataFlowNode) DataFlowNode(net.sourceforge.pmd.lang.dfa.DataFlowNode) Test(org.junit.Test)

Example 14 with DataFlowNode

use of net.sourceforge.pmd.lang.dfa.DataFlowNode in project pmd by pmd.

the class DataFlowNodeTest method testAddPathToChild.

@Test
public void testAddPathToChild() {
    DataFlowNode parent = new StartOrEndDataFlowNode(new LinkedList<DataFlowNode>(), 10, false);
    DataFlowNode child = new StartOrEndDataFlowNode(new LinkedList<DataFlowNode>(), 12, false);
    parent.addPathToChild(child);
    assertEquals(parent.getChildren().size(), 1);
    assertTrue(child.getParents().contains(parent));
    assertTrue(parent.getChildren().contains(child));
}
Also used : StartOrEndDataFlowNode(net.sourceforge.pmd.lang.dfa.StartOrEndDataFlowNode) StartOrEndDataFlowNode(net.sourceforge.pmd.lang.dfa.StartOrEndDataFlowNode) DataFlowNode(net.sourceforge.pmd.lang.dfa.DataFlowNode) Test(org.junit.Test)

Example 15 with DataFlowNode

use of net.sourceforge.pmd.lang.dfa.DataFlowNode in project pmd by pmd.

the class DataFlowNodeTest method testRemovePathToChild.

@Test
public void testRemovePathToChild() {
    DataFlowNode parent = new StartOrEndDataFlowNode(new LinkedList<DataFlowNode>(), 10, false);
    DataFlowNode child = new StartOrEndDataFlowNode(new LinkedList<DataFlowNode>(), 12, false);
    parent.addPathToChild(child);
    assertTrue(parent.removePathToChild(child));
    assertFalse(child.getParents().contains(parent));
    assertFalse(parent.getChildren().contains(child));
}
Also used : StartOrEndDataFlowNode(net.sourceforge.pmd.lang.dfa.StartOrEndDataFlowNode) StartOrEndDataFlowNode(net.sourceforge.pmd.lang.dfa.StartOrEndDataFlowNode) DataFlowNode(net.sourceforge.pmd.lang.dfa.DataFlowNode) Test(org.junit.Test)

Aggregations

DataFlowNode (net.sourceforge.pmd.lang.dfa.DataFlowNode)35 StartOrEndDataFlowNode (net.sourceforge.pmd.lang.dfa.StartOrEndDataFlowNode)17 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)7 VariableAccess (net.sourceforge.pmd.lang.dfa.VariableAccess)6 ASTExpression (net.sourceforge.pmd.lang.plsql.ast.ASTExpression)6 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)4 List (java.util.List)3 Node (net.sourceforge.pmd.lang.ast.Node)3 ASTExpression (net.sourceforge.pmd.lang.java.ast.ASTExpression)3 ASTProgramUnit (net.sourceforge.pmd.lang.plsql.ast.ASTProgramUnit)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 ASTMethodDeclarator (net.sourceforge.pmd.lang.java.ast.ASTMethodDeclarator)2 JavaNode (net.sourceforge.pmd.lang.java.ast.JavaNode)2 PLSQLNode (net.sourceforge.pmd.lang.plsql.ast.PLSQLNode)2 NameOccurrence (net.sourceforge.pmd.lang.symboltable.NameOccurrence)2 Point (org.eclipse.swt.graphics.Point)2 DAAPathFinder (net.sourceforge.pmd.lang.dfa.pathfinder.DAAPathFinder)1