[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.m2t] Re: [MTL] How to reverse lists ?

Hi,

This iterate is indeed the way to go for now, the "old" acceleo's "nReverse" method has been proposed no equivalent for a simple reason : the incoming version of OCL should have its own "collection::reverse()" method for this.

Cheers,

Laurent Goubet
Obeo

Guillaume Bourel a écrit :
Max Bureck a écrit :
I don't know about hidden features of Acceleo, but it seems that OCL does not provide such a method on Collections and the MOF Model To Text standard does not include such a method in it's library. Here is a query I used for creating a new sequence that contains the elements in reverse order:

[query reverse(s : Collection(T)) : Sequence(T) =
s->iterate(x; acc : Sequence(T) = Sequence{} | acc->prepend(x) )/]


You will have troubles with the returned collection, due to the inferred type of the sequence. Here is an example how to use it:

[template operationInfo(o : Operation)]
Operation name: [o.name/]
Parameters (reverse): [o.ownedParameter->reverse()->collect(oclAsType(uml::Parameter)).name/] [/template]


I hope this helps.

It works well :)

Thanks a lot Mr.Bureck !

begin:vcard
fn:Laurent Goubet
n:Goubet;Laurent
org:<a href="http://www.obeo.fr/";>Obeo</a>
email;internet:laurent.goubet@xxxxxxx
url:http://www.obeo.fr
version:2.1
end:vcard