|
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 Messages: 849 Registered: July 2009 |
Senior Member |
|
|
Edoardo:
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:
http://help.eclipse.org/ganymede/topic/org.eclipse.platform. doc.isv/reference/api/org/eclipse/text/edits/TextEdit.html
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:
JavaCode.create(IProject):
http://help.eclipse.org/ganymede/topic/org.eclipse.jdt.doc.i sv/reference/api/org/eclipse/jdt/core/JavaCore.html#create(org.eclipse.core.resources.IProject)
and then:
IJavaProject.getOptions(boolean):
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:
<x:javaFormat project="foo.bar">
..... Java code to format ...
</x:javaFormat>
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)?
Paul
"Edoardo Comar" <ecomar@uk.ibm.com> wrote in message
news:gkfn3e$5an$1@build.eclipse.org...
> 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.03315 seconds