mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-02 05:45:58 +02:00
Allow to cancel indexer while collecting files.
This commit is contained in:
parent
75ab77d311
commit
fe15e65401
5 changed files with 29 additions and 12 deletions
|
@ -59,14 +59,20 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
|
||||||
private final Collection fHeaders;
|
private final Collection fHeaders;
|
||||||
private final boolean fAllFiles;
|
private final boolean fAllFiles;
|
||||||
private final Collection fSources;
|
private final Collection fSources;
|
||||||
|
private final IProgressMonitor fProgressMonitor;
|
||||||
|
|
||||||
private TranslationUnitCollector(Collection sources, Collection headers, boolean allFiles) {
|
private TranslationUnitCollector(Collection sources, Collection headers, boolean allFiles,
|
||||||
|
IProgressMonitor pm) {
|
||||||
fHeaders = headers;
|
fHeaders = headers;
|
||||||
fAllFiles = allFiles;
|
fAllFiles = allFiles;
|
||||||
fSources = sources;
|
fSources = sources;
|
||||||
|
fProgressMonitor= pm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean visit(ICElement element) throws CoreException {
|
public boolean visit(ICElement element) throws CoreException {
|
||||||
|
if (fProgressMonitor.isCanceled()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
switch (element.getElementType()) {
|
switch (element.getElementType()) {
|
||||||
case ICElement.C_UNIT:
|
case ICElement.C_UNIT:
|
||||||
ITranslationUnit tu = (ITranslationUnit)element;
|
ITranslationUnit tu = (ITranslationUnit)element;
|
||||||
|
@ -118,14 +124,15 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
|
||||||
return (trace != null && trace.equalsIgnoreCase(value));
|
return (trace != null && trace.equalsIgnoreCase(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void processDelta(ICElementDelta delta, Collection added, Collection changed, Collection removed) throws CoreException {
|
protected void processDelta(ICElementDelta delta, Collection added, Collection changed, Collection removed,
|
||||||
|
IProgressMonitor pm) throws CoreException {
|
||||||
boolean allFiles= getIndexAllFiles();
|
boolean allFiles= getIndexAllFiles();
|
||||||
int flags = delta.getFlags();
|
int flags = delta.getFlags();
|
||||||
|
|
||||||
if ((flags & ICElementDelta.F_CHILDREN) != 0) {
|
if ((flags & ICElementDelta.F_CHILDREN) != 0) {
|
||||||
ICElementDelta[] children = delta.getAffectedChildren();
|
ICElementDelta[] children = delta.getAffectedChildren();
|
||||||
for (int i = 0; i < children.length; ++i) {
|
for (int i = 0; i < children.length; ++i) {
|
||||||
processDelta(children[i], added, changed, removed);
|
processDelta(children[i], added, changed, removed, pm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,20 +162,22 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
|
||||||
case ICElement.C_CCONTAINER:
|
case ICElement.C_CCONTAINER:
|
||||||
ICContainer folder= (ICContainer) element;
|
ICContainer folder= (ICContainer) element;
|
||||||
if (delta.getKind() == ICElementDelta.ADDED) {
|
if (delta.getKind() == ICElementDelta.ADDED) {
|
||||||
collectSources(folder, added, added, allFiles);
|
collectSources(folder, added, added, allFiles, pm);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void collectSources(ICContainer container, final Collection sources, final Collection headers, final boolean allFiles) throws CoreException {
|
private void collectSources(ICContainer container, Collection sources, Collection headers, boolean allFiles,
|
||||||
container.accept(new TranslationUnitCollector(sources, headers, allFiles));
|
IProgressMonitor pm) throws CoreException {
|
||||||
|
container.accept(new TranslationUnitCollector(sources, headers, allFiles, pm));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void collectSources(ICProject project, final Collection sources, final Collection headers, final boolean allFiles) throws CoreException {
|
protected void collectSources(ICProject project, Collection sources, Collection headers, boolean allFiles,
|
||||||
|
IProgressMonitor pm) throws CoreException {
|
||||||
fMessage= MessageFormat.format(Messages.PDOMIndexerTask_collectingFilesTask, new Object[]{project.getElementName()});
|
fMessage= MessageFormat.format(Messages.PDOMIndexerTask_collectingFilesTask, new Object[]{project.getElementName()});
|
||||||
project.accept(new TranslationUnitCollector(sources, headers, allFiles));
|
project.accept(new TranslationUnitCollector(sources, headers, allFiles, pm));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void removeTU(IWritableIndex index, ITranslationUnit tu, int readlocks) throws CoreException, InterruptedException {
|
protected void removeTU(IWritableIndex index, ITranslationUnit tu, int readlocks) throws CoreException, InterruptedException {
|
||||||
|
|
|
@ -21,6 +21,7 @@ import org.eclipse.cdt.core.model.ICElementDelta;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
|
|
||||||
class PDOMFastHandleDelta extends PDOMFastIndexerJob {
|
class PDOMFastHandleDelta extends PDOMFastIndexerJob {
|
||||||
|
|
||||||
|
@ -29,7 +30,7 @@ class PDOMFastHandleDelta extends PDOMFastIndexerJob {
|
||||||
|
|
||||||
public PDOMFastHandleDelta(PDOMFastIndexer indexer, ICElementDelta delta) throws CoreException {
|
public PDOMFastHandleDelta(PDOMFastIndexer indexer, ICElementDelta delta) throws CoreException {
|
||||||
super(indexer);
|
super(indexer);
|
||||||
processDelta(delta, changed, changed, removed);
|
processDelta(delta, changed, changed, removed, new NullProgressMonitor());
|
||||||
fTotalSourcesEstimate= changed.size() + removed.size();
|
fTotalSourcesEstimate= changed.size() + removed.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,12 @@ class PDOMFastReindex extends PDOMFastIndexerJob {
|
||||||
boolean allFiles= getIndexAllFiles();
|
boolean allFiles= getIndexAllFiles();
|
||||||
List sources= new ArrayList();
|
List sources= new ArrayList();
|
||||||
List headers= new ArrayList();
|
List headers= new ArrayList();
|
||||||
collectSources(indexer.getProject(), sources, allFiles ? headers : null, allFiles);
|
collectSources(indexer.getProject(), sources,
|
||||||
|
allFiles ? headers : null, allFiles, monitor);
|
||||||
|
|
||||||
|
if (monitor.isCanceled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
fTotalSourcesEstimate= sources.size() + headers.size();
|
fTotalSourcesEstimate= sources.size() + headers.size();
|
||||||
setupIndexAndReaderFactory();
|
setupIndexAndReaderFactory();
|
||||||
|
|
|
@ -21,6 +21,7 @@ import org.eclipse.cdt.core.model.ICElementDelta;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
|
@ -33,7 +34,7 @@ class PDOMFullHandleDelta extends PDOMFullIndexerJob {
|
||||||
|
|
||||||
public PDOMFullHandleDelta(PDOMFullIndexer indexer, ICElementDelta delta) throws CoreException {
|
public PDOMFullHandleDelta(PDOMFullIndexer indexer, ICElementDelta delta) throws CoreException {
|
||||||
super(indexer);
|
super(indexer);
|
||||||
processDelta(delta, changed, changed, removed);
|
processDelta(delta, changed, changed, removed, new NullProgressMonitor());
|
||||||
fTotalSourcesEstimate= changed.size() + removed.size();
|
fTotalSourcesEstimate= changed.size() + removed.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,8 @@ class PDOMFullReindex extends PDOMFullIndexerJob {
|
||||||
List/*<ITranslationUnit>*/ sources= new ArrayList/*<ITranslationUnit>*/();
|
List/*<ITranslationUnit>*/ sources= new ArrayList/*<ITranslationUnit>*/();
|
||||||
List/*<ITranslationUnit>*/ headers= new ArrayList/*<ITranslationUnit>*/();
|
List/*<ITranslationUnit>*/ headers= new ArrayList/*<ITranslationUnit>*/();
|
||||||
|
|
||||||
collectSources(indexer.getProject(), sources, allFiles ? headers : null, allFiles);
|
collectSources(indexer.getProject(), sources,
|
||||||
|
allFiles ? headers : null, allFiles, monitor);
|
||||||
fTotalSourcesEstimate= sources.size() + headers.size();
|
fTotalSourcesEstimate= sources.size() + headers.size();
|
||||||
|
|
||||||
setupIndexAndReaderFactory();
|
setupIndexAndReaderFactory();
|
||||||
|
|
Loading…
Add table
Reference in a new issue