views:

57

answers:

0

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