我已经从Ecore生成了模型代码。在我的模型中,我有一个派生引用:derivedThings。
我想在derivedThingsImpl中做的事情如下:
我希望遍历整个模型,并根据元素的不同,将其添加到集合中。
for(TreeIterator iter = EcoreUtil.getAllContents(rootObject); iter.hasNext();)
...问题是,我如何从derivedThingsImpl访问根对象?!有没有像getRootObject()这样的东西?!
谢谢
更新:
EObject e = this;
while(e.eContainer() != null) {
e = e.eContainer()
if (e instanceof RootElement)
break;
}
// No I should have the root element. Is this a good and clean way ?!发布于 2012-05-12 00:21:51
有一种更好的方法:
EcoreUtil.getRootContainer(eObject);https://stackoverflow.com/questions/10495112
复制相似问题