【问题标题】:EMF: Defining a generic containment reference in an Ecore metamodelEMF:在 Ecore 元模型中定义通用包含引用
【发布时间】:2021-06-22 08:33:23
【问题描述】:

我已经很久没有使用 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)
    }

【问题讨论】:

    标签: eclipse-emf ecore


    【解决方案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 一起使用

    【讨论】:

      猜你喜欢
      • 2021-03-12
      • 2018-10-13
      • 2012-02-28
      • 2021-12-18
      • 1970-01-01
      • 2019-11-06
      • 2011-04-09
      • 2011-12-28
      • 2012-04-04
      相关资源
      最近更新 更多