[英]Traverse ecore model
我已经从Ecore生成了模型代码。 在我的模型中,我有一个派生的引用: derivedThings
。
我想在derivedThingsImpl
做的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 ?!
有一种更好的方法:
EcoreUtil.getRootContainer(eObject);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.