Search in sources :

Example 21 with DataFlowNode

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);
}
Also used : DataFlowNode(net.sourceforge.pmd.lang.dfa.DataFlowNode) StartOrEndDataFlowNode(net.sourceforge.pmd.lang.dfa.StartOrEndDataFlowNode) VariableAccess(net.sourceforge.pmd.lang.dfa.VariableAccess)

Example 22 with DataFlowNode

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;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DataFlowNode(net.sourceforge.pmd.lang.dfa.DataFlowNode)

Example 23 with DataFlowNode

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;
}
Also used : DAAPathFinder(net.sourceforge.pmd.lang.dfa.pathfinder.DAAPathFinder) DataFlowNode(net.sourceforge.pmd.lang.dfa.DataFlowNode)

Example 24 with DataFlowNode

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));
}
Also used : DataFlowNode(net.sourceforge.pmd.lang.dfa.DataFlowNode) ASTExpression(net.sourceforge.pmd.lang.java.ast.ASTExpression) Test(org.junit.Test)

Example 25 with DataFlowNode

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));
}
Also used : DataFlowNode(net.sourceforge.pmd.lang.dfa.DataFlowNode) ASTExpression(net.sourceforge.pmd.lang.java.ast.ASTExpression) Test(org.junit.Test)

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