当我编写eclipse插件时,如何从ICompilationUnit中找到所有方法,包括继承的方法?当我调用方法 getMethods()时,没有继承的方法。
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
IFile file = (IFile) receiver;
try {
IJavaElement element = JavaCore.create(file);
ICompilationUnit icu = (ICompilationUnit) element;
IType[] types = icu.getTypes();
return hasMethodCalledTest(types[0]);
} catch (Exception e) {
System.out.println();
}
return false;
}
public boolean hasMethodCalledTest(IType typeClass) {
typeClass.getMethods();//There is no inherited method here.
return false;
}
答案 0 :(得分:0)
我使用 ITypeHierarchy
找到了解决方案IJavaElement element = JavaCore.create(file);
ICompilationUnit icu = (ICompilationUnit) element;
IType[] types = icu.getTypes();
ITypeHierarchy th = types[0].newTypeHierarchy(new NullProgressMonitor());
IType[] superTypes = th.getAllSuperclasses(types[0]);