L
leppoc
Hi !
I'm trying to modify an Abstract Syntax Tree (a
com.sun.tools.javac.tree.JCTree).
I can get the AST with something like that:
// new compiler, fileManager, compilationUnits1.....
CompilationTask ct = compiler.getTask(null, fileManager, null, null,
null, compilationUnits1);
JavacTask jt = (JavacTask)ct;
try {
Iterable trees = jt.parse();
//... do something else here....
} catch (IOException e) {
e.printStackTrace();
}
Then, I obviously can walk throw the tree....
I now want to modify this AST. Is there any simple way to achieve this
?
For example, if a leaf is a JCBlock, I would like to do something like
that (Just to test):
((JCBlock)t).stats.append(((JCBlock)t).getStatements().last());
but it seems that everything is read-only in those JCTrees.
Then, I would like to generate the .class with the modified tree... any
idea ?
Thank you !
Best regards,
Yohann Coppel.
I'm trying to modify an Abstract Syntax Tree (a
com.sun.tools.javac.tree.JCTree).
I can get the AST with something like that:
// new compiler, fileManager, compilationUnits1.....
CompilationTask ct = compiler.getTask(null, fileManager, null, null,
null, compilationUnits1);
JavacTask jt = (JavacTask)ct;
try {
Iterable trees = jt.parse();
//... do something else here....
} catch (IOException e) {
e.printStackTrace();
}
Then, I obviously can walk throw the tree....
I now want to modify this AST. Is there any simple way to achieve this
?
For example, if a leaf is a JCBlock, I would like to do something like
that (Just to test):
((JCBlock)t).stats.append(((JCBlock)t).getStatements().last());
but it seems that everything is read-only in those JCTrees.
Then, I would like to generate the .class with the modified tree... any
idea ?
Thank you !
Best regards,
Yohann Coppel.