Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [XPand2] setting local variables
[XPand2] setting local variables [message #805869] Fri, 24 February 2012 08:36 Go to next message
Florian Reischl is currently offline Florian Reischl
Messages: 5
Registered: February 2012
Junior Member
Hello,

I want to set a local variable to another value, for example:

«LET false AS itemFound»
«FOREACH ... AS ...»
«IF ...»
 «REM»do sth and set the variable itemFound to true«ENDREM»
 itemFound = true
«ENDIF»
«ENDFOREACH»
«ENDLET»


How can I do this?

[Updated on: Fri, 24 February 2012 09:06]

Report message to a moderator

Re: [XPand2] setting local variables [message #805893 is a reply to message #805869] Fri, 24 February 2012 09:09 Go to previous message
Karsten Thoms is currently offline Karsten Thoms
Messages: 354
Registered: July 2009
Location: Dortmund
Senior Member

The LET statement binds the result of an expression to a variable. There is no concept in Xpand to define variables, and usually it is not needed.

Anyway, to come around this you could use the elementprops extensions from stdlib.

extension org::eclipse::xtend::util::stdlib::elementprops;
«this.setProperty("itemFound", false)»
«IF ...»
  «this.setProperty("itemFound", true)»


You should always ask yourself: Do I really need this? I do not know your usecase, but it is likely that you could come around your issue with a smarter use of extension functions for your template. I have programmed so many templates, and don't have a real need for local variables in 99%. Also I avoid to use LET in favor of extension functions whenever applicable.

Regards,
~Karsten


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Previous Topic:[acceleo] best way to pass extra data from Java to template ?
Next Topic:[Acceleo] Errors running builder 'Acceleo Builder'
Goto Forum:
  


Current Time: Sat Oct 25 23:09:07 GMT 2014

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

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