Search in sources :

Example 26 with DataFlowNode

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

the class AcceptanceTest method check.

private boolean check(int[][] array, List<ASTMethodDeclarator> methodNodes) {
    for (int i = 0; i < methodNodes.size(); i++) {
        ASTMethodDeclarator decl = methodNodes.get(i);
        DataFlowNode inode = decl.getDataFlowNode();
        for (int j = 0; j < inode.getChildren().size(); j++) {
            DataFlowNode child = inode.getChildren().get(j);
            if (array[i][j] != child.getIndex() - 1) {
                return false;
            }
        }
    }
    return true;
}
Also used : ASTMethodDeclarator(net.sourceforge.pmd.lang.java.ast.ASTMethodDeclarator) DataFlowNode(net.sourceforge.pmd.lang.dfa.DataFlowNode)

Example 27 with DataFlowNode

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

the class DataFlowNodeTest method testRemovePathWithNonChild.

@Test
public void testRemovePathWithNonChild() {
    DataFlowNode parent = new StartOrEndDataFlowNode(new LinkedList<DataFlowNode>(), 10, false);
    DataFlowNode child = new StartOrEndDataFlowNode(new LinkedList<DataFlowNode>(), 12, false);
    assertFalse(parent.removePathToChild(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 28 with DataFlowNode

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

the class DataFlowNodeTest method testReverseParentPathsTo.

@Test
public void testReverseParentPathsTo() {
    DataFlowNode parent1 = new StartOrEndDataFlowNode(new LinkedList<DataFlowNode>(), 10, false);
    DataFlowNode parent2 = new StartOrEndDataFlowNode(new LinkedList<DataFlowNode>(), 12, false);
    DataFlowNode child1 = new StartOrEndDataFlowNode(new LinkedList<DataFlowNode>(), 13, false);
    DataFlowNode child2 = new StartOrEndDataFlowNode(new LinkedList<DataFlowNode>(), 13, false);
    parent1.addPathToChild(child1);
    parent2.addPathToChild(child1);
    assertTrue(parent1.getChildren().contains(child1));
    child1.reverseParentPathsTo(child2);
    assertTrue(parent1.getChildren().contains(child2));
    assertFalse(parent1.getChildren().contains(child1));
    assertTrue(parent2.getChildren().contains(child2));
    assertFalse(parent2.getChildren().contains(child1));
    assertEquals(0, child1.getParents().size());
    assertEquals(2, child2.getParents().size());
}
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 29 with DataFlowNode

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

the class GeneralFiddlingTest method test1.

@Test
public void test1() {
    ASTCompilationUnit acu = buildDFA(TEST1);
    ASTMethodDeclarator meth = acu.findDescendantsOfType(ASTMethodDeclarator.class).get(0);
    DataFlowNode n = meth.getDataFlowNode();
    List<DataFlowNode> f = n.getFlow();
    assertEquals(6, f.size());
    assertEquals("Undefinition(x)", String.valueOf(f.get(0).getVariableAccess().get(0)));
    assertEquals(0, f.get(1).getVariableAccess().size());
    assertEquals("Definition(x)", String.valueOf(f.get(2).getVariableAccess().get(0)));
    assertEquals("Reference(x)", String.valueOf(f.get(3).getVariableAccess().get(0)));
    assertEquals("Definition(x)", String.valueOf(f.get(4).getVariableAccess().get(0)));
    assertEquals("Undefinition(x)", String.valueOf(f.get(5).getVariableAccess().get(0)));
// for (DataFlowNode dfan : f) {
// System.out.println("Flow starting on line " + dfan.getLine());
// List<VariableAccess> va = dfan.getVariableAccess();
// for (VariableAccess o : va) {
// System.out.println(" variable: " + o);
// }
// }
}
Also used : ASTMethodDeclarator(net.sourceforge.pmd.lang.java.ast.ASTMethodDeclarator) ASTCompilationUnit(net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit) DataFlowNode(net.sourceforge.pmd.lang.dfa.DataFlowNode) Test(org.junit.Test)

Example 30 with DataFlowNode

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

the class VariableAccessVisitor method collectDeclarations.

private Set<Map<NameDeclaration, List<NameOccurrence>>> collectDeclarations(DataFlowNode inode) {
    Set<Map<NameDeclaration, List<NameOccurrence>>> decls = new HashSet<>();
    Map<NameDeclaration, List<NameOccurrence>> varDecls;
    for (int i = 0; i < inode.getFlow().size(); i++) {
        DataFlowNode n = inode.getFlow().get(i);
        if (n instanceof StartOrEndDataFlowNode) {
            continue;
        }
        varDecls = ((PLSQLNode) n.getNode()).getScope().getDeclarations();
        if (!decls.contains(varDecls)) {
            decls.add(varDecls);
        }
    }
    return decls;
}
Also used : StartOrEndDataFlowNode(net.sourceforge.pmd.lang.dfa.StartOrEndDataFlowNode) DataFlowNode(net.sourceforge.pmd.lang.dfa.DataFlowNode) StartOrEndDataFlowNode(net.sourceforge.pmd.lang.dfa.StartOrEndDataFlowNode) PLSQLNode(net.sourceforge.pmd.lang.plsql.ast.PLSQLNode) ArrayList(java.util.ArrayList) List(java.util.List) NameDeclaration(net.sourceforge.pmd.lang.symboltable.NameDeclaration) Map(java.util.Map) PLSQLNameOccurrence(net.sourceforge.pmd.lang.plsql.symboltable.PLSQLNameOccurrence) NameOccurrence(net.sourceforge.pmd.lang.symboltable.NameOccurrence) HashSet(java.util.HashSet)

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