Skip to content
Snippets Groups Projects
Commit a7859556 authored by Simon Barner's avatar Simon Barner
Browse files

- Move getFirstChildWithType() from ExplorationUtils to EcoreUtils

parent 7c6d2762
No related branches found
No related tags found
No related merge requests found
......@@ -241,6 +241,31 @@ public class EcoreUtils {
return children;
}
/**
* For a given {@link EObject}, recursively returns the first child that has a certain type.
* Using this method is more efficient than returning the first element of the result of
* {@link #getChildrenWithType(EObject, Class)}.
*
* @param parent
* the parent {@link EObject}
* @param type
* the type
*
* @return the first child of the given type.
*/
@SuppressWarnings("unchecked")
public static <S> S getFirstChildWithType(EObject parent, Class<S> type) {
TreeIterator<EObject> content = EcoreUtil.getAllContents(parent, true);
while(content.hasNext()) {
EObject child = content.next();
if(type.isAssignableFrom(child.getClass())) {
return (S)child;
}
}
return null;
}
/**
* Returns a list of all parent {@link EObject}s that have the type <code>T</code>. If none are
* found, an empty list is returned.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment