mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Move the Full indexer to the PDOM Indexer Task Framework.
This commit is contained in:
parent
194e0d00b4
commit
475d55c8e1
7 changed files with 21 additions and 84 deletions
|
@ -13,8 +13,6 @@ package org.eclipse.cdt.core.dom;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
|
||||||
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
|
@ -38,10 +36,4 @@ public interface IPDOMManager {
|
||||||
// Enqueue and indexer sub job
|
// Enqueue and indexer sub job
|
||||||
public void enqueue(IPDOMIndexerTask subjob);
|
public void enqueue(IPDOMIndexerTask subjob);
|
||||||
|
|
||||||
// Scheduling rule used by indexers to make sure we don't get
|
|
||||||
// Too much indexing going on.
|
|
||||||
public ISchedulingRule getIndexerSchedulingRule();
|
|
||||||
|
|
||||||
public IProgressMonitor getProgressGroup();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,6 @@ import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.core.runtime.QualifiedName;
|
import org.eclipse.core.runtime.QualifiedName;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
|
||||||
import org.eclipse.core.runtime.jobs.Job;
|
import org.eclipse.core.runtime.jobs.Job;
|
||||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||||
import org.eclipse.core.runtime.preferences.IPreferencesService;
|
import org.eclipse.core.runtime.preferences.IPreferencesService;
|
||||||
|
@ -62,17 +61,6 @@ public class PDOMManager implements IPDOMManager, IElementChangedListener {
|
||||||
private static final QualifiedName pdomProperty
|
private static final QualifiedName pdomProperty
|
||||||
= new QualifiedName(CCorePlugin.PLUGIN_ID, "pdom"); //$NON-NLS-1$
|
= new QualifiedName(CCorePlugin.PLUGIN_ID, "pdom"); //$NON-NLS-1$
|
||||||
|
|
||||||
private IProgressMonitor group;
|
|
||||||
|
|
||||||
private final ISchedulingRule indexerSchedulingRule = new ISchedulingRule() {
|
|
||||||
public boolean contains(ISchedulingRule rule) {
|
|
||||||
return rule == this;
|
|
||||||
}
|
|
||||||
public boolean isConflicting(ISchedulingRule rule) {
|
|
||||||
return rule == this;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public synchronized IPDOM getPDOM(ICProject project) throws CoreException {
|
public synchronized IPDOM getPDOM(ICProject project) throws CoreException {
|
||||||
IProject rproject = project.getProject();
|
IProject rproject = project.getProject();
|
||||||
PDOM pdom = (PDOM)rproject.getSessionProperty(pdomProperty);
|
PDOM pdom = (PDOM)rproject.getSessionProperty(pdomProperty);
|
||||||
|
@ -316,16 +304,6 @@ public class PDOMManager implements IPDOMManager, IElementChangedListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ISchedulingRule getIndexerSchedulingRule() {
|
|
||||||
return indexerSchedulingRule;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IProgressMonitor getProgressGroup() {
|
|
||||||
if (group == null)
|
|
||||||
group = Platform.getJobManager().createProgressGroup();
|
|
||||||
return group;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Startup the PDOM. This mainly sets us up to handle model
|
* Startup the PDOM. This mainly sets us up to handle model
|
||||||
* change events.
|
* change events.
|
||||||
|
|
|
@ -42,7 +42,6 @@ public abstract class CtagsIndexerJob extends Job {
|
||||||
super("ctags Indexer: " + indexer.getProject().getElementName());
|
super("ctags Indexer: " + indexer.getProject().getElementName());
|
||||||
this.indexer = indexer;
|
this.indexer = indexer;
|
||||||
this.pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(indexer.getProject());
|
this.pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(indexer.getProject());
|
||||||
setRule(CCorePlugin.getPDOMManager().getIndexerSchedulingRule());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Indexing functions
|
// Indexing functions
|
||||||
|
|
|
@ -31,10 +31,8 @@ import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.core.runtime.Status;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
|
@ -54,7 +52,7 @@ public class PDOMFullHandleDelta extends PDOMFullIndexerJob {
|
||||||
this.delta = delta;
|
this.delta = delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IStatus run(IProgressMonitor monitor) {
|
public void run(IProgressMonitor monitor) {
|
||||||
try {
|
try {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
|
|
||||||
|
@ -63,42 +61,40 @@ public class PDOMFullHandleDelta extends PDOMFullIndexerJob {
|
||||||
int count = changed.size() + added.size() + removed.size();
|
int count = changed.size() + added.size() + removed.size();
|
||||||
|
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
monitor.beginTask("Indexing", count);
|
|
||||||
|
|
||||||
Iterator i = changed.values().iterator();
|
Iterator i = changed.values().iterator();
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
|
if (monitor.isCanceled())
|
||||||
|
return;
|
||||||
ITranslationUnit tu = (ITranslationUnit)i.next();
|
ITranslationUnit tu = (ITranslationUnit)i.next();
|
||||||
monitor.subTask(tu.getElementName());
|
|
||||||
try {
|
try {
|
||||||
changeTU(tu);
|
changeTU(tu);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
CCorePlugin.log(e);
|
CCorePlugin.log(e);
|
||||||
if (++errorCount > MAX_ERRORS)
|
if (++errorCount > MAX_ERRORS)
|
||||||
return Status.CANCEL_STATUS;
|
return;
|
||||||
}
|
}
|
||||||
monitor.worked(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
i = added.iterator();
|
i = added.iterator();
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
|
if (monitor.isCanceled())
|
||||||
|
return;
|
||||||
ITranslationUnit tu = (ITranslationUnit)i.next();
|
ITranslationUnit tu = (ITranslationUnit)i.next();
|
||||||
monitor.subTask(tu.getElementName());
|
|
||||||
try {
|
try {
|
||||||
addTU(tu);
|
addTU(tu);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
CCorePlugin.log(e);
|
CCorePlugin.log(e);
|
||||||
if (++errorCount > MAX_ERRORS)
|
if (++errorCount > MAX_ERRORS)
|
||||||
return Status.CANCEL_STATUS;
|
return;
|
||||||
}
|
}
|
||||||
monitor.worked(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
i = removed.iterator();
|
i = removed.iterator();
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
|
if (monitor.isCanceled())
|
||||||
|
return;
|
||||||
ITranslationUnit tu = (ITranslationUnit)i.next();
|
ITranslationUnit tu = (ITranslationUnit)i.next();
|
||||||
monitor.subTask(tu.getElementName());
|
|
||||||
removeTU(tu);
|
removeTU(tu);
|
||||||
monitor.worked(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String showTimings = Platform.getDebugOption(CCorePlugin.PLUGIN_ID
|
String showTimings = Platform.getDebugOption(CCorePlugin.PLUGIN_ID
|
||||||
|
@ -106,12 +102,9 @@ public class PDOMFullHandleDelta extends PDOMFullIndexerJob {
|
||||||
if (showTimings != null && showTimings.equalsIgnoreCase("true")) //$NON-NLS-1$
|
if (showTimings != null && showTimings.equalsIgnoreCase("true")) //$NON-NLS-1$
|
||||||
System.out.println("PDOM Full Delta Time: " + (System.currentTimeMillis() - start)); //$NON-NLS-1$
|
System.out.println("PDOM Full Delta Time: " + (System.currentTimeMillis() - start)); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
return Status.OK_STATUS;
|
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
return e.getStatus();
|
CCorePlugin.log(e);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
return Status.CANCEL_STATUS;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.core.pdom.indexer.full;
|
package org.eclipse.cdt.internal.core.pdom.indexer.full;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMIndexer;
|
import org.eclipse.cdt.core.dom.IPDOMIndexer;
|
||||||
import org.eclipse.cdt.core.model.ICElementDelta;
|
import org.eclipse.cdt.core.model.ICElementDelta;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
@ -36,11 +37,12 @@ public class PDOMFullIndexer implements IPDOMIndexer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleDelta(ICElementDelta delta) throws CoreException {
|
public void handleDelta(ICElementDelta delta) throws CoreException {
|
||||||
new PDOMFullHandleDelta(this, delta).schedule();
|
CCorePlugin.getPDOMManager().enqueue(
|
||||||
|
new PDOMFullHandleDelta(this, delta));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reindex() throws CoreException {
|
public void reindex() throws CoreException {
|
||||||
new PDOMFullReindex(this).schedule();
|
CCorePlugin.getPDOMManager().enqueue(new PDOMFullReindex(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
package org.eclipse.cdt.internal.core.pdom.indexer.full;
|
package org.eclipse.cdt.internal.core.pdom.indexer.full;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
|
@ -24,13 +25,12 @@ import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.jobs.Job;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public abstract class PDOMFullIndexerJob extends Job {
|
public abstract class PDOMFullIndexerJob implements IPDOMIndexerTask {
|
||||||
|
|
||||||
protected final PDOMFullIndexer indexer;
|
protected final PDOMFullIndexer indexer;
|
||||||
protected final PDOM pdom;
|
protected final PDOM pdom;
|
||||||
|
@ -40,10 +40,8 @@ public abstract class PDOMFullIndexerJob extends Job {
|
||||||
protected final int MAX_ERRORS = 10;
|
protected final int MAX_ERRORS = 10;
|
||||||
|
|
||||||
public PDOMFullIndexerJob(PDOMFullIndexer indexer) throws CoreException {
|
public PDOMFullIndexerJob(PDOMFullIndexer indexer) throws CoreException {
|
||||||
super("Full Indexer: " + indexer.getProject().getElementName());
|
|
||||||
this.indexer = indexer;
|
this.indexer = indexer;
|
||||||
this.pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(indexer.getProject());
|
this.pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(indexer.getProject());
|
||||||
setRule(CCorePlugin.getPDOMManager().getIndexerSchedulingRule());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IASTTranslationUnit parse(ITranslationUnit tu) throws CoreException {
|
protected IASTTranslationUnit parse(ITranslationUnit tu) throws CoreException {
|
||||||
|
|
|
@ -18,7 +18,6 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
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.IStatus;
|
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
|
|
||||||
|
@ -32,33 +31,13 @@ public class PDOMFullReindex extends PDOMFullIndexerJob {
|
||||||
super(indexer);
|
super(indexer);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IStatus run(final IProgressMonitor monitor) {
|
public void run(final IProgressMonitor monitor) {
|
||||||
try {
|
try {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
|
|
||||||
// First clear out the PDOM
|
// First clear out the PDOM
|
||||||
pdom.clear();
|
pdom.clear();
|
||||||
|
|
||||||
// Get a count of all the elements that we'll be visiting for the monitor
|
|
||||||
final int[] count = { 0 };
|
|
||||||
indexer.getProject().accept(new ICElementVisitor() {
|
|
||||||
public boolean visit(ICElement element) throws CoreException {
|
|
||||||
if (monitor.isCanceled())
|
|
||||||
throw new CoreException(Status.CANCEL_STATUS);
|
|
||||||
switch (element.getElementType()) {
|
|
||||||
case ICElement.C_UNIT:
|
|
||||||
++count[0];
|
|
||||||
return false;
|
|
||||||
case ICElement.C_CCONTAINER:
|
|
||||||
case ICElement.C_PROJECT:
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
monitor.beginTask("Indexing", count[0]);
|
|
||||||
|
|
||||||
// First index all the source files (i.e. not headers)
|
// First index all the source files (i.e. not headers)
|
||||||
indexer.getProject().accept(new ICElementVisitor() {
|
indexer.getProject().accept(new ICElementVisitor() {
|
||||||
public boolean visit(ICElement element) throws CoreException {
|
public boolean visit(ICElement element) throws CoreException {
|
||||||
|
@ -68,7 +47,6 @@ public class PDOMFullReindex extends PDOMFullIndexerJob {
|
||||||
case ICElement.C_UNIT:
|
case ICElement.C_UNIT:
|
||||||
ITranslationUnit tu = (ITranslationUnit)element;
|
ITranslationUnit tu = (ITranslationUnit)element;
|
||||||
if (tu.isSourceUnit()) {
|
if (tu.isSourceUnit()) {
|
||||||
monitor.subTask(tu.getElementName());
|
|
||||||
try {
|
try {
|
||||||
addTU(tu);
|
addTU(tu);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
@ -76,7 +54,6 @@ public class PDOMFullReindex extends PDOMFullIndexerJob {
|
||||||
if (++errorCount > MAX_ERRORS)
|
if (++errorCount > MAX_ERRORS)
|
||||||
throw new CoreException(Status.CANCEL_STATUS);
|
throw new CoreException(Status.CANCEL_STATUS);
|
||||||
}
|
}
|
||||||
monitor.worked(1);
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
case ICElement.C_CCONTAINER:
|
case ICElement.C_CCONTAINER:
|
||||||
|
@ -99,7 +76,6 @@ public class PDOMFullReindex extends PDOMFullIndexerJob {
|
||||||
IFile rfile = (IFile)tu.getUnderlyingResource();
|
IFile rfile = (IFile)tu.getUnderlyingResource();
|
||||||
String filename = rfile.getLocation().toOSString();
|
String filename = rfile.getLocation().toOSString();
|
||||||
if (pdom.getFile(filename) == null) {
|
if (pdom.getFile(filename) == null) {
|
||||||
monitor.subTask(tu.getElementName());
|
|
||||||
try {
|
try {
|
||||||
addTU(tu);
|
addTU(tu);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
@ -108,7 +84,6 @@ public class PDOMFullReindex extends PDOMFullIndexerJob {
|
||||||
throw new CoreException(Status.CANCEL_STATUS);
|
throw new CoreException(Status.CANCEL_STATUS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
monitor.worked(1);
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
case ICElement.C_CCONTAINER:
|
case ICElement.C_CCONTAINER:
|
||||||
|
@ -122,11 +97,11 @@ public class PDOMFullReindex extends PDOMFullIndexerJob {
|
||||||
String showTimings = Platform.getDebugOption(CCorePlugin.PLUGIN_ID
|
String showTimings = Platform.getDebugOption(CCorePlugin.PLUGIN_ID
|
||||||
+ "/debug/pdomtimings"); //$NON-NLS-1$
|
+ "/debug/pdomtimings"); //$NON-NLS-1$
|
||||||
if (showTimings != null && showTimings.equalsIgnoreCase("true")) //$NON-NLS-1$
|
if (showTimings != null && showTimings.equalsIgnoreCase("true")) //$NON-NLS-1$
|
||||||
System.out.println("PDOM Full Reindex Time: " + (System.currentTimeMillis() - start)); //$NON-NLS-1$
|
System.out.println("PDOM Full Reindex Time: " + (System.currentTimeMillis() - start) //$NON-NLS-1$
|
||||||
|
+ " " + indexer.getProject().getElementName()); //$NON-NLS-1$
|
||||||
return Status.OK_STATUS;
|
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
return e.getStatus();
|
if (e.getStatus() != Status.CANCEL_STATUS)
|
||||||
|
CCorePlugin.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue