Skip to main content

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 21:42 Go to next message
b x is currently offline b xFriend
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 22:04 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1828
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,

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: Fri Nov 27 04:26:01 GMT 2020

Powered by FUDForum. Page generated in 0.01737 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top