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;
}
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));
}
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());
}
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);
// }
// }
}
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;
}
Aggregations