我在 Eclipse 工作区中有 A 类和继承 A 的 B 类。
我遇到的问题是,当我尝试使用 eclipse JDT API 获取 B 类的超级类型时,我什么也没得到。这是代码(我从 - List all subclasses with fullqualified names得到代码):
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
java.io.File workspaceDirectory = root.getLocation().toFile();
// 1. The name of the project in the workspace
IProgressMonitor pm = new NullProgressMonitor();
IProject orig = root.getProject(this.projectName);
orig.open(pm);
this.javaProject = JavaCore.create(orig);
orig.refreshLocal(IResource.DEPTH_INFINITE, pm);
// 2. Find the type
IType type = this.javaProject.findType("p.B"); <-- returns correct type info
ITypeHierarchy hier = type.newSupertypeHierarchy(new NullProgressMonitor());
IType[] types = hier.getAllSuperclasses(type);
System.out.println(types); <-- Returns []
我还添加了代码来刷新/更新包中的资源。
IPackageFragmentRoot[] packageFragmentRoots = this.javaProject.getPackageFragmentRoots();
for (IPackageFragmentRoot proot: packageFragmentRoots)
{
proot.getResource().refreshLocal(IResource.DEPTH_INFINITE, null);
}
除了获取分层类型信息外,一切正常。可能有什么问题?在执行 API 之前我是否错过了任何设置?
我的是一个无头 RCP 应用程序。