为什么 IJavaProject.findPackageFragmentRoots 返回空数组?

发布于 2024-09-11 11:56:45 字数 1525 浏览 9 评论 0原文

每次我调用 IJavaProject.findPackageFragmentRoots(IClasspathEntry cpe) 并向其传递 CPE_PROJECT 类型的 IClasspathEntry 时,它都会返回一个空列表。我暂停了调试器,并在 Eclipse Display 视图中运行以下几行来查看发生了什么:

IClasspathEntry cpe = javaProject.getRawClasspath()[8];
cpe.toString();
    (java.lang.String) /Some Project[CPE_PROJECT][K_SOURCE][isExported:false][combine access rules:false]

// Show that the referenced project exists and has a root containing source
IClasspathEntry cpe = javaProject.getRawClasspath()[8];
IProject someProject = ResourcesPlugin.getWorkspace().getRoot().getProject(cpe.getPath().toString());
IJavaProject someJavaProject = (IJavaProject) someProject.getNature(JavaCore.NATURE_ID);
IPackageFragmentRoot pfr = someJavaProject.getPackageFragmentRoots()[0];
new Boolean(pfr.getKind() == IPackageFragmentRoot.K_SOURCE).toString();
    (java.lang.String) true

IClasspathEntry cpe = javaProject.getRawClasspath()[8];
javaProject.findPackageFragmentRoots(cpe);
    (org.eclipse.jdt.core.IPackageFragmentRoot[]) []

类路径条目是 Java 项目类路径的一部分,并且属于 CPE_PROJECT 类型。此外,引用的 Java 项目(标题为“Some Project”)至少有一个包含源代码的根。根据 IJavaProject 的 javadoc,看起来这应该至少返回一个 IPackageFragmentRoot,但事实并非如此。

知道我在这里误解了什么吗?如何从 CPE_PROJECT 类型的 IClasspathEntry 获取 IPackageFragmentRoots 而不做一些黑客行为? (我的意思是,我可以从类路径条目获取 IJavaProject 并迭代其原始类路径,忽略未导出的条目,以搜索 IPackageFragmentRoots。)

Every time I call IJavaProject.findPackageFragmentRoots(IClasspathEntry cpe) and pass it an IClasspathEntry of kind CPE_PROJECT, it returns an empty list. I paused the debugger and ran the following lines in the Eclipse Display view to see what was going on:

IClasspathEntry cpe = javaProject.getRawClasspath()[8];
cpe.toString();
    (java.lang.String) /Some Project[CPE_PROJECT][K_SOURCE][isExported:false][combine access rules:false]

// Show that the referenced project exists and has a root containing source
IClasspathEntry cpe = javaProject.getRawClasspath()[8];
IProject someProject = ResourcesPlugin.getWorkspace().getRoot().getProject(cpe.getPath().toString());
IJavaProject someJavaProject = (IJavaProject) someProject.getNature(JavaCore.NATURE_ID);
IPackageFragmentRoot pfr = someJavaProject.getPackageFragmentRoots()[0];
new Boolean(pfr.getKind() == IPackageFragmentRoot.K_SOURCE).toString();
    (java.lang.String) true

IClasspathEntry cpe = javaProject.getRawClasspath()[8];
javaProject.findPackageFragmentRoots(cpe);
    (org.eclipse.jdt.core.IPackageFragmentRoot[]) []

The classpath entry is part of the Java project's classpath and it's of kind CPE_PROJECT. In addition, the referenced Java project (titled "Some Project") has at least one root containing source. According to the javadoc for IJavaProject, it seems this should return at least one IPackageFragmentRoot, but its doesn't.

Any idea what I'm misunderstanding here? How can I get the IPackageFragmentRoots from an IClasspathEntry of kind CPE_PROJECT without doing something hackish? (I mean, I could get the IJavaProject from the classpath entry and iterate through its raw classpath, ignoring non-exported entries, in search of IPackageFragmentRoots.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浸婚纱 2024-09-18 11:56:45

这是 Eclipse 3.7 中修复的错误(请参阅 https://bugs.eclipse .org/bugs/show_bug.cgi?id=324367)。

根据新的 API:

结果不包括此项目的类路径上引用的其他项目中的包片段根。

请参阅

This was a bug that was fixed in Eclipse 3.7 (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=324367).

As per the new API:

The result does not include package fragment roots in other projects referenced on this project's classpath.

See http://help.eclipse.org/indigo/index.jsp?topic=/org.eclipse.jdt.doc.isv/reference/api/org/eclipse/jdt/core/IJavaProject.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文