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