[英]Nested classes with EMF/ecore
The ecore model editor does not allow adding classes as children to classes; ecore模型编辑器不允许将类作为子类添加到类中。 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? 有什么方法可以在ecore文件中对嵌套类之类的东西建模?
You cannot create nested EClasses
in Ecore. 您不能在Ecore中创建嵌套的
EClasses
。 The only elements that can be contained by EClass
are EStructuralFeatures
(references and attributes), EOperation
, EAnnotation
, EGenericType
and ETypeParameter
. EClass
只能包含的EClass
是EStructuralFeatures
(引用和属性), EOperation
, EAnnotation
, EGenericType
和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 看看Ecore元模型: 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)
为了在元模型中的两个EClass对象之间创建包含引用,您必须创建一个
EReference ereference=EcoreFactory.eInstance.create
并添加为母类: motherclass.getEReferences().add(ereference)
and put the children class as EType of the ereference. 并将children类作为ereference的EType。
ereference.setEType()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.