Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » How to compile AST to bytecode
How to compile AST to bytecode [message #901889] Tue, 14 August 2012 17:42 Go to next message
b x is currently offline b x
Messages: 16
Registered: February 2012
Junior Member
Hi, I added some statements to an existed AST tree and got a new AST tree, I wanted to compile the new tree, do you have any idea that how to compile AST to bytecode?
Re: How to compile AST to bytecode [message #901892 is a reply to message #901889] Tue, 14 August 2012 18:04 Go to previous message
Stephan Herrmann is currently offline Stephan Herrmann
Messages: 994
Registered: July 2009
Senior Member
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,
HTH,
Stephan

Previous Topic:How to call an existing Eclipse dialog from my custom Eclipse plugin?
Next Topic:Juno - Spurious warning: Resource Leak
Goto Forum:
  


Current Time: Wed Aug 20 01:03:59 EDT 2014

Powered by FUDForum. Page generated in 0.15064 seconds