Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Direct access to the elements in a Collection or Sequence
[Acceleo] Direct access to the elements in a Collection or Sequence [message #714057] Tue, 09 August 2011 17:46 Go to next message
Tomas Balderas is currently offline Tomas BalderasFriend
Messages: 64
Registered: July 2010
Member
Hello

I am looking for an operation that returns the n-th element in a Sequence (or Collection if it is possible). I am transforming activity diagrams to source code and need to generate source code statements that use the name of the object flow edges incoming to an action's input pins. I am restricting every action to have only two input pins. Therefore, iterating over the collection of two input pins of an action is not convenient. The most readable solution to me is to directly access the instances of InputPin in the collection of input pins of every action.

Does anybody know how to directly access the elements in a collection (or sequence)? I looked for an operation in Accleo's Operation Reference and in the OCL specification and cannot find it. I think there should be support for this kind of access since I think it is a common requirement.

Thanks. Kindest regards.


/TB
Re: [Acceleo] Direct access to the elements in a Collection or Sequence [message #714064 is a reply to message #714057] Tue, 09 August 2011 17:53 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I think you want Sequence::at() or OrderedSet::at()

You can loop (in OCL and not that differently in Acceleo) with an index
counter as

Sequence{1..collection->size()}->forAll(i : Integer | collection->at(i)
.....)

Regards

Ed Willink

On 09/08/2011 18:46, Balderas wrote:
> Hello
>
> I am looking for an operation that returns the n-th element in a
> Sequence (or Collection if it is possible). I am transforming activity
> diagrams to source code and need to generate source code statements
> that use the name of the object flow edges incoming to an action's
> input pins. I am restricting every action to have only two input pins.
> Therefore, iterating over the collection of two input pins of an
> action is not convenient. The most readable solution to me is to
> directly access the instances of InputPin in the collection of input
> pins of every action.
>
> Does anybody know how to directly access the elements in a collection
> (or sequence)? I looked for an operation in Accleo's Operation
> Reference and in the OCL specification and cannot find it. I think
> there should be support for this kind of access since I think it is a
> common requirement.
>
> Thanks. Kindest regards.
Re: [Acceleo] Direct access to the elements in a Collection or Sequence [message #714263 is a reply to message #714064] Wed, 10 August 2011 07:19 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Hi,

Ed has answered perfectly, I only want to add that the "at(int)" method is only available for ordered collections. If you set the reference as "unordered" in your metamodel, you'll have to cast the collection to an ordered type prior to access it (with the potential randomness of the reordering it involves). These methods are not Acceleo methods, thus the correct place to find them was in the OCL operation reference for Sequence or OrderedSet.

The cast to ordered collections is done through "asSequence" or "asOrderedSet" :

-----
inputPins->asSequence()->at(1)
-----

Laurent Goubet
Obeo
Re: [Acceleo] Direct access to the elements in a Collection or Sequence [message #714287 is a reply to message #714263] Wed, 10 August 2011 08:35 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

As of Indigo, Eclipse OCL has its own library documentation
(auto-generated from the library model by Acceleo).

See
http://help.eclipse.org/indigo/topic/org.eclipse.ocl.doc/help/StandardLibrary.html
or the OCL Documentation in the Help Contents.

Regards

Ed Willink

On 10/08/2011 08:19, Laurent Goubet wrote:
> Hi,
>
> Ed has answered perfectly, I only want to add that the "at(int)"
> method is only available for ordered collections. If you set the
> reference as "unordered" in your metamodel, you'll have to cast the
> collection to an ordered type prior to access it (with the potential
> randomness of the reordering it involves). These methods are not
> Acceleo methods, thus the correct place to find them was in the OCL
> operation reference for
> http://wiki.eclipse.org/Acceleo/OCL_Operations_Reference#at_.28_index_:_Integer_.29_:_T
> or
> http://wiki.eclipse.org/Acceleo/OCL_Operations_Reference#at_.28_index_:_Integer_.29_:_T_2.
>
> The cast to ordered collections is done through "asSequence" or
> "asOrderedSet" :
>
> -----
> inputPins->asSequence()->at(1)
> -----
>
> Laurent Goubet
> Obeo
Previous Topic:JET Transformation fails when EMF model editor plugin installed
Next Topic:[Xtend] How to create and populate an XMLFeatureMap
Goto Forum:
  


Current Time: Thu Mar 28 17:39:58 GMT 2024

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

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

Back to the top