Skip to content
Snippets Groups Projects
Commit b6b4577f authored by Andreas Bayha's avatar Andreas Bayha
Browse files

Created additional Util method getFirstParentWithType.

parent 14b13897
No related branches found
No related tags found
No related merge requests found
......@@ -55,7 +55,7 @@ import org.eclipse.emf.ecore.util.EcoreUtil.UsageCrossReferencer;
* @author ratiu
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating GREEN Hash: DCA15548774DAD2A0A1B51F5B6AC808E
* @ConQAT.Rating YELLOW Hash: B57ACDA4FC8E3B3B2C2EE50008A3D8EE
*/
public class EcoreUtils {
......@@ -292,6 +292,30 @@ public class EcoreUtils {
return parentElements;
}
/**
* Returns the first parent {@link EObject} that has the type <code>T</code>. If none are
* found, null is returned.
*
* @param startElement
* The {@link EObject} from which the "upwards" search shall begin.
* @param type
* The class type to find the first parent with.
* @return List of parent {EObject} of type <code>T</code>.
*/
@SuppressWarnings("unchecked")
public static <T extends EObject> T getFirstParentWithType(EObject startElement, Class<T> type) {
EObject currentParent = startElement.eContainer();
while(currentParent != null) {
if(type.isAssignableFrom(currentParent.getClass())) {
return (T)currentParent;
}
currentParent = currentParent.eContainer();
}
return null;
}
/**
* Posts a {@link Notification} with an event type ID outside the EMF
* default notification IDs to cause UI refreshes.
......
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