From b6b4577f48cdc1bc89918cd12259565866a0ac56 Mon Sep 17 00:00:00 2001
From: Andreas Bayha <bayha@fortis.org>
Date: Tue, 12 Jul 2016 11:08:59 +0000
Subject: [PATCH] Created additional Util method getFirstParentWithType.

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

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 7569bebbc..53e06e98d 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
@@ -55,7 +55,7 @@ import org.eclipse.emf.ecore.util.EcoreUtil.UsageCrossReferencer;
  * @author ratiu
  * @author $Author: hoelzl $
  * @version $Rev: 18709 $
- * @ConQAT.Rating GREEN Hash: DCA15548774DAD2A0A1B51F5B6AC808E
+ * @ConQAT.Rating YELLOW Hash: B57ACDA4FC8E3B3B2C2EE50008A3D8EE
  */
 public class EcoreUtils {
 
@@ -292,6 +292,30 @@ public class EcoreUtils {
 		return parentElements;
 	}
 
+	/**
+	 * Returns the first parent {@link EObject} that has the type <code>T</code>. If none are
+	 * found, null is returned.
+	 * 
+	 * @param startElement
+	 *            The {@link EObject} from which the "upwards" search shall begin.
+	 * @param type
+	 *            The class type to find the first parent with.
+	 * @return List of parent {EObject} of type <code>T</code>.
+	 */
+	@SuppressWarnings("unchecked")
+	public static <T extends EObject> T getFirstParentWithType(EObject startElement, Class<T> type) {
+
+		EObject currentParent = startElement.eContainer();
+
+		while(currentParent != null) {
+			if(type.isAssignableFrom(currentParent.getClass())) {
+				return (T)currentParent;
+			}
+			currentParent = currentParent.eContainer();
+		}
+		return null;
+	}
+
 	/**
 	 * Posts a {@link Notification} with an event type ID outside the EMF
 	 * default notification IDs to cause UI refreshes.
-- 
GitLab