From 4ededccc4eefeffc09f142f7a0f7ad34ec2bd3f7 Mon Sep 17 00:00:00 2001 From: Daniel Ratiu <ratiu@fortiss.org> Date: Thu, 5 Jan 2012 09:34:05 +0000 Subject: [PATCH] Added language compliance checking for model-checking-based analyzes. refs 385 --- .../kernel/utils/KernelModelElementUtils.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/KernelModelElementUtils.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/KernelModelElementUtils.java index e7334bcce..e99959876 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/KernelModelElementUtils.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/KernelModelElementUtils.java @@ -32,7 +32,7 @@ import org.fortiss.tooling.kernel.service.IPersistencyService; * @author hoelzl * @author $Author$ * @version $Rev$ - * @ConQAT.Rating YELLOW Hash: 9C6BFB0E29B3623A7A4BE3DC69FA3BEC + * @ConQAT.Rating YELLOW Hash: 38F43F6516A99A19C128B6706D7CBE45 */ public final class KernelModelElementUtils { @@ -55,6 +55,27 @@ public final class KernelModelElementUtils { .getRootModelElement().eContents()); } + /** + * Returns the parent of an element with a certain type. + * + * @param element + * a model element. + * @param targetClass + * the class of the parent that is returned. + * @return instance of class <code>targetClass</code> or <code>null</code> + * if no such parent element was found. + */ + @SuppressWarnings("unchecked") + public static <T extends EObject> T getParentElement(EObject element, + Class<T> targetClass) { + EObject currentParent = element; + while (currentParent != null + && !(targetClass.isAssignableFrom(currentParent.getClass()))) { + currentParent = currentParent.eContainer(); + } + return (T) currentParent; + } + /** * Finds the model element referenced by the given * {@link IIdLabeledReference} element or <code>null</code> if no such -- GitLab