Home » Modeling » M2T (model-to-text transformation) » [JET2] How to correctly indent/linebreak lines?
|Re: [JET2] How to correctly indent/linebreak lines? [message #20758 is a reply to message #20661]
||Wed, 06 June 2007 12:44
| Paul Elder
Registered: July 2009
JET has no automated tools for indenting, although I do know that some users
that have written a custom tag to indent. I have submitted bug 191228
(https://bugs.eclipse.org/bugs/show_bug.cgi?id=191228) to track a possible
enhancement. Feel free to add comments.
I have done indenting by using a variable:
<%-- Set the initial indent, spaces added around ' ' just for clarity --%>
<c:setVariable var="indent" select=" ' ' "/>
Then, in the recursive template, start with:
<c:setVariable var="indent" select="concat($indent, ' ')"/>
.... through the template add:
<c:get select="$indent"/>...rest of line...
.... and, at the end of the template:
<%-- restore the previous indent, assuming that we indented 4 spaces --%>
<c:setVariable var="indent" select="substring($indent,5)"/>
The only real problem with this is that all those <c:get select="$indent"/>
tags interfere with template readability.
As for whitespace, JET has specific rules for removing whitespace and
newlines from the template.
1) JET will only CONSIDER removing whitespace if a language element
(scriptlet, expression, declaration, directive, open tag, end tag, empty
tag, comment) is 'alone' on a line. Technically, this is implemented as the
element starts on a line in which preceeding text in only whitespace, and
ends on a line that is only whitespace. So, for example, the following are
all 'alone' on a line:
<c:iterate select="..." var="...">
<%-- this is a multiline comment,
but it is still 'alone' on a line --%>
2) For scriptlets, declarations, directives and comments, being alone on a
line will cause JET to remove the surrounding whitespace, including new-line
characters at the end of the trailing line.
3) For JET custom tags, which space removal is dependent on that tag. Each
tag is declared with a 'whenContainingLineIsEmpty' attribute, which can have
a value of either 'preserve' or 'remove'. Typically, tags that produce
content preserve, while those that provide control structure like
capabilites remove. Some examples of whitespace preserving tags: c:get, f:lc
(lowercase). Examples of whitespace removing tags: c:iterate, c:if,
I have had suggestions that JET needs other modes of whitespace processing.
As an example, consider writing code generate a Java method signature.
Instinctively, I'd want to write something like:
<c:iterate select="$method/flags" var="flag" >
<c:get select="$method/@name"/> (
<c:iterate select="$method/parameter" var="parameter" delimiter=",">
<c:get select="$parameter/@type"/> <c:get select="$parameter/@name"/>
But if you did that, you'd get a whole pile of extra lines. Today, you need
to run this all onto one long line. It would be nice to either a tag, or a
template mode that operated in a whitespace normalizing mode (all runs of
whitespace including new lines are converted to a single blank; initial and
trailing whitespace is removed). I have a bug on this one, too: bug 180927
"Florian Georg" <firstname.lastname@example.org> wrote in message
> I'm trying to generate a XML file with a certain indention.
> When I try this:
> <c:iterate select="$packages" var="package" >
> <c:include template="templates/package.jet" passVariables="package"/>
> I would hope the output of the included template being indented by a tab
> (or four spaces), but it is not.
> Additionally, I call that template recursivly and I was hoping that the
> indents "add up" for each level of hierarchy... is this possible?
> Is there a general rule how JET deals with indention/whitespaces/line
> This is particularly important e.g. for languages where indention has some
> semantical meaning.
> Thanks in advance for your help
Current Time: Thu Feb 02 20:49:02 GMT 2023
Powered by FUDForum
. Page generated in 0.30924 seconds