eclipse-emf - EMF:在 Ecore 元模型中定义通用包含引用
问题描述
自从我使用 EMF 已经很长时间了,我一直坚持这一点。我想创建一个等效于的泛型类型:
class Result<T:ASTNode>{
T root;
}
我在 Kotlin 中定义这个:
val result = ePackage.createEClass("Result").apply {
// I think this part is correct
val typeParameter = EcoreFactory.eINSTANCE.createETypeParameter().apply {
this.name = "T"
this.eBounds.add(EcoreFactory.eINSTANCE.createEGenericType().apply {
// astNode is my EClass
this.eClassifier = astNode
})
}
this.eTypeParameters.add(typeParameter)
val rootContainment = EcoreFactory.eINSTANCE.createEReference()
rootContainment.name = "root"
// STUCK!
// here should I set rootContainment.eType? rootContainment.eGenericType?
// how?
rootContainment.isContainment = true
rootContainment.lowerBound = 0
rootContainment.upperBound = 1
this.eStructuralFeatures.add(rootContainment)
addContainment("issues", issue, 0, -1)
}
解决方案
等效的 .ecore 是:
<eClassifiers xsi:type="ecore:EClass" name="Result">
<eTypeParameters name="T">
<eBounds eClassifier="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eTypeParameters>
<eStructuralFeatures xsi:type="ecore:EReference" name="t">
<eGenericType eTypeParameter="#//Result/T"/>
</eStructuralFeatures>
所以你想使用rootContainment.eGenericType
一个引用你的 ETypeParameter 的新 EGenericType
推荐阅读
- c# - 返回带有批处理响应的 HttpResponseMessage
- html - Typescript:从返回不稳定结果的 HTML 中获取 id 元素
- android-studio - 重复时小部件“跳过”ID号
- python - 多幅图像中的主色
- cas - 如果 X.509 用户未注册,则阻止 CAS 身份验证
- c++ - 当顶点在 for 循环中时 glDrawElements 不绘制
- r - geom_mosaic() 中的 product() 不接受 R Shiny 上的反应输入?
- c++ - 如何在不污染缓存的情况下读取大量数据?
- hadoop - 为什么hadoop对于一个简单的hello world工作很慢
- xaml - Xamarin Forms:我可以制作一个可以由不同页面动态更改的自定义模板吗?