Search in sources :

Example 6 with StartOrEndDataFlowNode

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

the class VariableAccessVisitor method collectDeclarations.

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

Example 7 with StartOrEndDataFlowNode

use of net.sourceforge.pmd.lang.dfa.StartOrEndDataFlowNode 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 8 with StartOrEndDataFlowNode

use of net.sourceforge.pmd.lang.dfa.StartOrEndDataFlowNode 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 9 with StartOrEndDataFlowNode

use of net.sourceforge.pmd.lang.dfa.StartOrEndDataFlowNode 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)9 StartOrEndDataFlowNode (net.sourceforge.pmd.lang.dfa.StartOrEndDataFlowNode)9 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 ASTExpression (net.sourceforge.pmd.lang.plsql.ast.ASTExpression)2 ASTProgramUnit (net.sourceforge.pmd.lang.plsql.ast.ASTProgramUnit)2 NameOccurrence (net.sourceforge.pmd.lang.symboltable.NameOccurrence)2 JavaNode (net.sourceforge.pmd.lang.java.ast.JavaNode)1 JavaNameOccurrence (net.sourceforge.pmd.lang.java.symboltable.JavaNameOccurrence)1 VariableNameDeclaration (net.sourceforge.pmd.lang.java.symboltable.VariableNameDeclaration)1 PLSQLNode (net.sourceforge.pmd.lang.plsql.ast.PLSQLNode)1 PLSQLNameOccurrence (net.sourceforge.pmd.lang.plsql.symboltable.PLSQLNameOccurrence)1 NameDeclaration (net.sourceforge.pmd.lang.symboltable.NameDeclaration)1