我正在处理 xtext 项目,我正在通过 .xtext 文件生成对象。我想将新属性添加到生成的对象之一。我在http://christiandietrich.wordpress.com/2011/07/22/customizing-xtext-metamodel-inference-using-xtend2/ 中看到以下代码在 ObjectValue 中生成一个临时变量,但我希望 temp 是 MyObject 类型.
怎么做?我在哪里可以读到它?
import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage
import org.eclipse.emf.common.util.BasicEMap$Entry
import org.eclipse.emf.ecore.EClass
import org.eclipse.emf.ecore.EPackage
import org.eclipse.emf.ecore.EcoreFactory
import org.eclipse.emf.ecore.EcorePackage
import org.eclipse.xtext.GeneratedMetamodel
import org.eclipse.xtext.xtext.ecoreInference.IXtext2EcorePostProcessor
class CodeGeneratorClass implements IXtext2EcorePostProcessor {
override process(GeneratedMetamodel metamodel) {
metamodel.EPackage.process
}
def process(EPackage p) {
for (c : p.EClassifiers.filter(typeof(EClass))) {
if (c.name == "ObjectValue") {
c.handle
}
}
}
def handle (EClass c) {
val attr = EcoreFactory::eINSTANCE.createEAttribute
attr.name = "temp"
attr.EType = EcorePackage::eINSTANCE.EString
c.EStructuralFeatures += attr
}
}