mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix for Bug 71500: [Indexer] all headers get indexed on project open
This commit is contained in:
parent
1b940db018
commit
92d190f0ab
10 changed files with 195 additions and 9 deletions
|
@ -99,7 +99,7 @@ public class UpdateDependency implements IJob {
|
|||
if (fileToReindex!=null && fileToReindex.exists() ) {
|
||||
// if (VERBOSE)
|
||||
// System.out.println("Going to reindex " + fileToReindex.getName());
|
||||
indexManager.addSource(fileToReindex,fileToReindex.getProject().getProject().getFullPath());
|
||||
indexManager.addSource(fileToReindex,fileToReindex.getProject().getProject().getFullPath(), false);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -1,3 +1,16 @@
|
|||
2004-08-19 Bogdan Gheorghe
|
||||
Fix for Bug 71500: [Indexer] all headers get indexed on project open
|
||||
|
||||
* index/org/eclipse/cdt/internal/core/search/indexing/AddCompilationUnitToIndex.java
|
||||
* index/org/eclipse/cdt/internal/core/search/indexing/AddFileToIndex.java
|
||||
* index/org/eclipse/cdt/internal/core/search/indexing/AddFolderToIndex.java
|
||||
* index/org/eclipse/cdt/internal/core/search/indexing/CleanEncounteredHeaders.java
|
||||
* index/org/eclipse/cdt/internal/core/search/indexing/IndexerModelListener.java
|
||||
* index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java
|
||||
* index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexerRequestor.java
|
||||
* dependency/org/eclipse/cdt/internal/core/sourcedependency/UpdateDependency.java
|
||||
* model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java
|
||||
|
||||
2004-08-11 Bogdan Gheorghe
|
||||
Fix for Bug 59493: need to refine index query for open-type
|
||||
|
||||
|
|
|
@ -21,8 +21,8 @@ import org.eclipse.core.runtime.IPath;
|
|||
public class AddCompilationUnitToIndex extends AddFileToIndex {
|
||||
char[] contents;
|
||||
|
||||
public AddCompilationUnitToIndex(IFile resource, IPath indexedContainer, IndexManager manager) {
|
||||
super(resource, indexedContainer, manager);
|
||||
public AddCompilationUnitToIndex(IFile resource, IPath indexedContainer, IndexManager manager, boolean checkEncounteredHeaders) {
|
||||
super(resource, indexedContainer, manager, checkEncounteredHeaders);
|
||||
}
|
||||
protected boolean indexDocument(IIndex index) throws IOException {
|
||||
if (!initializeContents()) return false;
|
||||
|
|
|
@ -12,23 +12,39 @@ package org.eclipse.cdt.internal.core.search.indexing;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.ICLogConstants;
|
||||
import org.eclipse.cdt.core.filetype.ICFileType;
|
||||
import org.eclipse.cdt.internal.core.index.IIndex;
|
||||
import org.eclipse.cdt.internal.core.search.processing.JobManager;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
public abstract class AddFileToIndex extends IndexRequest {
|
||||
IFile resource;
|
||||
private boolean checkEncounteredHeaders;
|
||||
|
||||
public AddFileToIndex(IFile resource, IPath indexPath, IndexManager manager) {
|
||||
public AddFileToIndex(IFile resource, IPath indexPath, IndexManager manager, boolean checkEncounteredHeaders) {
|
||||
super(indexPath, manager);
|
||||
this.resource = resource;
|
||||
this.checkEncounteredHeaders = checkEncounteredHeaders;
|
||||
}
|
||||
|
||||
public boolean execute(IProgressMonitor progressMonitor) {
|
||||
if (progressMonitor != null && progressMonitor.isCanceled()) return true;
|
||||
|
||||
if (checkEncounteredHeaders) {
|
||||
IProject resourceProject = resource.getProject();
|
||||
/* Check to see if this is a header file */
|
||||
ICFileType type = CCorePlugin.getDefault().getFileType(resourceProject,resource.getName());
|
||||
|
||||
/* See if this file has been encountered before */
|
||||
if (type.isHeader() &&
|
||||
manager.haveEncounteredHeader(resourceProject.getFullPath(),resource.getLocation()))
|
||||
return true;
|
||||
}
|
||||
/* ensure no concurrent write access to index */
|
||||
IIndex index = manager.getIndex(this.indexPath, true, /*reuse index file*/ true /*create if none*/);
|
||||
if (index == null) return true;
|
||||
|
|
|
@ -11,6 +11,10 @@
|
|||
|
||||
package org.eclipse.cdt.internal.core.search.indexing;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.filetype.ICFileType;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.internal.core.Util;
|
||||
import org.eclipse.cdt.internal.core.index.IIndex;
|
||||
|
@ -28,12 +32,16 @@ class AddFolderToIndex extends IndexRequest {
|
|||
IPath folderPath;
|
||||
IProject project;
|
||||
char[][] exclusionPattern;
|
||||
ArrayList sourceFilesToIndex;
|
||||
ArrayList headerFilesToIndex;
|
||||
|
||||
public AddFolderToIndex(IPath folderPath, IProject project, char[][] exclusionPattern, IndexManager manager) {
|
||||
super(project.getFullPath(), manager);
|
||||
this.folderPath = folderPath;
|
||||
this.project = project;
|
||||
this.exclusionPattern = exclusionPattern;
|
||||
this.sourceFilesToIndex = new ArrayList();
|
||||
this.headerFilesToIndex = new ArrayList();
|
||||
}
|
||||
|
||||
public boolean execute(IProgressMonitor progressMonitor) {
|
||||
|
@ -62,7 +70,8 @@ class AddFolderToIndex extends IndexRequest {
|
|||
IResource resource = proxy.requestResource();
|
||||
if (CoreModel.isValidTranslationUnitName(resource.getProject(),resource.getName())) {
|
||||
if (pattern == null || !Util.isExcluded(resource, pattern))
|
||||
indexManager.addSource((IFile)resource, container);
|
||||
//indexManager.addSource((IFile)resource, container);
|
||||
sortFiles((IFile) resource);
|
||||
}
|
||||
return false;
|
||||
case IResource.FOLDER :
|
||||
|
@ -74,6 +83,7 @@ class AddFolderToIndex extends IndexRequest {
|
|||
},
|
||||
IResource.NONE
|
||||
);
|
||||
scheduleJobs();
|
||||
} catch (CoreException e) {
|
||||
if (IndexManager.VERBOSE) {
|
||||
JobManager.verbose("-> failed to add " + this.folderPath + " to index because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
@ -86,8 +96,37 @@ class AddFolderToIndex extends IndexRequest {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void scheduleJobs() {
|
||||
//Schedule the source jobs first, then the headers
|
||||
for (int i=0; i<sourceFilesToIndex.size(); i++)
|
||||
this.manager.addSource((IFile)sourceFilesToIndex.get(i), this.indexPath, true);
|
||||
|
||||
for (int i=0;i<headerFilesToIndex.size(); i++)
|
||||
this.manager.addSource((IFile)headerFilesToIndex.get(i), this.indexPath, true);
|
||||
|
||||
CleanEncounteredHeaders cleanHeaders = new CleanEncounteredHeaders(this.manager);
|
||||
this.manager.request(cleanHeaders);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "adding " + this.folderPath + " to index " + this.indexPath; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
protected void sortFiles(IFile file){
|
||||
|
||||
/* Check to see if this is a header file */
|
||||
ICFileType type = CCorePlugin.getDefault().getFileType(file.getProject(), file.getName());
|
||||
|
||||
/* See if this file has been encountered before */
|
||||
if (type.isHeader())
|
||||
headerFilesToIndex.add(file);
|
||||
|
||||
if (type.isSource())
|
||||
sourceFilesToIndex.add(file);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Created on Aug 19, 2004
|
||||
*
|
||||
* TODO To change the template for this generated file go to
|
||||
* Window - Preferences - Java - Code Style - Code Templates
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.search.indexing;
|
||||
|
||||
import org.eclipse.cdt.internal.core.search.processing.IJob;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
/**
|
||||
* @author bgheorgh
|
||||
*
|
||||
* TODO To change the template for this generated type comment go to
|
||||
* Window - Preferences - Java - Code Style - Code Templates
|
||||
*/
|
||||
public class CleanEncounteredHeaders implements IJob {
|
||||
|
||||
IndexManager manager = null;
|
||||
|
||||
public CleanEncounteredHeaders(IndexManager manager){
|
||||
this.manager = manager;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.search.processing.IJob#execute(org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
public boolean execute(IProgressMonitor progress) {
|
||||
|
||||
//Clean out the headers
|
||||
this.manager.resetEncounteredHeaders();
|
||||
return true;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.search.processing.IJob#belongsTo(java.lang.String)
|
||||
*/
|
||||
public boolean belongsTo(String jobFamily) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.search.processing.IJob#cancel()
|
||||
*/
|
||||
public void cancel() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.search.processing.IJob#isReadyToRun()
|
||||
*/
|
||||
public boolean isReadyToRun() {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -35,6 +35,7 @@ import org.eclipse.cdt.internal.core.Util;
|
|||
import org.eclipse.cdt.internal.core.index.IIndex;
|
||||
import org.eclipse.cdt.internal.core.index.impl.Index;
|
||||
import org.eclipse.cdt.internal.core.index.impl.IndexDelta;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectSet;
|
||||
import org.eclipse.cdt.internal.core.search.CWorkspaceScope;
|
||||
import org.eclipse.cdt.internal.core.search.IndexSelector;
|
||||
import org.eclipse.cdt.internal.core.search.SimpleLookupTable;
|
||||
|
@ -80,6 +81,9 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
|||
private SimpleLookupTable indexStates = null;
|
||||
private File savedIndexNamesFile =
|
||||
new File(getCCorePluginWorkingLocation().append("savedIndexNames.txt").toOSString()); //$NON-NLS-1$
|
||||
|
||||
private SimpleLookupTable encounteredHeaders = null;
|
||||
|
||||
public static Integer SAVED_STATE = new Integer(0);
|
||||
public static Integer UPDATING_STATE = new Integer(1);
|
||||
public static Integer UNKNOWN_STATE = new Integer(2);
|
||||
|
@ -149,8 +153,9 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
|||
/**
|
||||
* Trigger addition of a resource to an index
|
||||
* Note: the actual operation is performed in background
|
||||
* @param checkEncounteredHeaders TODO
|
||||
*/
|
||||
public void addSource(IFile resource, IPath indexedContainer){
|
||||
public void addSource(IFile resource, IPath indexedContainers, boolean checkEncounteredHeaders){
|
||||
|
||||
IProject project = resource.getProject();
|
||||
|
||||
|
@ -163,7 +168,7 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
|||
if (CCorePlugin.getDefault() == null) return;
|
||||
|
||||
if (indexEnabled){
|
||||
AddCompilationUnitToIndex job = new AddCompilationUnitToIndex(resource, indexedContainer, this);
|
||||
AddCompilationUnitToIndex job = new AddCompilationUnitToIndex(resource, indexedContainers, this, checkEncounteredHeaders);
|
||||
|
||||
//If we are in WAITING mode, we need to kick ourselves into enablement
|
||||
if (!jobSet.add(job.resource.getLocation()) &&
|
||||
|
@ -270,6 +275,33 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
|||
return index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index for a given project, according to the following algorithm:
|
||||
* - if index is already in memory: answers this one back
|
||||
* - if (reuseExistingFile) then read it and return this index and record it in memory
|
||||
* - if (createIfMissing) then create a new empty index and record it in memory
|
||||
*
|
||||
* Warning: Does not check whether index is consistent (not being used)
|
||||
*/
|
||||
public synchronized boolean haveEncounteredHeader(IPath projectPath, IPath filePath) {
|
||||
|
||||
SimpleLookupTable headerTable = getEncounteredHeaders();
|
||||
// Path is already canonical per construction
|
||||
ObjectSet headers = (ObjectSet) headerTable.get(projectPath);
|
||||
if (headers == null) {
|
||||
//First time for the project, must create a new ObjectSet
|
||||
headers = new ObjectSet(4);
|
||||
headerTable.put(projectPath, headers);
|
||||
}
|
||||
|
||||
if (headers.containsKey(filePath.toOSString()))
|
||||
return true;
|
||||
|
||||
headers.put(filePath.toOSString());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private SimpleLookupTable getIndexStates() {
|
||||
if (indexStates != null) return indexStates;
|
||||
|
||||
|
@ -286,6 +318,23 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
|||
return this.indexStates;
|
||||
}
|
||||
|
||||
private SimpleLookupTable getEncounteredHeaders(){
|
||||
|
||||
if (encounteredHeaders == null){
|
||||
this.encounteredHeaders = new SimpleLookupTable();
|
||||
}
|
||||
|
||||
|
||||
return this.encounteredHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the headers table
|
||||
*/
|
||||
public void resetEncounteredHeaders() {
|
||||
this.encounteredHeaders = null;
|
||||
}
|
||||
|
||||
private IPath getCCorePluginWorkingLocation() {
|
||||
if (this.cCorePluginLocation != null) return this.cCorePluginLocation;
|
||||
|
||||
|
@ -554,6 +603,7 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
|||
this.indexes = new HashMap(5);
|
||||
this.monitors = new HashMap(5);
|
||||
this.indexStates = null;
|
||||
this.encounteredHeaders = null;
|
||||
}
|
||||
|
||||
if (this.timeoutThread == null){
|
||||
|
@ -881,6 +931,7 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ public class IndexerModelListener implements IElementChangedListener {
|
|||
switch(tempResource.getType())
|
||||
{
|
||||
case IResource.FILE:
|
||||
indexManager.addSource((IFile) tempResource,tempResource.getProject().getFullPath());
|
||||
indexManager.addSource((IFile) tempResource,tempResource.getProject().getFullPath(), false);
|
||||
break;
|
||||
|
||||
case IResource.FOLDER:
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.filetype.ICFileType;
|
||||
import org.eclipse.cdt.core.model.ICModelMarker;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.IParser;
|
||||
|
@ -71,6 +72,7 @@ import org.eclipse.cdt.core.parser.ast.IASTVariableReference;
|
|||
import org.eclipse.cdt.internal.core.Util;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspaceRunnable;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -265,6 +267,15 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo
|
|||
pushInclude(inclusion);
|
||||
//Add to traversed files
|
||||
this.filesTraversed.add(inclusion.getFullFileName());
|
||||
|
||||
IProject resourceProject = resourceFile.getProject();
|
||||
/* Check to see if this is a header file */
|
||||
ICFileType type = CCorePlugin.getDefault().getFileType(resourceProject,
|
||||
inclusion.getFullFileName());
|
||||
|
||||
/* See if this file has been encountered before */
|
||||
if (type.isHeader())
|
||||
CCorePlugin.getDefault().getCoreModel().getIndexManager().haveEncounteredHeader(resourceProject.getFullPath(),new Path(inclusion.getFullFileName()));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -585,7 +585,7 @@ public class DeltaProcessor {
|
|||
case ICElement.C_UNIT:
|
||||
IFile file = (IFile) delta.getResource();
|
||||
IProject filesProject = file.getProject();
|
||||
indexManager.addSource(file, filesProject.getFullPath());
|
||||
indexManager.addSource(file, filesProject.getFullPath(), false);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue