Skip to content
Snippets Groups Projects
Commit 9148471b authored by Johannes Eder's avatar Johannes Eder
Browse files

fixed getParentElement behaviour

parent 5ef87720
No related branches found
No related tags found
No related merge requests found
......@@ -38,7 +38,7 @@ import org.fortiss.tooling.kernel.service.IPersistencyService;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: AF4108116CA2222CFBF5FD1A83E6C48E
* @ConQAT.Rating YELLOW Hash: BC56E7A75A6B5ECC3B37218EEA28B9C2
*/
public final class KernelModelElementUtils {
......@@ -109,7 +109,10 @@ public final class KernelModelElementUtils {
* 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.
*
* @deprecated use {@link #getParentElement(EObject, Class, boolean)} instead
*/
@Deprecated
@SuppressWarnings("unchecked")
public static <T extends EObject> T getParentElement(EObject element, Class<T> targetClass) {
EObject currentParent = element;
......@@ -119,6 +122,33 @@ public final class KernelModelElementUtils {
return (T)currentParent;
}
/**
* 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.
* @param isReflexive
* boolean indicating if a parent can be a parent to itself
* @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,
boolean isReflexive) {
EObject currentParent;
if(isReflexive)
currentParent = element;
else
currentParent = element.eContainer();
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 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