简体   繁体   English

遍历ecore模型

[英]Traverse ecore model

I have generated model code from Ecore. 我已经从Ecore生成了模型代码。 Within my model I have a derived reference: derivedThings . 在我的模型中,我有一个派生的引用: derivedThings

What I want to do in the derivedThingsImpl is the following: 我想在derivedThingsImpl做的derivedThingsImpl如下:

I want to traverse the whole model and depending on the element, I want to add it to a collection or not. 我想遍历整个模型,并且根据元素,我想是否将其添加到集合中。

for(TreeIterator iter = EcoreUtil.getAllContents(rootObject); iter.hasNext();)
 ...

The problem is, how can I access the root object from the derivedThingsImpl ?! 问题是,我怎么能从derivedThingsImpl访问根对象? is there something like getRootObject() ?! 是否有类似getRootObject()东西?

Thanks 谢谢

UPDATE: 更新:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM