Home » Modeling » EMF » Duplicated EReferences in a ecore Model
Duplicated EReferences in a ecore Model [message #1148505] |
Mon, 21 October 2013 10:59  |
Eclipse User |
|
|
|
Hi all!
When I use a metamodel where a class inherits from two (or more) other Classes; sometimes, it duplicates references (the last one from the inherited class and the first one from the actual class).
Have anyone came accross this issue ?
how to solve this ?
Cheers
|
|
| | | | |
Re: Duplicated EReferences in a ecore Model [message #1149263 is a reply to message #1148711] |
Mon, 21 October 2013 22:16   |
Eclipse User |
|
|
|
Amine,
Comments below.
On 21/10/2013 7:50 PM, Amine BENELALLAM wrote:
> Ed
> please see comments in red
>> an error merged while manipulating the model
> Is it possible to be more vague?
> This happened to me when I was trying to reflectively manipulate my
> models.
> I was trying to query data of type 'A' (for instance) but I get
> objects of type B.
That would be expected if B extends A.
>> , so, I debugged and noticed this duplication.
> Noticed it where? Yes, I imagine in the debugger, but what
> specifically do you see that makes you feel something has been
> duplicated?
> I run the debugger over the 'Class.getEAllReferences()', in the
> debugger view at the featureID field two different EReferences had the
> same featureID.
That's also expected. There's a difference between
EStructuralFeature.getFeatureID and
EClass.getFeatureID(EStructuralFeature). The former is the feature's ID
relative to the EClass in which is it defined/contained and the later is
it's position in the EClass's getEAllStructuralFeatures. With multiple
inheritance, the two IDs can be different. I.e., if you have A.x and
B.y and C extends A and B, then the feature ID of y will be 0, but if
for EClass C, when you call getFeatureID(y), you'll get see that it's 1.
> Thank you for your patience
> Cheers
|
|
| | |
Re: Duplicated EReferences in a ecore Model [message #1154670 is a reply to message #1149747] |
Fri, 25 October 2013 07:14   |
Eclipse User |
|
|
|
Hi Ed,
I reproduced a simple example to show you the issue (https://www.dropbox.com/s/1kjh7jkc4t8wq5o/fr.test.simple.zip).
This metamodel is composed of 5 eClasses (A..E), each has one eAttribute (aa..ee).
The Structure of the metamodel (inheritance and IDs in the real order) is as follow :
B->A (aa=0, bb=1)
C->A (aa=0, cc=1)
D->C (aa=0, cc=1, dd=2)
E->D,B (aa=0, cc=1, dd=2, bb=1, ee=4).
The issue I am pointing here is the same id value for (cc and bb).
Best regards
|
|
|
Re: Duplicated EReferences in a ecore Model [message #1155104 is a reply to message #1154670] |
Fri, 25 October 2013 13:45   |
Eclipse User |
|
|
|
So your concern is that the EcoreUtil.equals returns something you don't
expect and you attribute that to the feature IDs?
On 25/10/2013 1:14 PM, Amine BENELALLAM wrote:
> Hi Ed,
> I reproduced a simple example to show you the issue
> (https://www.dropbox.com/s/1kjh7jkc4t8wq5o/fr.test.simple.zip). This
> metamodel is composed of 5 eClasses (A..E), each has one eAttribute
> (aa..ee).
> The Structure of the metamodel (inheritance and IDs in the real order)
> is as follow : B->A (aa=0, bb=1)
> C->A (aa=0, cc=1)
> D->C (aa=0, cc=1, dd=2)
> E->D,B (aa=0, cc=1, dd=2, bb=1, ee=4).
> The issue I am pointing here is the same id value for (cc and bb).
> Best regards
|
|
|
Re: Duplicated EReferences in a ecore Model [message #1277103 is a reply to message #1154670] |
Tue, 25 March 2014 10:05  |
Eclipse User |
|
|
|
Hi Amine,
let me just to clarify how feature IDs work in the example you provide.
First, let's suppose that we have a model as the one you showed:

And second, lets suppose we have the following code:
public static void main(String[] args) {
EClass e = SimpleTestModelPackage.eINSTANCE.getE();
for (EStructuralFeature feat : e.getEAllStructuralFeatures()) {
System.out.print(feat.getName());
System.out.print(": ");
System.out.print(feat.getFeatureID());
System.out.print(":");
System.out.println(e.getFeatureID(feat));
}
}
In this case, the output of the execution of this code is:
aa: 0:0
cc: 1:1
dd: 2:2
bb: 1:3
ee: 4:4
As you can see, there's a difference between feat.getFeatureID() and e.getFeatureID(feat). That's because the method org.eclipse.emf.ecore.EStructuralFeature.getFeatureID() returns the ID relative to the containing class. The ID for both cc and bb is 1 relative to their corresponding classes (C and B). It makes sense, since B.bb and C.cc, as isolated elements, do not know that are also included in a subclass E.
In this case, to get the right numeric ID for a feature in a specific EClass, you have to ask that same EClass for the ID using the method org.eclipse.emf.ecore.EClass.getFeatureID(EStructuralFeature feature).
Regards,
Abel
NOTE: Find the example project attached.
|
|
|
Goto Forum:
Current Time: Fri Jul 04 19:48:16 EDT 2025
Powered by FUDForum. Page generated in 0.20859 seconds
|