From 0ac40bdc5e55a048cf54c160ef40cee505b4d959 Mon Sep 17 00:00:00 2001 From: Daniel Ratiu <ratiu@fortiss.org> Date: Mon, 2 Jan 2012 16:19:02 +0000 Subject: [PATCH] added a small utility function --- .../kernel/utils/KernelModelElementUtils.java | 32 ++++++++++++++++++- 1 file changed, 31 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 9394ecb8d..e44ff67f5 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: E77DC792D810E6886DD06EC35AB21D0D + * @ConQAT.Rating YELLOW Hash: 4C3069E19588989D191FB58D5D51CE66 */ public final class KernelModelElementUtils { @@ -138,4 +138,34 @@ public final class KernelModelElementUtils { } return null; } + + /** + * Computes the qualified name relative to a parent element. + * + * @param parent + * the parent element. + * @param element + * the element whose relative name will be computed. + * @return the qualified name relative to the parent element or null if the + * parent element is not a container for element + */ + public static String computeRelativeName(INamedElement parent, + INamedElement element) { + String qualifiedName = element.getName(); + + EObject current = element.eContainer(); + while (current != null && current != parent) { + if (current instanceof INamedElement) { + qualifiedName = ((INamedElement) current).getName() + "." + + qualifiedName; + } + current = current.eContainer(); + } + + if (current == null) { + return null; + } + + return qualifiedName; + } } -- GitLab