开发Eclipse:如何从ICompilationUnit获取所有继承的方法?

时间:2018-04-02 12:46:10

标签: java eclipse plugins eclipse-jdt pde

当我编写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;
 }

1 个答案:

答案 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]);