Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [EMF] Problems with multiple supertypes in programatic metamodel creation
[EMF] Problems with multiple supertypes in programatic metamodel creation [message #1064874] Fri, 21 June 2013 13:47 Go to next message
Simon Goodall is currently offline Simon Goodall
Messages: 11
Registered: July 2009
Junior Member
Hi,

I have a normal ECore model registered via plugin.xml etc. Now in some
test code I am manually creating an EPackage and an EClass and setting
the EClass to have two supertypes - both of which are in my .ecore file.

EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
EClass cls = EcoreFactory.eINSTANCE.createEClass();

cls.setName("TestClass");

cls.getESuperTypes().add(MyECorePackage.eINSTANCE.getClassA());
cls.getESuperTypes().add(MyECorePackage.eINSTANCE.getClassB());

ePackage.getEClassifiers().add(cls);

I can then create an instance of this class;

EObject eObj = ePackage.getEFactoryInstance().create(cls);

And set some features (string attributes);

eObj.eSet(MyECorePackage.eINSTANCE.getClassA_Name(), "name");
eObj.eSet(MyECorePackage.eINSTANCE.getClassB_Text(), "text");

However, this will fail;

Assert.assertEquals("name",
eObj.eGet(MyECorePackage.eINSTANCE.getClassA_Name()));

When debugging it seems that "text" will be returned. Inspecting the
class shows the EObject is an instance of ClassAImpl and it only has a
name attribute, not the text attribute.

Note - it would appear both these features have the same integer ID.
Also in my case ClassA and ClassB both have another class - say ClassC -
as a supertype.

This looks incorrect to myself on two counts; Firstly I was expecting a
DynamicEObjectImpl to be returned. I would also expect a feature not
found error when attempting to set the text field.

Is this expected behaviour? Have I missed something in my test code?

Thanks,

Simon
Re: [EMF] Problems with multiple supertypes in programatic metamodel creation [message #1064881 is a reply to message #1064874] Fri, 21 June 2013 13:56 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26152
Registered: July 2009
Senior Member
Simon,

Comments below.

On 21/06/2013 3:47 PM, Simon Goodall wrote:
> Hi,
>
> I have a normal ECore model registered via plugin.xml etc. Now in some
> test code I am manually creating an EPackage and an EClass and setting
> the EClass to have two supertypes - both of which are in my .ecore file.
That's already sounding problematic...
>
> EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
> EClass cls = EcoreFactory.eINSTANCE.createEClass();
>
> cls.setName("TestClass");
>
> cls.getESuperTypes().add(MyECorePackage.eINSTANCE.getClassA());
> cls.getESuperTypes().add(MyECorePackage.eINSTANCE.getClassB());
>
> ePackage.getEClassifiers().add(cls);
>
> I can then create an instance of this class;
>
> EObject eObj = ePackage.getEFactoryInstance().create(cls);
>
> And set some features (string attributes);
>
> eObj.eSet(MyECorePackage.eINSTANCE.getClassA_Name(), "name");
> eObj.eSet(MyECorePackage.eINSTANCE.getClassB_Text(), "text");
>
> However, this will fail;
>
> Assert.assertEquals("name",
> eObj.eGet(MyECorePackage.eINSTANCE.getClassA_Name()));
>
> When debugging it seems that "text" will be returned. Inspecting the
> class shows the EObject is an instance of ClassAImpl and it only has a
> name attribute, not the text attribute.
>
> Note - it would appear both these features have the same integer ID.
> Also in my case ClassA and ClassB both have another class - say ClassC
> - as a supertype.
>
> This looks incorrect to myself on two counts; Firstly I was expecting
> a DynamicEObjectImpl to be returned. I would also expect a feature not
> found error when attempting to set the text field.
No, that's the problem. When you extend a generated model, the
extension must implement all the generated interfaces. That's
generally accomplished by reusing the generated class and making it
behave like a dynamic object to implement the rest of the features
supported by the super types. But if you extend two generated classes,
it's simply not possible to have an implementation class that implements
all the generated interfaces, so it can't be supported.
>
> Is this expected behaviour?
Yes, dynamic models with more than one generated super class isn't
supported.
> Have I missed something in my test code?
>
> Thanks,
>
> Simon
Previous Topic:[SOLVED] Parts of EMF Plugin are not deployed on startup
Next Topic:Xcore syntax for object creation and initialization
Goto Forum:
  


Current Time: Fri Oct 31 17:22:05 GMT 2014

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

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