1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix for 91544: DOM Indexer double indexing on save

This commit is contained in:
Bogdan Gheorghe 2005-04-15 17:45:23 +00:00
parent a27d2a6da5
commit 672f24a4d4
2 changed files with 43 additions and 18 deletions

View file

@ -41,14 +41,16 @@ import org.eclipse.core.runtime.Path;
*/
public class UpdateDependency implements IIndexJob {
PathCollector pathCollector;
IResource resource;
IFile resource=null;
SourceIndexer indexer;
/**
* @param resource
*/
public UpdateDependency(IResource resource, SourceIndexer indexer) {
this.resource = resource;
if (resource instanceof IFile)
this.resource = (IFile) resource;
this.indexer = indexer;
}
@ -94,17 +96,25 @@ public class UpdateDependency implements IIndexJob {
this );
String[] iPath = pathCollector.getPaths();
for (int i=0;i<iPath.length; i++){
IPath pathToReindex = new Path(iPath[i]);
IWorkspaceRoot workRoot = resource.getWorkspace().getRoot();
IFile fileToReindex = workRoot.getFile(pathToReindex);
if (fileToReindex!=null && fileToReindex.exists() ) {
// if (VERBOSE)
// System.out.println("Going to reindex " + fileToReindex.getName());
indexer.addSource(fileToReindex,fileToReindex.getProject().getProject().getFullPath());
if (iPath.length > 0){
//If we found any dependents on this header file, indexing them will also index the header
for (int i=0;i<iPath.length; i++){
IPath pathToReindex = new Path(iPath[i]);
IWorkspaceRoot workRoot = resource.getWorkspace().getRoot();
IFile fileToReindex = workRoot.getFile(pathToReindex);
if (fileToReindex!=null && fileToReindex.exists() ) {
// if (VERBOSE)
// System.out.println("Going to reindex " + fileToReindex.getName());
indexer.addSource(fileToReindex,fileToReindex.getProject().getFullPath());
}
}
}
else {
//No dependents found, just index the stand alone header
indexer.addSource(resource,resource.getProject().getFullPath());
}
return false;
}

View file

@ -5,6 +5,8 @@ package org.eclipse.cdt.internal.core.model;
* All Rights Reserved.
*/
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.filetype.ICFileType;
import org.eclipse.cdt.core.index.ICDTIndexer;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
@ -18,6 +20,7 @@ import org.eclipse.cdt.core.model.ICElementDelta;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
@ -537,7 +540,7 @@ public class DeltaProcessor {
switch (delta.getKind()) {
case IResourceDelta.ADDED :
if (element != null) {
updateIndexAddResource(element, delta);
updateIndexAddResource(element, delta, false);
elementAdded(element, delta);
return element instanceof ICContainer;
}
@ -556,7 +559,7 @@ public class DeltaProcessor {
// content has changed
if (element != null) {
elementChanged(element, delta);
updateIndexAddResource(element, delta);
updateIndexAddResource(element, delta, true);
//check to see if any projects need to be reindexed
updateDependencies(element);
@ -568,7 +571,7 @@ public class DeltaProcessor {
if (element != null) {
if (project.isOpen()) {
elementOpened(element, delta);
updateIndexAddResource(element, delta);
updateIndexAddResource(element, delta, true);
return false;
}
elementClosed(element, delta);
@ -588,7 +591,7 @@ public class DeltaProcessor {
// note its resources are still visible as roots to other projects
if (isCProject) {
elementOpened(element, delta);
updateIndexAddResource(element, delta);
updateIndexAddResource(element, delta, true);
} else {
elementRemoved(element, delta);
updateIndexRemoveResource(element, delta);
@ -603,7 +606,7 @@ public class DeltaProcessor {
return true;
}
protected void updateIndexAddResource(ICElement element, IResourceDelta delta) {
protected void updateIndexAddResource(ICElement element, IResourceDelta delta, boolean elementHasChanged) {
if (indexManager == null)
return;
@ -618,9 +621,21 @@ public class DeltaProcessor {
break;
case ICElement.C_UNIT:
indexManager.addResourceEvent(element.getCProject().getProject(),delta, ICDTIndexer.COMPILATION_UNIT);
//if the element has changed check to see if file is header, if it is don't schedule for index - update dependencies will
//take care of it.
//otherwise just schedule element for index
boolean shouldAddFile=false;
IProject project = element.getCProject().getProject();
if (elementHasChanged){
ICFileType type = CCorePlugin.getDefault().getFileType(project,((IFile) delta.getResource()).getName());
if (type.isSource())
shouldAddFile=true;
} else {
shouldAddFile = true;
}
if (shouldAddFile)
indexManager.addResourceEvent(project,delta, ICDTIndexer.COMPILATION_UNIT);
break;
}