简体   繁体   中英

Nested classes with EMF/ecore

The ecore model editor does not allow adding classes as children to classes; doing so manually as in

...
<eClassifiers xsi:type="ecore:EClass" name="Test_Class">
    <eClassifiers xsi:type="ecore:EClass" name="Nested_Class"></eClassifiers>
    ...

results in

org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature 'eClassifiers' not found. (platform:/resource/EMFTestProject/model/My.ecore, 5, 62)

Is there any way to model something like nested classes in ecore files?

You cannot create nested EClasses in Ecore. The only elements that can be contained by EClass are EStructuralFeatures (references and attributes), EOperation , EAnnotation , EGenericType and ETypeParameter .

Take a look to the Ecore metamodel: http://download.eclipse.org/modeling/emf/emf/javadoc/2.10.0/org/eclipse/emf/ecore/package-summary.html

For creating a containment reference between two EClass objects in a metamodel you have to create A EReference ereference=EcoreFactory.eInstance.create and add is the the mother class : motherclass.getEReferences().add(ereference)
and put the children class as EType of the ereference. ereference.setEType()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM