为什么IJavaProject。findpackagefragmentroot返回空数组?

时间:2023-01-14 12:03:57

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:

每次我调用IJavaProject。findPackageFragmentRoots(IClasspathEntry cpe)并将其传递给kind CPE_PROJECT的IClasspathEntry,它返回一个空列表。我暂停了调试器,并在Eclipse显示视图中运行下列代码行,以查看发生了什么:

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.

类路径条目是Java项目的类路径的一部分,它属于类CPE_PROJECT。此外,引用的Java项目(标题为“一些项目”)至少有一个根包含源。根据IJavaProject的javadoc,它似乎应该返回至少一个IPackageFragmentRoot,但它没有。

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.)

你知道我在这里误解了什么吗?我怎样才能从一个类似CPE_PROJECT的IClasspathEntry中获得IPackageFragmentRoots,而不需要做一些黑客行为呢?(我的意思是,我可以从类路径条目中获取IJavaProject,并通过它的原始类路径进行迭代,忽略非导出的条目,以搜索ipackagefragmentroot。)

1 个解决方案

#1


0  

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

这是一个在Eclipse 3.7中修复的bug(参见https://bugs.eclipse.org/bugs/show_bug.cgi?id=324367)。

As per the new API:

根据新的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

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

#1


0  

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

这是一个在Eclipse 3.7中修复的bug(参见https://bugs.eclipse.org/bugs/show_bug.cgi?id=324367)。

As per the new API:

根据新的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

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