Skip to content
Snippets Groups Projects
Commit 7c6d2762 authored by Simon Barner's avatar Simon Barner
Browse files

- Move DreamsPlatformUtils.getParentElements() -> KernelModelElementUtils

parent dc10af6b
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,7 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.utils;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
......@@ -144,6 +145,34 @@ public final class KernelModelElementUtils {
return (T)currentParent;
}
/**
* Returns the {@link List} of all parent elements of the given {@link EObject} that
* inherit from the given target {@link Class} (possibly including the element itself).
*
* @param element
* the element whose parents should be determined (possibly including the element
* itself)
*
* @param targetClass
* the {@link Class} "filter"
*
* @return {@link List} of all parent elements of the given {@link EObject} that
* inherit from the given target {@link Class} (possibly including the element itself)
*/
@SuppressWarnings("unchecked")
public static <T extends EObject> List<T> getParentElements(EObject element,
Class<T> targetClass) {
List<T> retList = new ArrayList<T>();
EObject currentElement = element;
while(currentElement != null && !(currentElement instanceof IProjectRootElement)) {
if(targetClass.isAssignableFrom(currentElement.getClass())) {
retList.add((T)currentElement);
currentElement = currentElement.eContainer();
}
}
return retList;
}
/**
* Finds the model element referenced by the given {@link IIdLabeledReference} element or
* <code>null</code> if no such element exists. The reference's model project is searched from
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment