Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Nested calls to 'iterate' method
[Acceleo] Nested calls to 'iterate' method [message #509636] Sat, 23 January 2010 21:47 Go to next message
Andre is currently offline AndreFriend
Messages: 29
Registered: November 2009
Location: Brazil
Junior Member
Hi

is it possible to make nested calls to 'iterate' method?

my problem is:
i want to get the type of all paramethers of an method. This is very easy to do by using 'for' loops (consider i an interface):

[for (op : Operation | i.operations)]
[for (at : Parameter | op.parameters)]
	[at.type.name/]
[/for]	
[/for]

This code is working, but i want to do this using a query. I've tried the code below but it does not return any value:
[query public getParametersPackage(i : Interface) : Sequence(T) =  
	i.operations->iterate(elem; res: Sequence(String) = Sequence{} |
	elem.parameters->iterate(a; b : Sequence(String) = Sequence{} |
	res->append(a.type.name)
	))/]


what is the problem? is my query wrong?

thanks


Andre Silva
Natal-RN
Brazil
Re: [Acceleo] Nested calls to 'iterate' method [message #509642 is a reply to message #509636] Sat, 23 January 2010 22:43 Go to previous messageGo to next message
Sebastien Roy is currently offline Sebastien RoyFriend
Messages: 51
Registered: November 2009
Member
Hello,
Have you tried something like this :
[query public getAllTypes(i : Interface) : Set(T) = 
    i.operations.parameters.type->asSet()/]


It should answer to your needs...
Re: [Acceleo] Nested calls to 'iterate' method [message #509650 is a reply to message #509642] Sun, 24 January 2010 01:50 Go to previous messageGo to next message
Andre is currently offline AndreFriend
Messages: 29
Registered: November 2009
Location: Brazil
Junior Member
Sebastien

yes, it is working! thanks...

but i got curious about using nested iterate calls... is it possible?


Andre Silva
Natal-RN
Brazil
Re: [Acceleo] Nested calls to 'iterate' method [message #510662 is a reply to message #509650] Thu, 28 January 2010 09:34 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1638
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------020506040009020106060405
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Andre,

Nested iterate calls are possible, but IIRC you have to explicitely
append to the "result" variables in each iterate. That would give
something like

i.operations->iterate(elem; res: Sequence(String) = Sequence{} |
res->union(elem.parameters->iterate(a; res2 : Sequence(String) =
Sequence{} |
res2->append(a.type.name))))

But for the sake of your coworkers or those that will follow after you
to maintain your modules, _avoid_ iterates at all costs : they totally
hinder the readeability of your expressions.

There's pretty much always a way to work around iterates. Sebastien's
solution is way more elegant, but even without that, use specific OCL
loops whenever possible. The "collect", "select", "reject", ...
operations are there to answer specific iteration needs. For exemple,
your expression could be rewrote as
"i.operations->collect(parameters->collect(type.name))"

Laurent Goubet
Obeo

Andre wrote:
> Sebastien
>
> yes, it is working! thanks...
>
> but i got curious about using nested iterate calls... is it possible?
>


--------------020506040009020106060405
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------020506040009020106060405--
Re: [Acceleo] Nested calls to 'iterate' method [message #510735 is a reply to message #510662] Thu, 28 January 2010 14:06 Go to previous message
Andre is currently offline AndreFriend
Messages: 29
Registered: November 2009
Location: Brazil
Junior Member
Laurent

I dont know why, but for me it's easier to think about iterations than other operations (collect, reject, ...), but i'll try to follow your advice.

thanks,


Andre Silva
Natal-RN
Brazil
Previous Topic:[Acceleo] Suggestion : icons for autocompletion
Next Topic:Xpand vs Acceleo vs JET
Goto Forum:
  


Current Time: Sun Nov 23 16:14:11 GMT 2014

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

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