From 940344589aac781412d8270d10cf6fd978122c66 Mon Sep 17 00:00:00 2001
From: Daniel Ratiu <ratiu@fortiss.org>
Date: Fri, 30 Dec 2011 15:22:21 +0000
Subject: [PATCH] A first baseline of model-checking of simple code
 specifications. refs 411

---
 .../tooling/kernel/utils/EcoreUtils.java      | 27 +++++++++++++++++++
 1 file changed, 27 insertions(+)

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 637690ea1..b88d7d687 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;
+	}
 }
-- 
GitLab