IModelElement.getAncestor(Class<E> clazz) method added
diff --git a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/core/IModelElement.java b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/core/IModelElement.java
index cb8beec..1f5fc14 100644
--- a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/core/IModelElement.java
+++ b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/core/IModelElement.java
@@ -224,6 +224,18 @@
 	IModelElement getAncestor(int ancestorType);
 
 	/**
+	 * Returns the first ancestor of this script element that has the given
+	 * type. Returns <code>null</code> if no such an ancestor can be found. This
+	 * is a handle-only method.
+	 * 
+	 * @param ancestorType
+	 *            the given type
+	 * @return the first ancestor of this script element that has the given
+	 *         type, null if no such an ancestor can be found
+	 */
+	<E extends IModelElement> E getAncestor(Class<E> clazz);
+
+	/**
 	 * Returns the first openable parent. If this element is openable, the
 	 * element itself is returned. Returns <code>null</code> if this element
 	 * doesn't have an openable parent. This is a handle-only method.
diff --git a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ModelElement.java b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ModelElement.java
index 41e925c..1d568e0 100644
--- a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ModelElement.java
+++ b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ModelElement.java
@@ -129,6 +129,18 @@
 		return null;
 	}
 
+	@SuppressWarnings("unchecked")
+	public <E extends IModelElement> E getAncestor(Class<E> elementClass) {
+		IModelElement element = this;
+		do {
+			if (elementClass.isInstance(element)) {
+				return (E) element;
+			}
+			element = element.getParent();
+		} while (element != null);
+		return null;
+	}
+
 	/**
 	 * @see IOpenable
 	 */