Xtend, rich strings and SEPARATOR option [message #876315] |
Thu, 24 May 2012 07:05  |
Eclipse User |
|
|
|
Hello,
In a previous post I have seen this code with rich strings
toString(Entity e) '''
«e.name»
«FOR member: e.members BEFORE "(" SEPARATOR "," AFTER ")"»
«member.toString»
«ENDFOR»
'''
The result will be the members separated by commas, in parentheses. If there
are no members, there won't be parentheses.
OK, but how can I do if I have a conditional inside the FOR?, as in the example:
toString(Entity e) '''
«e.name»
«FOR member: e.members BEFORE "(" SEPARATOR "," AFTER ")"»
«IF (a condition...)»«member.toString»«ENDIF»
«ENDFOR»
'''
Then, the result could be something like: m1, , , , m5, m6, m7, , , , , , m13,
How can I do if I want a result will be m1, m5, m6, m7, m3 ? Do I have to work it by hand?
Thanks in advance,
Aran
|
|
|
Re: Xtend, rich strings and SEPARATOR option [message #876379 is a reply to message #876315] |
Thu, 24 May 2012 09:36  |
Eclipse User |
|
|
|
What about wrapping it into an extra extension using map and filter?
e.g.
toString(Entity e) '''
«e.name»
«FOR member: e.members.filter(m|a condition) BEFORE "(" SEPARATOR "," AFTER ")"»
«member.toString»
«ENDFOR»
'''
[Updated on: Thu, 24 May 2012 14:08] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.05396 seconds