|Re: [EMF] Problems with multiple supertypes in programatic metamodel creation [message #1064881 is a reply to message #1064874]
||Fri, 21 June 2013 13:56
| Ed Merks
Registered: July 2009
On 21/06/2013 3:47 PM, Simon Goodall wrote:
> 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();
> 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;
> 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
> Have I missed something in my test code?
Powered by FUDForum
. Page generated in 0.02466 seconds