Pretty printing generated AST? [message #253654] |
Sat, 31 May 2008 22:32 |
Eclipse User |
|
|
|
Originally posted by: colin.mailinglist.gmail.com
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,
Colin
|
|
|
Re: Pretty printing generated AST? [message #844345 is a reply to message #253654] |
Fri, 13 April 2012 23:27 |
Mirko Klemm Messages: 1 Registered: April 2012 |
Junior Member |
|
|
This might work:
ASTFlattener fl = new ASTFlattener();
unit.accept(fl);
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);
te.apply(doc);
System.out.println(doc.get());
Good Luck!
Mirko
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
|
|
|
Powered by
FUDForum. Page generated in 0.03049 seconds