Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
JET FAQ How do I get new lines in the right place when using iterate with delimiter?
Question
The <c:iterate> tag includes a delimiter attribute which inserts a delimiter between blocks of code generated. But, if you try something like:
public enum MyEnum {
<c:iterate select="/def/elements" var="element" delimiter=",">
<c:get select="upper-case($element/@name)"/>("<c:get select="$element/@alias"/>")
</c:iterate>
;
private MyEnum(String alias) {
// ...
}
}
You end up with generated code looking like:
public enum MyEnum {
BANK("bank")
, RECORD("record")
, MESSENGER("messenger")
;
private MyEnum(String alias) {
// ...
}
}
Answer
JET is inserting the delimiter between each block generated by the iterate tag. But in this case, the tag's content includes a final new-line character - the delimiter is inserted after this. One possibility is to make the new-line part of the delimiter itself:
public enum MyEnum {
<%-- The value of delimiter includes a new line. This not an accidental wrapping! --%>
<c:iterate select="/def/elements" var="element" delimiter=",
">
<%-- and, the </c:iterate> tag is moved up, to eliminate the new line in content block --%>
<%-- finally, the semi-colon is moved to onto the same line, too --%>
<c:get select="upper-case($element/@name)"/>("<c:get select="$element/@alias"/>")</c:iterate>;
private MyEnum(String alias) {
// ...
}
}
See Also
Return to the M2T-JET-FAQ.