From e1669056a6ed1b0247e3518af2227bb6ea59c9dd Mon Sep 17 00:00:00 2001 From: Florian Hoelzl <hoelzl@fortiss.org> Date: Wed, 28 Dec 2011 16:27:28 +0000 Subject: [PATCH] extended STLC example with deployment refs 350 --- .../kernel/utils/KernelModelElementUtils.java | 28 ++++++++++++++++++- 1 file changed, 27 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 94d136c21..9394ecb8d 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 @@ -22,6 +22,7 @@ import java.util.Iterator; import org.eclipse.emf.ecore.EObject; import org.fortiss.tooling.kernel.model.IIdLabeled; import org.fortiss.tooling.kernel.model.IIdLabeledReference; +import org.fortiss.tooling.kernel.model.INamedElement; import org.fortiss.tooling.kernel.model.IProjectRootElement; import org.fortiss.tooling.kernel.service.IPersistencyService; @@ -31,7 +32,7 @@ import org.fortiss.tooling.kernel.service.IPersistencyService; * @author hoelzl * @author $Author$ * @version $Rev$ - * @ConQAT.Rating YELLOW Hash: BFAEE573B73BEA35ED5EC160F4015FB5 + * @ConQAT.Rating YELLOW Hash: E77DC792D810E6886DD06EC35AB21D0D */ public final class KernelModelElementUtils { @@ -112,4 +113,29 @@ public final class KernelModelElementUtils { } return false; } + + /** + * Iterates the content of the given root element and finds a contained + * element with the given name and the given class. + * + * @param root + * the root element to be searched + * @param name + * the name of the element to find + * @param clazz + * the class of the element to find + * @return the element found or <code>null</code> if none was found + */ + @SuppressWarnings("unchecked") + public static <T extends INamedElement> T findContentElementByNameAndClass( + EObject root, String name, Class<T> clazz) { + Iterator<EObject> iter = root.eAllContents(); + while (iter.hasNext()) { + EObject nxt = iter.next(); + if (clazz.isInstance(nxt) && ((T) nxt).getName().equals(name)) { + return (T) nxt; + } + } + return null; + } } -- GitLab