Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Pretty printing generated AST?
Pretty printing generated AST? [message #253654] Sat, 31 May 2008 22:32 Go to next message
Eclipse UserFriend
Originally posted by:

Hi all,

I'm pretty new to the JDT core. I'm trying to generate code using the core
AST APIs in an application external to Eclipse, and write the result to
files. I've managed to generate an AST, and write it to a file using
ASTFlattener. I'd like to format this code with the formatter, is this
possible? Can I directly print formatted code from the AST without having
to re-parse the generated code?

Thanks for any help,
Re: Pretty printing generated AST? [message #844345 is a reply to message #253654] Fri, 13 April 2012 23:27 Go to previous message
Mirko Klemm is currently offline Mirko KlemmFriend
Messages: 1
Registered: April 2012
Junior Member
This might work:

ASTFlattener fl = new ASTFlattener();
String code = fl.getResult();
CodeFormatter cf = new DefaultCodeFormatter();
TextEdit te = cf.format(CodeFormatter.K_UNKNOWN, code, 0,
code.length(), 0, null);
Document doc = new Document(code);

Good Luck!

EDIT: Better use "ToolFactory" to create the formatter, and experiment with the "options" map parameter of the "createCodeFormatter" method!

[Updated on: Sun, 15 April 2012 12:13]

Report message to a moderator

Previous Topic:Import jsf 2.0 netbeans project in to Eclipse IDE Helios
Next Topic:problem with eclipse installation
Goto Forum:

Current Time: Sat May 26 16:04:14 GMT 2018

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

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

Back to the top