Skip to main content



      Home
Home » Modeling » M2T (model-to-text transformation) » [XTEND]Iteration over a list
icon5.gif  [XTEND]Iteration over a list [message #522150] Sat, 20 March 2010 10:51 Go to next message
Eclipse UserFriend
Hey guys,

I'm still a newbie in the openarchitectureware project, so any help would be much appreciated.

I have a recursive function transformDec(Object obj) and it's working, but the problem is my object obj contains a property "declarations" which is itself a list of objects so when i call back transformDec(obj.declarations) it won't work.

I have thinked of creating a new function :

String transformDecList(List lst) :
if (!lst.IsEmpty) then
transformDec(lst.first())->
transformDecList(lst.withoutfirst())
;


But that is still not working. Any help?

[Updated on: Sat, 20 March 2010 10:56] by Moderator

Re: [XTEND]Iteration over a list [message #522179 is a reply to message #522150] Sat, 20 March 2010 16:45 Go to previous messageGo to next message
Eclipse UserFriend
It is quite easy to iterate over an collection calling an extension on every element. Try:
String transformDec(Object) :
...
obj.declarations.transformDec()->
...
;


Regards
Re: [XTEND]Iteration over a list [message #522323 is a reply to message #522179] Mon, 22 March 2010 07:01 Go to previous messageGo to next message
Eclipse UserFriend
Thx Darius for your reply,

I have tried just what you said but the extension transformDec is not called for each object of the list, it's the whole liste that is passed as a parameter and it simply returns "null" !!

Any ideas?

Thanks
Re: [XTEND]Iteration over a list [message #522405 is a reply to message #522323] Mon, 22 March 2010 11:02 Go to previous messageGo to next message
Eclipse UserFriend
Just in case, do you have to call it from Xtend ?

Because it's easy to call your function on each element of the list using Xpand and "EXPAND ... FOREACH".
Re: [XTEND]Iteration over a list [message #522415 is a reply to message #522405] Mon, 22 March 2010 11:18 Go to previous messageGo to next message
Eclipse UserFriend
Yes, I have too, otherwise that would be simple.. I'm looking for a "FOR statement" or a "WHILE statement" or anything like that using XTEND.

Actually, I have in my expand file :

<<FOREACH declarations AS dec>>
<<this.transformDec()>>
<<ENDFOREACH>>


and within this dec , there is a list of other declarations, that's the way my metamodel is !

Regards
Re: [XTEND]Iteration over a list [message #522427 is a reply to message #522415] Mon, 22 March 2010 11:38 Go to previous messageGo to next message
Eclipse UserFriend
shouldn't it look like this?

<<FOREACH declarations AS dec>>
<<dec.transformDec()>>
<<ENDFOREACH>>
Re: [XTEND]Iteration over a list [message #522437 is a reply to message #522427] Mon, 22 March 2010 12:07 Go to previous messageGo to next message
Eclipse UserFriend
Christian Dietrich wrote on Mon, 22 March 2010 11:38
shouldn't it look like this?

<<FOREACH declarations AS dec>>
<<dec.transformDec()>>
<<ENDFOREACH>>



It's the same, isn't it?
Re: [XTEND]Iteration over a list [message #522441 is a reply to message #522437] Mon, 22 March 2010 12:17 Go to previous messageGo to next message
Eclipse UserFriend
no dec != this
Re: [XTEND]Iteration over a list [message #522608 is a reply to message #522150] Tue, 23 March 2010 07:01 Go to previous message
Eclipse UserFriend
Thank you guys, problem resolved.. I reformulated my Xpand template and everything is fine now.
Previous Topic:Using JET2 to modify existing files
Next Topic:[JET] How to do like <c:dump select="var"/> but to a variable/string instead?
Goto Forum:
  


Current Time: Wed Jul 30 18:48:48 EDT 2025

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

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

Back to the top