    1   package test.net.sourceforge.pmd.dfa;
    2
    3   import net.sourceforge.pmd.PMD;
    4   import net.sourceforge.pmd.ast.ASTCompilationUnit;
    5   import net.sourceforge.pmd.ast.ASTMethodDeclarator;
    6   import net.sourceforge.pmd.dfa.DataFlowNode;
    7   import net.sourceforge.pmd.dfa.IDataFlowNode;
    8   import net.sourceforge.pmd.dfa.variableaccess.VariableAccess;
    9   import test.net.sourceforge.pmd.testframework.ParserTst;
    10
    11  import java.util.Iterator;
    12  import java.util.List;
    13
    14  public class GeneralFiddlingTest extends ParserTst {
    15
    16      public void test1() throws Throwable {
    17          ASTCompilationUnit acu = buildDFA(TEST1);
    18          ASTMethodDeclarator meth = (ASTMethodDeclarator) acu.findChildrenOfType(ASTMethodDeclarator.class).get(0);
    19          IDataFlowNode n = meth.getDataFlowNode();
    20          List f = n.getFlow();
    21          for (Iterator i = f.iterator(); i.hasNext();) {
    22              DataFlowNode dfan = (DataFlowNode) i.next();
    23              System.out.println(dfan);
    24              List va = dfan.getVariableAccess();
    25              for (Iterator j = va.iterator(); j.hasNext();) {
    26                  VariableAccess o = (VariableAccess) j.next();
    27                  System.out.println(o);
    28              }
    29          }
    30      }
    31
    32      private static final String TEST1 =
    33              "class Foo {" + PMD.EOL +
    34              " void bar() {" + PMD.EOL +
    35              "  int x = 2;" + PMD.EOL +
    36              "  foo(x);" + PMD.EOL +
    37              "  x = 3;" + PMD.EOL +
    38              " }" + PMD.EOL +
    39              "}";
    40  }