Skip to main content



      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 16:47 Go to next message
Eclipse UserFriend
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
Re: [Acceleo] Nested calls to 'iterate' method [message #509642 is a reply to message #509636] Sat, 23 January 2010 17:43 Go to previous messageGo to next message
Eclipse UserFriend
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] Sat, 23 January 2010 20:50 Go to previous messageGo to next message
Eclipse UserFriend
Sebastien

yes, it is working! thanks...

but i got curious about using nested iterate calls... is it possible?
Re: [Acceleo] Nested calls to 'iterate' method [message #510662 is a reply to message #509650] Thu, 28 January 2010 04:34 Go to previous messageGo to next message
Eclipse UserFriend
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 09:06 Go to previous message
Eclipse UserFriend
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,
Previous Topic:[Acceleo] Suggestion : icons for autocompletion
Next Topic:Xpand vs Acceleo vs JET
Goto Forum:
  


Current Time: Tue Jul 22 18:52:32 EDT 2025

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

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

Back to the top