Daniel Megert schrieb:
exquisitus wrote:
Hi,
Sorry if the question has been already answered, but I didn't found
the (entry) point... :-(
How may I determine the superclass(es) from a given source IType. I'm
finally interested in deciding, if a IMethod overrides a derived one
and/or implements an interface method.
For a pointer take a look at the methods in
org.eclipse.jdt.internal.corext.util.JavaModelUtil.
Dani
Thanks in advance,
Sven
Got it. Just for Thread completion:
IMethod method = ...
IType type = method.getDeclaringType();
ITypeHierarchy typeHierarchy = type.newSupertypeHierarchy(null);
IType superclass = typeHierarchy.getSuperclass(type);
while(superclass != null) {
IMethod[] methods = superclass.getMethods();
for (IMethod superMethod : methods) {
if (equals(method, superMethod)) {
// is derived method
}
}
}
static boolean equals(IMethod m1, IMethod m2) throws
JavaModelException {
if (m1 == m2) return true;
if (m1 == null || m2 == null) return false;
boolean b = m1.getElementName().equals(m2.getElementName());
String r1 = m1.getReturnType();
String r2 = m2.getReturnType();
b = b && equals(r1, r2); // null safe equals
String[] p1 = m1.getParameterTypes();
String[] p2 = m2.getParameterTypes();
b = b && Arrays.deepEquals(p1, p2);
String[] e1 = m1.getExceptionTypes();
String[] e2 = m2.getExceptionTypes();
b = b && Arrays.deepEquals(e1, e2);
return b;
}
static boolean equals(String s1, String s2) {
if (s1 == s2) return true;
if (s1 == null || s2 == null) return false;
return s1.equals(s2);
}