简体   繁体   中英

Traverse ecore model

I have generated model code from Ecore. Within my model I have a derived reference: derivedThings .

What I want to do in the derivedThingsImpl is the following:

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 ?! is there something like 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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