Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Xpand2] Looping (for loop / do while loop / while loop)
[Xpand2] Looping (for loop / do while loop / while loop) [message #551993] Tue, 10 August 2010 13:00 Go to next message
Abdull is currently offline AbdullFriend
Messages: 32
Registered: May 2010
Member
Is there a way to express loops within Xpand2 templates? That is, I would like to have some Xpand2 statements repeated until some particular condition is no longer met.
As I can see right now, using collections together with the "EXPAND...FOREACH" statement or the "FOREACH" statement is the only way to have loops out of the box.

Background: My metamodel has a class "Element" with a reference "nextElement" on itself. Instances of this metamodel can have several elements forming a linked list (i.e. someElement.nextElement points on someOtherElement.... someOtherElement.nextElement could point on yetAnotherElement and so on).
I'd like to generate text using an Xpand2 template which walks along this linked list, stopping when nextElement points to "null".
Re: [Xpand2] Looping (for loop / do while loop / while loop) [message #551998 is a reply to message #551993] Tue, 10 August 2010 13:16 Go to previous message
Abdull is currently offline AbdullFriend
Messages: 32
Registered: May 2010
Member
In the meantime, I'm using the following Xtend extension

create List[my::namespace::Element] getOrderedElements(my::namespace::Element head) :
this.add(head) ->
head.nextElement == null ? this : this.addAll(getOrderedElements(head.nextElement));
Previous Topic:[Acceleo 3] Can't find my ecore model
Next Topic:[XPAND] Problems with getting started
Goto Forum:
  


Current Time: Fri Oct 04 11:24:45 GMT 2024

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

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

Back to the top