Home » Modeling » EMF » Duplicated EReferences in a ecore Model
| | | |
Re: Duplicated EReferences in a ecore Model [message #1148711 is a reply to message #1148669] |
Mon, 21 October 2013 17:50 |
Amine BENELALLAM Messages: 13 Registered: January 2013 |
Junior Member |
|
|
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.
The first thing that came to my mind is that may be I am calling the wrong reference
> , 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.
Thank you for your patience
Cheers
[Updated on: Mon, 21 October 2013 17:53] Report message to a moderator
|
|
|
Re: Duplicated EReferences in a ecore Model [message #1149263 is a reply to message #1148711] |
Tue, 22 October 2013 02:16 |
Ed Merks Messages: 33141 Registered: July 2009 |
Senior Member |
|
|
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
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | |
Re: Duplicated EReferences in a ecore Model [message #1154670 is a reply to message #1149747] |
Fri, 25 October 2013 11:14 |
Amine BENELALLAM Messages: 13 Registered: January 2013 |
Junior Member |
|
|
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 17:45 |
Ed Merks Messages: 33141 Registered: July 2009 |
Senior Member |
|
|
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
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Duplicated EReferences in a ecore Model [message #1277103 is a reply to message #1154670] |
Tue, 25 March 2014 14:05 |
Abel Gómez Messages: 1 Registered: July 2009 |
Junior Member |
|
|
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 Apr 26 02:25:19 GMT 2024
Powered by FUDForum. Page generated in 0.03474 seconds
|