|Re: Formatting jet-generated java sources according to Eclipse formatting rules ? [message #55362 is a reply to message #55255]
||Wed, 14 January 2009 13:21
| Paul Elder
Registered: July 2009
A quick look at the JDT APIs reveals CodeFormatter.format:
http://help.eclipse.org/ganymede/topic/org.eclipse.jdt.doc.i sv/reference/api/org/eclipse/jdt/core/formatter/CodeFormatte r.html#format (int,%20java.lang.String,%20int,%20int,%20int,%20java.lang.S tring)
So, a basic code format could be implemented as a function tag that called
this. It gets a little tricky, as format returns a TextEdit, the the Java
doc shows how to turn this into a modified string:
There also appears to be the very useful ToolFactory.createCodeFormatter()
method that instantiates a code formatter:
http://help.eclipse.org/ganymede/topic/org.eclipse.jdt.doc.i sv/reference/api/org/eclipse/jdt/core/ToolFactory.html#creat eCodeFormatter(java.util.Map,%20int)
The last problem is getting the options for the target project. This appears
to be done via a number of methods:
http://help.eclipse.org/ganymede/topic/org.eclipse.jdt.doc.i sv/reference/api/org/eclipse/jdt/core/IJavaProject.html#getO ptions(boolean)
So, all this suggests you could implement a tag such as:
..... Java code to format ...
I'd be interested in adding such a tag to JET. Would you be interested in
implementing it (and getting your masters to agree to its contribution)?
"Edoardo Comar" <firstname.lastname@example.org> wrote in message
> How can I get the jet-generated java sources formatted according to
> Eclipse formatting rules ?
> sure I could manually select the files and invoke the formatter, but since
> they are scattered acorss my projects and packages it's too long and
> error-prone, so I'd rather have it done as part of the one-click code
> generation ...
Powered by FUDForum
. Page generated in 0.02309 seconds