| [news.eclipse.modeling.m2t] Re: [MTL] How to reverse lists ? |
Hi,
Cheers,
Jonathan
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 !