| Super class references get lost when saving ecore models [message #412221] |
Fri, 17 August 2007 10:28  |
Eclipse User |
|
|
|
Hi there,
after upgrading to EMF 2.3 I have some problems regarding inheritance
between EClasses in generated Ecore models.
Background: For developing my Ecore models, I'm using a graphical UML
editor based on the Eclipse UML2 plugin. This plugin comes with a
UML-to-Ecore converter, which I am using. After upgrading to the latest
releases, the generalizations from the UML models get (partly) lost when
translating the models into Ecore and saving the Ecore file.
I have debugged into the issue and built a test case that reproduces the
problem (see test code below).
In detail:
- the org.eclipse.uml2.uml.util.UMLUtil$UML2EcoreConverter uses the new
EMF generics feature
- super classes are set by wrapping them into an EGenericType object and
adding this wrapper to the eGenericSuperTypes collection of the subclass
- this means the eSuperTypes collection of the subclass is NOT
initialized yet
When saving the Ecore file, the following things happen:
- all features of an EClass are iterated and checked if they must be saved
- this sooner or later accesses the isSetESuperTypes and the
isSetEGenericSuperTypes methods
- both of them return false, because the eSuperTypes collection is a
derived feature which has not been initialized yet (its still null), and
because the eGenericSuperTypes collection (which is not null) returns
false for the isSet method (eType is null)
- therefore, the inheritance will not be saved in the resulting ecore file
Workaround:
- iterate through the resource and call getESuperTypes() on all EClasses
before saving them
So, the question now is:
What is broken? Is the UML-to-Ecore-Converter not implemented correctly?
Or is it a bug in the save mechanism of EMF?
thank you,
Peter
Here is the sample code:
public class EMFTest
{
public static void main(String[] args)
{
// create a package with two classes
EPackage p1 = EcoreFactory.eINSTANCE.createEPackage();
p1.setName("mypackage");
EClass c1 = EcoreFactory.eINSTANCE.createEClass();
c1.setName("MySuperClass");
p1.getEClassifiers().add(c1);
EClass c2 = EcoreFactory.eINSTANCE.createEClass();
c2.setName("MySubClass");
p1.getEClassifiers().add(c2);
// Variant 1:
{
// with this, the super class reference will not be saved
EGenericType g1 = EcoreFactory.eINSTANCE.createEGenericType();
g1.setEClassifier(c1);
c2.getEGenericSuperTypes().add(g1);
}
// Variant 2:
{
// this works fine
// c2.getESuperTypes().add(c1);
}
ResourceSet rs = new ResourceSetImpl();
rs.getResourceFactoryRegistry().getExtensionToFactoryMap().p ut(
Resource.Factory.Registry.DEFAULT_EXTENSION,
new XMIResourceFactoryImpl());
URI uri = URI.createFileURI(new
File("test/model.ecore").getAbsolutePath());
Resource r = rs.createResource(uri);
r.getContents().add(p1);
try
{
r.save(Collections.EMPTY_MAP);
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
|
|
|
| Re: Super class references get lost when saving ecore models [message #412224 is a reply to message #412221] |
Fri, 17 August 2007 10:45   |
Eclipse User |
|
|
|
Peter,
Sounds like a bug. Please open a bugzilla and I'll investigate and fix
for next week's build.
Peter Hänsgen wrote:
> Hi there,
>
> after upgrading to EMF 2.3 I have some problems regarding inheritance
> between EClasses in generated Ecore models.
>
> Background: For developing my Ecore models, I'm using a graphical UML
> editor based on the Eclipse UML2 plugin. This plugin comes with a
> UML-to-Ecore converter, which I am using. After upgrading to the
> latest releases, the generalizations from the UML models get (partly)
> lost when translating the models into Ecore and saving the Ecore file.
>
>
> I have debugged into the issue and built a test case that reproduces
> the problem (see test code below).
>
> In detail:
> - the org.eclipse.uml2.uml.util.UMLUtil$UML2EcoreConverter uses the
> new EMF generics feature
> - super classes are set by wrapping them into an EGenericType object
> and adding this wrapper to the eGenericSuperTypes collection of the
> subclass
> - this means the eSuperTypes collection of the subclass is NOT
> initialized yet
>
> When saving the Ecore file, the following things happen:
> - all features of an EClass are iterated and checked if they must be
> saved
> - this sooner or later accesses the isSetESuperTypes and the
> isSetEGenericSuperTypes methods
> - both of them return false, because the eSuperTypes collection is a
> derived feature which has not been initialized yet (its still null),
> and because the eGenericSuperTypes collection (which is not null)
> returns false for the isSet method (eType is null)
> - therefore, the inheritance will not be saved in the resulting ecore
> file
>
> Workaround:
> - iterate through the resource and call getESuperTypes() on all
> EClasses before saving them
>
>
> So, the question now is:
> What is broken? Is the UML-to-Ecore-Converter not implemented
> correctly? Or is it a bug in the save mechanism of EMF?
>
>
> thank you,
> Peter
>
>
>
>
> Here is the sample code:
>
> public class EMFTest
> {
> public static void main(String[] args)
> {
> // create a package with two classes
> EPackage p1 = EcoreFactory.eINSTANCE.createEPackage();
> p1.setName("mypackage");
>
> EClass c1 = EcoreFactory.eINSTANCE.createEClass();
> c1.setName("MySuperClass");
> p1.getEClassifiers().add(c1);
>
> EClass c2 = EcoreFactory.eINSTANCE.createEClass();
> c2.setName("MySubClass");
> p1.getEClassifiers().add(c2);
>
>
> // Variant 1:
> {
> // with this, the super class reference will not be saved
> EGenericType g1 =
> EcoreFactory.eINSTANCE.createEGenericType();
> g1.setEClassifier(c1);
> c2.getEGenericSuperTypes().add(g1);
> }
> // Variant 2:
> {
> // this works fine
> // c2.getESuperTypes().add(c1);
> }
>
> ResourceSet rs = new ResourceSetImpl();
> rs.getResourceFactoryRegistry().getExtensionToFactoryMap().p ut(
> Resource.Factory.Registry.DEFAULT_EXTENSION,
> new XMIResourceFactoryImpl());
>
> URI uri = URI.createFileURI(new
> File("test/model.ecore").getAbsolutePath());
> Resource r = rs.createResource(uri);
> r.getContents().add(p1);
>
> try
> {
> r.save(Collections.EMPTY_MAP);
> }
> catch (IOException e)
> {
> e.printStackTrace();
> }
> }
> }
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.03884 seconds