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.
Difference between revisions of "JET FAQ How do I get new lines in the right place when using iterate with delimiter?"
(New page: The <c:iterate> tag includes a delimiter attribute, which inserts a delimiter between blocks of code generated. But, if you try something like: <pre> public enum MyEnum { <c:iterate selec...) |
m |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
− | The <c:iterate> tag includes a delimiter attribute | + | == Question == |
+ | The <c:iterate> tag includes a delimiter attribute which inserts a delimiter between blocks of code generated. But, if you try something like: | ||
<pre> | <pre> | ||
Line 28: | Line 29: | ||
</pre> | </pre> | ||
− | 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 | + | == 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: | ||
<pre> | <pre> | ||
Line 44: | Line 46: | ||
} | } | ||
</pre> | </pre> | ||
+ | |||
+ | == See Also == | ||
+ | * [[JET FAQ What are the JET whitespace handling rules?]] | ||
Return to the [[M2T-JET-FAQ]]. | Return to the [[M2T-JET-FAQ]]. | ||
[[Category:Modeling]][[Category:M2T]] | [[Category:Modeling]][[Category:M2T]] |
Latest revision as of 10:01, 22 June 2007
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.