[QVT] Adding element to feature [message #723721] |
Fri, 09 September 2011 09:13 |
Wilbert Alberts 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 |
Ed Willink 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?
>
|
|
|
Powered by
FUDForum. Page generated in 0.03007 seconds