diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/EcoreUtils.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/EcoreUtils.java index 637690ea1f6c2247d28d1d669bdd6e41ad98333c..b88d7d6874dc24e6b79e52da43f854c048f79a39 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/EcoreUtils.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/EcoreUtils.java @@ -23,6 +23,9 @@ import java.util.List; import org.eclipse.emf.common.util.BasicEList; import org.eclipse.emf.common.util.ECollections; import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.TreeIterator; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.util.EcoreUtil; /** * Utility methods for dealing with .ecore models. These methods should be used @@ -127,4 +130,28 @@ public class EcoreUtils { return (T) sourceElement; return null; } + + /** + * For a given EObject recursively returns all its children that have a + * certain type. + * + * @param parent + * - the parent EObject + * @param type + * - the type + * @return a list of children + */ + @SuppressWarnings("unchecked") + public static <S> EList<S> getChildrenWithType(EObject parent, Class<S> type) { + EList<S> children = new BasicEList<S>(); + TreeIterator<EObject> content = EcoreUtil.getAllContents(parent, true); + + while (content.hasNext()) { + EObject child = content.next(); + if (type.isAssignableFrom(child.getClass())) { + children.add((S) child); + } + } + return children; + } }