Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Post trim not working(post (trim()) seems to do nothing)
Post trim not working [message #1765385] Fri, 09 June 2017 05:51 Go to next message
Philip Schröder is currently offline Philip SchröderFriend
Messages: 28
Registered: January 2017
Junior Member
Hello folks,
I would like to structure my code, and with Acceleo it mostly feels like I need to put everything in one line to make it work.
Thus I tried out post (trim()), but it doesn't seem to do anything.

Here is what I tried:

[template public generateTrimTests(c : Class)]
[comment @main/]
[file ('src/' + + '.h', false, 'UTF-8')]

[template public trimBeforeWrite(c : Class) post (trim())]
[for(a : Property | c.attribute)]
Whatevertype [];
[if (2 < 3)]
		Blablubs: [] foo 

The Papyrus diagram looks like this


Now I would expect something like this

	Whatevertype Attribute1; Whatevertype Attribute2;   Blablubs: SomeClass foo bla

Instead I get this

	Whatevertype Attribute1;
	Whatevertype Attribute2;
			Blablubs: SomeClass foo 

To me it seems as if post (trim()) does nothing, any idea?

Thank you for your time and trouble.



[Updated on: Fri, 09 June 2017 05:54]

Report message to a moderator

Re: Post trim not working [message #1765947 is a reply to message #1765385] Wed, 14 June 2017 14:39 Go to previous message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member

"trim" will remove the spaces "around" the result of your template call, not all spaces inside it; there are no such white spaces in your trimBeforeWrite template.

The whitespaces you see are the ones added by your for loop, specifically the carriage return after ";". You could remove that carriage returns by having the end of your for loop on the same line:
[for(a : Property | c.attribute)]
Whatevertype [];[/for]

LIkewise, the carriage return before "bla" is the one inside your "if", and you'd need to remove it as well:

[if (2 < 3)]
		Blablubs: [] foo[else]

This is probably not the answer you wanted, but we made the choice to preserve these particular line endings as significant in the template writing, so you need to work around them if you happen not to want them generated.

Note that you could use something other than "trim" if you want to remove all line separators from the template call, regardless of their position (i.e. also the ones "in the middle" of the text generated by the template.

For example, replace could work for your case:
[template public trimBeforeWrite(c : Class) post (replace('\\\\s', ''))]

would remove "all" whitespace.

[template public trimBeforeWrite(c : Class) post (replace('\\\\r|\\\\n', ''))]

would remove the line endings.

Laurent Goubet
Previous Topic:language
Next Topic:Invalid type for iteration Error
Goto Forum:

Current Time: Sun Mar 03 03:52:40 GMT 2024

Powered by FUDForum. Page generated in 0.01901 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top