From 863d9661369947de17f77f8274c0ceb9b27eb7d5 Mon Sep 17 00:00:00 2001 From: Vincent Aravantinos <aravantinos@fortiss.org> Date: Mon, 17 Jul 2017 09:08:45 +0000 Subject: [PATCH] adds the method isAncestor refs 2955 --- .../tooling/kernel/utils/EcoreUtils.java | 18 +++++++++++++++++- 1 file changed, 17 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 28ae0d444..09591a1c9 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 @@ -60,7 +60,7 @@ import org.eclipse.emf.ecore.util.EcoreUtil.Copier; * @author ratiu * @author $Author: hoelzl $ * @version $Rev: 18709 $ - * @ConQAT.Rating YELLOW Hash: DC361AE6E00DAE9F9178257FA915CCC4 + * @ConQAT.Rating YELLOW Hash: A74FA7C1F289F4F252E353D4F2AEC64E */ public class EcoreUtils { @@ -308,6 +308,22 @@ public class EcoreUtils { return null; } + /** + * Returns true if <code>candidateAncestor</code> is an ancestor of <code>startElement</code>. + * + * An element is not an ancestor of itself! + */ + public static boolean isAncestor(EObject startElement, EObject candidateAncestor) { + EObject currentParent = startElement.eContainer(); + while(currentParent != null) { + if(currentParent == candidateAncestor) { + return true; + } + currentParent = currentParent.eContainer(); + } + return false; + } + /** * Posts a {@link Notification} with an event type ID outside the EMF * default notification IDs to cause UI refreshes. -- GitLab