if (!project.isAccessible()) return true; // nothing to do
ReadWriteMonitor monitor = null;
try {
// Get source folder entries. Libraries are done as a separate job
JavaProject javaProject = (JavaProject)JavaCore.create(this.project);
// Do not create marker while getting raw classpath (see bug 41859)
IClasspathEntry[] entries = javaProject.getRawClasspath();
int length = entries.length;
IClasspathEntry[] sourceEntries = new IClasspathEntry[length];
int sourceEntriesNumber = 0;
for (int i = 0; i < length; i++) {
IClasspathEntry entry = entries[i];
if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE)
sourceEntries[sourceEntriesNumber++] = entry;
}
if (sourceEntriesNumber == 0) {
IPath projectPath = javaProject.getPath();
for (int i = 0; i < length; i++) {
IClasspathEntry entry = entries[i];
if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && entry.getPath().equals(projectPath)) {
// the project is also a library folder (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=89815)
// ensure a job exists to index it as a binary folder
this.manager.indexLibrary(projectPath, this.project);
return true;
}
}
// nothing to index but want to save an empty index file so its not 'rebuilt' when part of a search request
Index index = this.manager.getIndexForUpdate(this.containerPath, true, /*reuse index file*/ true /*create if none*/);
if (index != null)
this.manager.saveIndex(index);
return true;
}
if (sourceEntriesNumber != length)
System.arraycopy(sourceEntries, 0, sourceEntries = new IClasspathEntry[sourceEntriesNumber], 0, sourceEntriesNumber);
Index index = this.manager.getIndexForUpdate(this.containerPath, true, /*reuse index file*/ true /*create if none*/);
if (index == null) return true;
monitor = index.monitor;
if (monitor == null) return true; // index got deleted since acquired
monitor.enterRead(); // ask permission to read
String[] paths = index.queryDocumentNames(""); // all file names //$NON-NLS-1$
int max = paths == null ? 0 : paths.length;
final SimpleLookupTable indexedFileNames = new SimpleLookupTable(max == 0 ? 33 : max + 11);
final String OK = "OK"; //$NON-NLS-1$
final String DELETED = "DELETED"; //$NON-NLS-1$
if (paths != null) {
for (int i = 0; i < max; i++)
indexedFileNames.put(paths[i], DELETED);
}
final long indexLastModified = max == 0 ? 0L : index.getIndexFile().lastModified();
IWorkspaceRoot root = this.project.getWorkspace().getRoot();
for (int i = 0; i < sourceEntriesNumber; i++) {
if (this.isCancelled) return false;
IClasspathEntry entry = sourceEntries[i];
IResource sourceFolder = root.findMember(entry.getPath());
if (sourceFolder != null) {
// collect output locations if source is project (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=32041)
final HashSet outputs = new HashSet();
if (sourceFolder.getType() == IResource.PROJECT) {
// Do not create marker while getting output location (see bug 41859)
outputs.add(javaProject.getOutputLocation());
for (int j = 0; j < sourceEntriesNumber; j++) {
IPath output = sourceEntries[j].getOutputLocation();
if (output != null) {
outputs.add(output);
}