Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [QVT] Adding element to feature
[QVT] Adding element to feature [message #723721] Fri, 09 September 2011 09:13 Go to next message
Wilbert Alberts is currently offline Wilbert AlbertsFriend
Messages: 212
Registered: June 2010
Senior Member
Hi,

Is it possible to add an element to a reference with a multiplicity larger then 1?

The goal is to add an element to a feature which is not known at forehand but dynamically computed. So in the end, I end up with the following helper:

helper setObjectInSingleFeature(e: EObject, f: EStructuralFeature, a: Element)
{
   e.eSet(f, a);
}


This works in case the feature has an upper bound of 1. What if the feature represents a collection? One would like to be able to do something like:

helper setObjectInMultiFeature(e: EObject, f: EStructuralFeature, a: Element)
{
   var entries := e.eGet(f);
   var newEntries := entries->asSequence().insertAt(0,a);
   e.eSet(f, newEntries);
}


However, this is not possible due to the fact that eSet expects an EJavaObject (or OclAny). I don't know how to make a sequence look like an EJavaObject, OclAny or EObject. A simple cast (oclAsType) doesn't seem to work?

Any ideas?
Re: [QVT] Adding element to feature [message #725142 is a reply to message #723721] Wed, 14 September 2011 04:56 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7679
Registered: July 2009
Senior Member
Hi

Using eSet and eGet in QVTo ignores the capabilities of QVTo to
transform rather than poke and peek. Occasionally you want to fold
multiple passes into a single transforation, so QVTo's List and Dict may
come in helpful.

However if you really want to treat QVTo as a wrapper for the EMF Java
API, you should learn to use EMF, then you will understand that EMF
collection manipulation uses .get().add()...

Regards

Ed Willink


On 09/09/2011 10:13, Wilbert Alberts wrote:
> Hi,
> Is it possible to add an element to a reference with a multiplicity
> larger then 1?
>
> The goal is to add an element to a feature which is not known at
> forehand but dynamically computed. So in the end, I end up with the
> following helper:
>
> helper setObjectInSingleFeature(e: EObject, f: EStructuralFeature, a:
> Element)
> {
> e.eSet(f, a);
> }
>
> This works in case the feature has an upper bound of 1. What if the
> feature represents a collection? One would like to be able to do
> something like:
>
> helper setObjectInMultiFeature(e: EObject, f: EStructuralFeature, a:
> Element)
> {
> var entries := e.eGet(f);
> var newEntries := entries->asSequence().insertAt(0,a);
> e.eSet(f, newEntries);
> }
>
>
> However, this is not possible due to the fact that eSet expects an
> EJavaObject (or OclAny). I don't know how to make a sequence look like
> an EJavaObject, OclAny or EObject. A simple cast (oclAsType) doesn't
> seem to work?
>
> Any ideas?
>
Previous Topic:How to handle references?
Next Topic:[QVT] undeterministic behaviour - sometimes classifiers disappear
Goto Forum:
  


Current Time: Sat Nov 09 02:53:32 GMT 2024

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

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

Back to the top