c:iterate with delimiter and formatting [message #23372] |
Thu, 21 June 2007 12:23  |
Eclipse User |
|
|
|
Originally posted by: ch.dev1.talgi-tech.net
I'm fairly new to JET so apologies if this is a stupid question but I'm
having a hard time generating decent looking enums using the <c:iterate>
tag. Here's the template:
<c:iterate select="/def/elements" var="element" delimiter=",">
<c:get select="upper-case($element/@name)"/>("<c:get
select="$element/@alias"/>")
</c:iterate>;
The result looks like this (I've added some context to make what I'm
trying to achieve more obvious):
public enum MyEnum {
BANK("bank")
, RECORD("record")
, MESSENGER("messenger")
;
private MyEnum(String alias) {...}
}
Is there a way I could make this look more like it should (ie with the
delimiters on the previous line). The only alternative I've found is to
have it all on a single line. I've tried appending some sort of newline
character to the delimiter but this is not as easy as it sounds...
Perhaps - a suggestion for Paul - a way to solve this and similar
formatting issues would be to add something along the lines of a
<ws:autoFormat> tag that would apply Eclipse's builtin automatic source
formatter (Ctrl-Shift-F) to its scope - although I have noticed that, at
least in my current version (3.3RC4), it does a terrible job at this
example...
Cheers,
Christian
|
|
|
Re: c:iterate with delimiter and formatting [message #23589 is a reply to message #23372] |
Fri, 22 June 2007 10:02   |
Eclipse User |
|
|
|
Christian:
First, I do have an enhancement open on improving whitespace handling
(https://bugs.eclipse.org/bugs/show_bug.cgi?id=180927). Feel free to add
comments/suggestions there.
But, let's see if we can solve your problem without an enhancement...
One possibility, although a bit unique to your situation is to slighly
modify you code generation...
<c:iterate select="/def/elements" var="element">
<c:get select="upper-case($element/@name)"/>("<c:get
select="$element/@alias"/>"),
</c:iterate>
;
This would produce:
public enum MyEnum {
BANK("bank"),
RECORD("record"),
MESSENGER("messenger"),
;
private MyEnum(String alias) {
// ...
}
}
And take advantage of the fact that Java lets you put a final comma at the
end of the listed enumerations.
As for doing it the the "right" way, this works...
public enum MyEnum {
<c:iterate select="/def/elements" var="element" delimiter=",
">
<c:get select="upper-case($element/@name)"/>(<c:get
select="$element/@name"/>)</c:iterate>;
private MyEnum(String alias) {
// ...
}
}
The 'clever' tricks:
1) put the NL in the delimiter attribute
2) move the </c:iterate>
Your question has finally motivated me to start a JET FAQ. Over the next few
weeks, I'll put answers posted on this group into the faq. Here's the
first...
The JET FAQ: http://wiki.eclipse.org/M2T-JET-FAQ
Your question:
http://wiki.eclipse.org/JET_FAQ_How_do_I_get_new_lines_in_th e_right_place_when_using_iterate_with_delimiter%3F
Paul
"Christian Sarrasin" <ch.dev1@talgi-tech.net> wrote in message
news:9ac5b5fab95ea24c8041c1e66643dc80$1@www.eclipse.org...
> I'm fairly new to JET so apologies if this is a stupid question but I'm
> having a hard time generating decent looking enums using the <c:iterate>
> tag. Here's the template:
>
> <c:iterate select="/def/elements" var="element" delimiter=",">
> <c:get select="upper-case($element/@name)"/>("<c:get
> select="$element/@alias"/>")
> </c:iterate>;
>
> The result looks like this (I've added some context to make what I'm
> trying to achieve more obvious):
>
> public enum MyEnum {
> BANK("bank")
> , RECORD("record")
> , MESSENGER("messenger")
> ;
>
> private MyEnum(String alias) {...}
> }
>
> Is there a way I could make this look more like it should (ie with the
> delimiters on the previous line). The only alternative I've found is to
> have it all on a single line. I've tried appending some sort of newline
> character to the delimiter but this is not as easy as it sounds...
>
> Perhaps - a suggestion for Paul - a way to solve this and similar
> formatting issues would be to add something along the lines of a
> <ws:autoFormat> tag that would apply Eclipse's builtin automatic source
> formatter (Ctrl-Shift-F) to its scope - although I have noticed that, at
> least in my current version (3.3RC4), it does a terrible job at this
> example...
>
> Cheers,
> Christian
>
|
|
|
Re: c:iterate with delimiter and formatting [message #23843 is a reply to message #23589] |
Tue, 26 June 2007 04:57  |
Eclipse User |
|
|
|
Originally posted by: ch.dev1.talgi-tech.net
Hi Paul,
Many thanks for answering my question in such a comprehensive manner and
for going as far as starting a whole FAQ based on it ;-) This is real
quality!
Many thanks again!
Christian
|
|
|
Powered by
FUDForum. Page generated in 0.07405 seconds