IPath projectPath = project.getFullPath();
String projectPathString = projectPath.toString();
addEnclosingProjectOrJar(projectPath);
IClasspathEntry[] entries = javaProject.getResolvedClasspath();
IJavaModel model = javaProject.getJavaModel();
JavaModelManager.PerProjectInfo perProjectInfo = javaProject.getPerProjectInfo();
for (int i = 0, length = entries.length; i < length; i++) {
IClasspathEntry entry = entries[i];
AccessRuleSet access = null;
ClasspathEntry cpEntry = (ClasspathEntry) entry;
if (referringEntry != null) {
// Add only exported entries.
// Source folder are implicitly exported.
if (!entry.isExported() && entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) {
continue;
}
cpEntry = cpEntry.combineWith((ClasspathEntry)referringEntry);
// cpEntry = ((ClasspathEntry)referringEntry).combineWith(cpEntry);
}
access = cpEntry.getAccessRuleSet();
switch (entry.getEntryKind()) {
case IClasspathEntry.CPE_LIBRARY:
IClasspathEntry rawEntry = null;
Map rootPathToRawEntries = perProjectInfo.rootPathToRawEntries;
if (rootPathToRawEntries != null) {
rawEntry = (IClasspathEntry) rootPathToRawEntries.get(entry.getPath());
}
if (rawEntry == null) break;
rawKind: switch (rawEntry.getEntryKind()) {
case IClasspathEntry.CPE_LIBRARY:
case IClasspathEntry.CPE_VARIABLE:
if ((includeMask & APPLICATION_LIBRARIES) != 0) {
IPath path = entry.getPath();
if (pathToAdd == null || pathToAdd.equals(path)) {
Object target = JavaModel.getTarget(path, false/*don't check existence*/);
if (target instanceof IFolder) // case of an external folder
path = ((IFolder) target).getFullPath();
String pathToString = path.getDevice() == null ? path.toString() : path.toOSString();
add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$
addEnclosingProjectOrJar(entry.getPath());
}
}
break;
case IClasspathEntry.CPE_CONTAINER:
IClasspathContainer container = JavaCore.getClasspathContainer(rawEntry.getPath(), javaProject);
if (container == null) break;
switch (container.getKind()) {
case IClasspathContainer.K_APPLICATION:
if ((includeMask & APPLICATION_LIBRARIES) == 0) break rawKind;
break;
case IClasspathContainer.K_SYSTEM:
case IClasspathContainer.K_DEFAULT_SYSTEM:
if ((includeMask & SYSTEM_LIBRARIES) == 0) break rawKind;
break;
default:
break rawKind;
}
IPath path = entry.getPath();
if (pathToAdd == null || pathToAdd.equals(path)) {
Object target = JavaModel.getTarget(path, false/*don't check existence*/);
if (target instanceof IFolder) // case of an external folder
path = ((IFolder) target).getFullPath();
String pathToString = path.getDevice() == null ? path.toString() : path.toOSString();
add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$
addEnclosingProjectOrJar(entry.getPath());
}
break;
}
break;
case IClasspathEntry.CPE_PROJECT:
if ((includeMask & REFERENCED_PROJECTS) != 0) {
IPath path = entry.getPath();
if (pathToAdd == null || pathToAdd.equals(path)) {
JavaProject referencedProject = (JavaProject) model.getJavaProject(path.lastSegment());
if (!projectsToBeAdded.contains(referencedProject)) { // do not recurse if depending project was used to create the scope
add(referencedProject, null, includeMask, projectsToBeAdded, visitedProjects, cpEntry);
}
}
}