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:
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!