|Re: How to compile AST to bytecode [message #901892 is a reply to message #901889]
||Tue, 14 August 2012 18:04
| Stephan Herrmann
Registered: July 2009
The short answer: JDT has no function to directly compile an AST (because the public AST is different from what the compiler uses). Thus you first need to flatten the AST to its text representation and that can be compiled as normal.|
For obtaining the text representation two options come to mind:
- use the debug representation of the CompilationUnit (via toString()), but I'm not sure if this is 100% accurate, the JavaDoc mentions "for debugging purposes only".
- create your AST changes via an ASTRewrite which produces TextEdits that can be applied to the original Document => changes will be persisted in the original source files.
- if you don't want to modify source files you should use a WorkingCopy
I'm aware that this is just a terse outline,
Powered by FUDForum
. Page generated in 0.01653 seconds