Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Duplicated EReferences in a ecore Model
Duplicated EReferences in a ecore Model [message #1148505] Mon, 21 October 2013 14:59 Go to next message
Amine BENELALLAM is currently offline Amine BENELALLAMFriend
Messages: 13
Registered: January 2013
Junior Member
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 #1148557 is a reply to message #1148505] Mon, 21 October 2013 15:43 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Amine,

Comments below.

On 21/10/2013 4:59 PM, Amine BENELALLAM wrote:
> 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).
What is "it"? Where are you seeing duplication?
> Have anyone came accross this issue ?
> how to solve this ?
> Cheers


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Duplicated EReferences in a ecore Model [message #1148624 is a reply to message #1148557] Mon, 21 October 2013 16:36 Go to previous messageGo to next message
Amine BENELALLAM is currently offline Amine BENELALLAMFriend
Messages: 13
Registered: January 2013
Junior Member

Ed,
an error merged while manipulating the model, so, I debugged and noticed this duplication.

[Updated on: Mon, 21 October 2013 16:37]

Report message to a moderator

Re: Duplicated EReferences in a ecore Model [message #1148669 is a reply to message #1148624] Mon, 21 October 2013 17:14 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Amine,

Comments below.


On 21/10/2013 6:36 PM, Amine BENELALLAM wrote:
> an error merged while manipulating the model
Is it possible to be more vague?
> , 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?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Duplicated EReferences in a ecore Model [message #1148711 is a reply to message #1148669] Mon, 21 October 2013 17:50 Go to previous messageGo to next message
Amine BENELALLAM is currently offline Amine BENELALLAMFriend
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 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
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 #1149654 is a reply to message #1149263] Tue, 22 October 2013 08:06 Go to previous messageGo to next message
Amine BENELALLAM is currently offline Amine BENELALLAMFriend
Messages: 13
Registered: January 2013
Junior Member
Ed,
I absolutly agree with you. The one I am using to retieve the featureID is 'strFeature.getFeatureID()'. Within the same loop and method calling for instance :
 for (EReference eRef : class.getEAllReferences()) {
    eRef.getFeatureId();   
       }
, I get two different references with the same ID, these references are respectively the last one coming from the first inherited class and the first one from the second inherited class.
Re: Duplicated EReferences in a ecore Model [message #1149747 is a reply to message #1149654] Tue, 22 October 2013 09:22 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Amine,

So it's clear now that there is no duplicate reference? I.e., it's
clear now that's it's expected that there can (and definitely will be in
the case of multiple inheritance) more than one feature f for which
fgetFeatureID() returns 0?

On 22/10/2013 10:06 AM, Amine BENELALLAM wrote:
> Ed, I absolutly agree with you. The one I am using to retieve the
> featureID is 'strFeature.getFeatureID()'. Within the same loop and
> method calling for instance : for (EReference eRef :
> class.getEAllReferences()) {
> eRef.getFeatureId(); }, I get two different references with
> the same ID, these references are respectively the last one coming
> from the first inherited class and the first one from the second
> inherited class.
>


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 Go to previous messageGo to next message
Amine BENELALLAM is currently offline Amine BENELALLAMFriend
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 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
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 Go to previous message
Abel  Gómez is currently offline Abel GómezFriend
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:

index.php/fa/17837/0/

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.

Previous Topic:[CDO] Auto release lock on transaction or session close ?
Next Topic:how to get the model element from a FeatureMapEntryWrapperItemProvider ?
Goto Forum:
  


Current Time: Fri Apr 26 02:25:19 GMT 2024

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

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

Back to the top