use of net.sourceforge.pmd.lang.dfa.DataFlowNode in project pmd by pmd.
the class VariableAccessVisitor method computeNow.
private void computeNow(Node node) {
DataFlowNode inode = node.getDataFlowNode();
List<VariableAccess> undefinitions = markUsages(inode);
// all variables are first in state undefinition
DataFlowNode firstINode = inode.getFlow().get(0);
firstINode.setVariableAccess(undefinitions);
// all variables are getting undefined when leaving scope
DataFlowNode lastINode = inode.getFlow().get(inode.getFlow().size() - 1);
lastINode.setVariableAccess(undefinitions);
}
use of net.sourceforge.pmd.lang.dfa.DataFlowNode in project pmd by pmd.
the class DAAPathFinder method getDoBranchNodeInLevel.
private PathElement getDoBranchNodeInLevel(DefaultMutableTreeNode level) {
DataFlowNode inode = currentPath.getLast();
if (!inode.isType(NodeType.DO_EXPR)) {
return null;
}
int childCount = level.getChildCount();
DefaultMutableTreeNode child;
for (int i = 0; i < childCount; i++) {
child = (DefaultMutableTreeNode) level.getChildAt(i);
PathElement pe = (PathElement) child.getUserObject();
if (inode.equals(pe.node)) {
return pe;
}
}
return null;
}
use of net.sourceforge.pmd.lang.dfa.DataFlowNode in project pmd by pmd.
the class DataflowAnomalyAnalysisRule method visit.
public Object visit(ASTMethodDeclaration methodDeclaration, Object data) {
rc = (RuleContext) data;
daaRuleViolations = new ArrayList<>();
final DataFlowNode node = methodDeclaration.getDataFlowNode().getFlow().get(0);
final DAAPathFinder pathFinder = new DAAPathFinder(node, this, getProperty(MAX_PATH_DESCRIPTOR));
pathFinder.run();
super.visit(methodDeclaration, data);
return data;
}
use of net.sourceforge.pmd.lang.dfa.DataFlowNode in project pmd by pmd.
the class StatementAndBraceFinderTest method testIfStmtHasCorrectTypes.
@Test
public void testIfStmtHasCorrectTypes() {
ASTExpression exp = getOrderedNodes(ASTExpression.class, TEST3).get(0);
DataFlowNode dfn = exp.getDataFlowNode().getFlow().get(2);
assertTrue(dfn.isType(NodeType.IF_EXPR));
assertTrue(dfn.isType(NodeType.IF_LAST_STATEMENT_WITHOUT_ELSE));
}
use of net.sourceforge.pmd.lang.dfa.DataFlowNode in project pmd by pmd.
the class StatementAndBraceFinderTest method testForStmtHasCorrectTypes.
@Test
public void testForStmtHasCorrectTypes() {
ASTExpression exp = getOrderedNodes(ASTExpression.class, TEST5).get(0);
DataFlowNode dfn = exp.getDataFlowNode().getFlow().get(2);
assertTrue(dfn.isType(NodeType.FOR_INIT));
dfn = exp.getDataFlowNode().getFlow().get(3);
assertTrue(dfn.isType(NodeType.FOR_EXPR));
dfn = exp.getDataFlowNode().getFlow().get(4);
assertTrue(dfn.isType(NodeType.FOR_UPDATE));
assertTrue(dfn.isType(NodeType.FOR_BEFORE_FIRST_STATEMENT));
assertTrue(dfn.isType(NodeType.FOR_END));
}
Aggregations