Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » c:iterate with delimiter and formatting
c:iterate with delimiter and formatting [message #23372] Thu, 21 June 2007 16:23 Go to next message
Eclipse UserFriend
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 14:02 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
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 08:57 Go to previous message
Eclipse UserFriend
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
Previous Topic:run jet2 outside of eclipse
Next Topic:JET2-GMF/EMF Access Container class
Goto Forum:
  


Current Time: Tue Apr 16 08:21:28 GMT 2024

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

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

Back to the top