Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "JET FAQ How do I get new lines in the right place when using iterate with delimiter?"

m
m
 
Line 1: Line 1:
== Problem ==
+
== Question ==
 
The <c:iterate> tag includes a delimiter attribute which inserts a delimiter between blocks of code generated. But, if you try something like:
 
The <c:iterate> tag includes a delimiter attribute which inserts a delimiter between blocks of code generated. But, if you try something like:
  
Line 29: Line 29:
 
</pre>
 
</pre>
  
== Solution ==
+
== 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:
 
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:
  
Line 46: 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.

Back to the top