【问题标题】:Developing a Eclipse: How to get all inherited methods from a ICompilationUnit?开发 Eclipse:如何从 ICompilationUnit 获取所有继承的方法?
【发布时间】:2018-09-11 16:31:42
【问题描述】:

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

【问题讨论】:

    标签: java eclipse plugins eclipse-jdt pde


    【解决方案1】:

    我使用 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]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-16
      • 2011-05-26
      • 1970-01-01
      • 2020-08-27
      • 1970-01-01
      • 2019-03-15
      • 2017-05-14
      • 1970-01-01
      相关资源
      最近更新 更多