Get container feature of an EClass [message #422092] |
Thu, 21 August 2008 17:35 |
Eclipse User |
|
|
|
Originally posted by: swt.magellium.fr
Hello all !
First, I'd like to clarify thing ; stop me if I'm wrong :
Every EClass can have one (and only one) container feature. This happens
when this EClass is contained by another EClass using a containment
feature, and this containment feature has an opposite. This opposite
feature is then the container feature.
Now, if this is right : How can I retrieve the container feature of an
EClass?
Thanks a lot in advance !
Stephane
|
|
|
Re: Get container feature of an EClass [message #422093 is a reply to message #422092] |
Thu, 21 August 2008 18:08 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Stephane,
Comments below.
SWT wrote:
> Hello all !
>
> First, I'd like to clarify thing ; stop me if I'm wrong :
> Every EClass can have one (and only one) container feature.
Wrong. An EClass can be the target of an unlimited number of
containment features and each one can have an opposite in that EClass.
> This happens when this EClass is contained by another EClass using a
> containment feature, and this containment feature has an opposite.
> This opposite feature is then the container feature.
Yes, but the EClass can be the target of many containment features so
there can be many container features.
>
> Now, if this is right : How can I retrieve the container feature of an
> EClass?
You'd have to iterate over getEAllStructuralFeatures and filter it to
the ones for which isContainer is true.
Of course given an EObject instance x, x().eContainer() will return its
containing object and if that isn't null, x.eContainmentFeature() will
be non-null, and if there is an explicit container feature, then
x.eContainmentFeature().getEOpposite() will be non-null and that will be
the currently populated container feature.
>
> Thanks a lot in advance !
> Stephane
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Get container feature of an EClass [message #422110 is a reply to message #422093] |
Fri, 22 August 2008 08:41 |
Eclipse User |
|
|
|
Originally posted by: swt.magellium.fr
Ed,
Thank you for this explanation. Everything is clear now :)
In fact, I already tried to iterate over getEAllStructuralFeatures(),
but I didn't find the "isContainer()" method on EStructuralFeature.
But I know that container features are always EReferences, so using
getEAllReference() solved the problem... (EReference has a isContainer()
method...)
Note that I cannot use EObject.eContainer(), because that is actually
the method I'm trying to implement on a custom EStore class...
Anyway, my problem is solved, thanks again for your help !
Stephane
Ed Merks wrote :
> Stephane,
>
> Comments below.
>
>
> SWT wrote:
>> Hello all !
>>
>> First, I'd like to clarify thing ; stop me if I'm wrong :
>> Every EClass can have one (and only one) container feature.
> Wrong. An EClass can be the target of an unlimited number of
> containment features and each one can have an opposite in that EClass.
>> This happens when this EClass is contained by another EClass using a
>> containment feature, and this containment feature has an opposite.
>> This opposite feature is then the container feature.
> Yes, but the EClass can be the target of many containment features so
> there can be many container features.
>>
>> Now, if this is right : How can I retrieve the container feature of an
>> EClass?
> You'd have to iterate over getEAllStructuralFeatures and filter it to
> the ones for which isContainer is true.
>
> Of course given an EObject instance x, x().eContainer() will return its
> containing object and if that isn't null, x.eContainmentFeature() will
> be non-null, and if there is an explicit container feature, then
> x.eContainmentFeature().getEOpposite() will be non-null and that will be
> the currently populated container feature.
>>
>> Thanks a lot in advance !
>> Stephane
|
|
|
Powered by
FUDForum. Page generated in 0.03132 seconds