Creating for/if blocks

14 views
Skip to first unread message

Julius Bezaras

unread,
Jan 11, 2015, 4:39:59 AM1/11/15
to javap...@googlegroups.com
Hello, 

I'm trying to figure out how to access for or if statement variables. I have parsed java code from a file, but how to access variables from for or if bodyblocks?

Code to read:

package tests;

class PrePostDemo {
     public static void main(String[] args){
          int i = 3;
          if (i > 2)
          {
         for (int j = 1; j>25; j++)
         {
         System.out.println(j);
         }
          }
}

My visitor class (dont mind class name):

private static class BodyChangerVisitor extends VoidVisitorAdapter {
@Override
public void visit(ForStmt n, Object arg) {
Expression statement1 = n.getCompare();
System.out.println(statement1);
}
}

Console output:
j > 25


How do I access individual members of getCompare, getInit, etc. and change them? 
Also I don't understand how to create Expression or Statement variables that could be the problem. Please help!
Reply all
Reply to author
Forward
0 new messages