Search code examples
xtend

Xtend - pop-off last character from template


I'm using Xtend template to generate list and I would like to pop-off the last comma from the generated sequence:

«FOR link : links»
«link.simpleName»,
«ENDFOR»

Can I manipulate the StringConcatenation behind "on-the-fly"?

«ENDFOR _builder.deleteCharAt(result.size - 1)»

The sample above is not possible, StringConcatenation does not have such a method.


Solution

  • Loops in templates support additional keywords to add characters before and after the loop and between elements.

    You can use SEPARATOR to avoid the trailing comma:

    «FOR link : links SEPARATOR ','»
    «link.simpleName»
    «ENDFOR»