Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [MTL] How to reverse lists ?
[MTL] How to reverse lists ? [message #480033] Thu, 13 August 2009 14:06 Go to next message
No real name is currently offline No real nameFriend
Messages: 18
Registered: July 2009
Junior Member
Hey,

is there a MTL command to reverse a list (Collection ?, Sequence ?)
content (as acceleo's reverse() method ?)

Guillaume
Re: [MTL] How to reverse lists ? [message #480192 is a reply to message #480033] Fri, 14 August 2009 10:31 Go to previous messageGo to next message
Max Bureck is currently offline Max BureckFriend
Messages: 72
Registered: July 2009
Member
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.
Re: [MTL] How to reverse lists ? [message #480215 is a reply to message #480192] Fri, 14 August 2009 12:09 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 18
Registered: July 2009
Junior Member
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 !
Re: [MTL] How to reverse lists ? [message #480491 is a reply to message #480215] Mon, 17 August 2009 11:49 Go to previous messageGo to next message
Jonathan MUSSET is currently offline Jonathan MUSSETFriend
Messages: 43
Registered: July 2009
Member
Hi,

Thanks a lot for using Acceleo
You have to put the tag [Acceleo] at the beginning of the subject (and
not MTL)
MTL is the name of the OMG standard, so we can understand ;-)
but the name of the eclipse implementation is Acceleo

Cheers,

Jonathan




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 !
Re: [MTL] How to reverse lists ? [message #480773 is a reply to message #480215] Tue, 18 August 2009 12:52 Go to previous message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050605020300040506090009
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit

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
Previous Topic:Run JET template from java error
Next Topic:[XPAND] Xpand/Xtend Invoker builder slowdown
Goto Forum:
  


Current Time: Sat Apr 20 04:13:29 GMT 2024

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

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

Back to the top