[Acceleo] Nested calls to 'iterate' method [message #509636] |
Sat, 23 January 2010 21:47 |
Andre 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 #510662 is a reply to message #509650] |
Thu, 28 January 2010 09:34 |
|
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--
|
|
|
|
Powered by
FUDForum. Page generated in 0.04058 seconds