mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Flipped back to a read/write lock on the pdom. Made the indexing operations one job to reduce the number of threads on the go. Now caching the language id to language object to speed up operations.
This commit is contained in:
parent
89ae273720
commit
23684e5f8f
11 changed files with 287 additions and 386 deletions
|
@ -12,6 +12,8 @@
|
|||
package org.eclipse.cdt.core.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.internal.core.model.TranslationUnit;
|
||||
|
@ -30,6 +32,7 @@ import org.eclipse.core.runtime.content.IContentTypeManager;
|
|||
public class LanguageManager {
|
||||
|
||||
private static LanguageManager instance;
|
||||
private Map cache = new HashMap();
|
||||
|
||||
public static LanguageManager getInstance() {
|
||||
if (instance == null)
|
||||
|
@ -38,16 +41,22 @@ public class LanguageManager {
|
|||
}
|
||||
|
||||
public ILanguage getLanguage(String id) throws CoreException {
|
||||
ILanguage language = (ILanguage)cache.get(id);
|
||||
if (language != null)
|
||||
return language;
|
||||
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, ILanguage.KEY);
|
||||
IExtension[] extensions = point.getExtensions();
|
||||
for (int i = 0; i < extensions.length; ++i) {
|
||||
IExtension extension = extensions[i];
|
||||
IConfigurationElement[] languages = extension.getConfigurationElements();
|
||||
for (int j = 0; j < languages.length; ++j) {
|
||||
IConfigurationElement language = languages[j];
|
||||
String langId = extension.getNamespace() + "." + language.getAttribute("id"); //$NON-NLS-1$ $NON-NLS-2$
|
||||
if (langId.equals(id))
|
||||
return (ILanguage)language.createExecutableExtension("class"); //$NON-NLS-1$
|
||||
IConfigurationElement languageElem = languages[j];
|
||||
String langId = extension.getNamespace() + "." + languageElem.getAttribute("id"); //$NON-NLS-1$ $NON-NLS-2$
|
||||
if (langId.equals(id)) {
|
||||
language = (ILanguage)languageElem.createExecutableExtension("class"); //$NON-NLS-1$
|
||||
cache.put(id, language);
|
||||
return language;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,10 +27,20 @@ public interface IPDOM extends IAdaptable {
|
|||
|
||||
public IBinding resolveBinding(IASTName name);
|
||||
|
||||
public IBinding[] findBindings(String pattern) throws CoreException;
|
||||
|
||||
public IASTName[] getDeclarations(IBinding binding);
|
||||
|
||||
public void delete() throws CoreException;
|
||||
|
||||
/**
|
||||
* Looks to see if anything has been stored in this PDOM.
|
||||
*
|
||||
* @return is the PDOM empty
|
||||
* @throws CoreException
|
||||
*/
|
||||
public boolean isEmpty() throws CoreException;
|
||||
|
||||
public ICodeReaderFactory getCodeReaderFactory();
|
||||
|
||||
public ICodeReaderFactory getCodeReaderFactory(IWorkingCopy root);
|
||||
|
@ -38,4 +48,9 @@ public interface IPDOM extends IAdaptable {
|
|||
public IPDOMIndexer getIndexer();
|
||||
public void setIndexer(IPDOMIndexer indexer) throws CoreException;
|
||||
|
||||
public void acquireReadLock() throws InterruptedException;
|
||||
public void releaseReadLock();
|
||||
public void acquireWriteLock() throws InterruptedException;
|
||||
public void releaseWriteLock();
|
||||
|
||||
}
|
||||
|
|
|
@ -41,8 +41,6 @@ import org.eclipse.core.runtime.CoreException;
|
|||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
import org.eclipse.core.runtime.QualifiedName;
|
||||
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
|
||||
/**
|
||||
* The PDOM Database.
|
||||
|
@ -227,6 +225,10 @@ public class PDOM extends PlatformObject implements IPDOM {
|
|||
fileIndex = null;
|
||||
}
|
||||
|
||||
public boolean isEmpty() throws CoreException {
|
||||
return getFirstLinkage() == null;
|
||||
}
|
||||
|
||||
public ICodeReaderFactory getCodeReaderFactory() {
|
||||
return new PDOMCodeReaderFactory(this);
|
||||
}
|
||||
|
@ -260,14 +262,14 @@ public class PDOM extends PlatformObject implements IPDOM {
|
|||
return null;
|
||||
}
|
||||
|
||||
public PDOMBinding[] findBindings(String pattern) throws CoreException {
|
||||
public IBinding[] findBindings(String pattern) throws CoreException {
|
||||
List bindings = new ArrayList();
|
||||
PDOMLinkage linkage = getFirstLinkage();
|
||||
while (linkage != null) {
|
||||
linkage.findBindings(pattern, bindings);
|
||||
linkage = linkage.getNextLinkage();
|
||||
}
|
||||
return (PDOMBinding[])bindings.toArray(new PDOMBinding[bindings.size()]);
|
||||
return (IBinding[])bindings.toArray(new IBinding[bindings.size()]);
|
||||
}
|
||||
|
||||
public PDOMLinkage getLinkage(ILanguage language) throws CoreException {
|
||||
|
@ -311,41 +313,43 @@ public class PDOM extends PlatformObject implements IPDOM {
|
|||
|
||||
// Read-write lock rules. Readers don't conflict with other readers,
|
||||
// Writers conflict with readers, and everyone conflicts with writers.
|
||||
private final ISchedulingRule readerLockRule = new ISchedulingRule() {
|
||||
public boolean isConflicting(ISchedulingRule rule) {
|
||||
if (rule == this)
|
||||
return false;
|
||||
else if (rule == getWriterLockRule())
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
public boolean contains(ISchedulingRule rule) {
|
||||
return rule == this;
|
||||
}
|
||||
};
|
||||
private Object mutex = new Object();
|
||||
private int lockCount;
|
||||
private int waitingReaders;
|
||||
|
||||
private final ISchedulingRule writerLockRule = new ISchedulingRule() {
|
||||
public boolean isConflicting(ISchedulingRule rule) {
|
||||
if (rule == this || rule == getReaderLockRule())
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
public void acquireReadLock() throws InterruptedException {
|
||||
synchronized (mutex) {
|
||||
++waitingReaders;
|
||||
while (lockCount < 0)
|
||||
mutex.wait();
|
||||
--waitingReaders;
|
||||
++lockCount;
|
||||
}
|
||||
public boolean contains(ISchedulingRule rule) {
|
||||
return rule == this;
|
||||
}
|
||||
};
|
||||
|
||||
public ISchedulingRule getReaderLockRule() {
|
||||
return readerLockRule;
|
||||
}
|
||||
|
||||
public ISchedulingRule getWriterLockRule() {
|
||||
return writerLockRule;
|
||||
public void releaseReadLock() {
|
||||
synchronized (mutex) {
|
||||
if (lockCount > 0)
|
||||
--lockCount;
|
||||
mutex.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
public void acquireWriteLock() throws InterruptedException {
|
||||
synchronized (mutex) {
|
||||
// Let the readers go first
|
||||
while (lockCount != 0 || waitingReaders > 0)
|
||||
mutex.wait();
|
||||
--lockCount;
|
||||
}
|
||||
}
|
||||
|
||||
public void releaseWriteLock() {
|
||||
synchronized (mutex) {
|
||||
if (lockCount < 0)
|
||||
++lockCount;
|
||||
mutex.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
// These are really only recommendations
|
||||
public static final int READER_PRIORITY = Job.SHORT;
|
||||
public static final int WRITER_PRIORITY = Job.LONG;
|
||||
}
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom.indexer.fast;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
*
|
||||
*/
|
||||
public class PDOMFastAddTU extends Job {
|
||||
|
||||
private final ITranslationUnit tu;
|
||||
private final PDOM pdom;
|
||||
|
||||
public PDOMFastAddTU(PDOM pdom, ITranslationUnit tu, IProgressMonitor group) {
|
||||
super("PDOM Fast Add: " + tu.getElementName());
|
||||
this.pdom = pdom;
|
||||
this.tu = tu;
|
||||
setPriority(PDOM.WRITER_PRIORITY);
|
||||
setProgressGroup(group, 1);
|
||||
}
|
||||
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
try {
|
||||
ILanguage language = tu.getLanguage();
|
||||
if (language == null)
|
||||
return Status.CANCEL_STATUS;
|
||||
|
||||
// begin the rule before the parse so that we are only parsing once at a time
|
||||
// maybe we can do more than one some day
|
||||
getJobManager().beginRule(pdom.getWriterLockRule(), monitor);
|
||||
monitor.beginTask("Adding: " + tu.getElementName(), 1);
|
||||
|
||||
// get the AST in a "Fast" way
|
||||
IASTTranslationUnit ast = language.getASTTranslationUnit(tu,
|
||||
ILanguage.AST_USE_INDEX |
|
||||
ILanguage.AST_SKIP_INDEXED_HEADERS |
|
||||
ILanguage.AST_SKIP_IF_NO_BUILD_INFO);
|
||||
if (ast == null)
|
||||
return Status.CANCEL_STATUS;
|
||||
|
||||
pdom.addSymbols(language, ast);
|
||||
monitor.done();
|
||||
getJobManager().endRule(pdom.getWriterLockRule());
|
||||
return Status.OK_STATUS;
|
||||
} catch (CoreException e) {
|
||||
return e.getStatus();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom.indexer.fast;
|
||||
|
||||
import org.eclipse.cdt.core.dom.IPDOM;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
*
|
||||
*/
|
||||
public class PDOMFastChangeTU extends Job {
|
||||
|
||||
private final PDOM pdom;
|
||||
private final ITranslationUnit tu;
|
||||
|
||||
public PDOMFastChangeTU(IPDOM pdom, ITranslationUnit tu) {
|
||||
super("PDOM Fast Change TU");
|
||||
this.pdom = (pdom instanceof PDOM) ? (PDOM)pdom : null;
|
||||
this.tu = tu;
|
||||
}
|
||||
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
if (pdom == null)
|
||||
return Status.CANCEL_STATUS;
|
||||
try {
|
||||
ILanguage language = tu.getLanguage();
|
||||
if (language == null)
|
||||
return Status.CANCEL_STATUS;
|
||||
|
||||
getJobManager().beginRule(pdom.getWriterLockRule(), monitor);
|
||||
|
||||
// get the AST in a "Fast" way
|
||||
IASTTranslationUnit ast = language.getASTTranslationUnit(tu,
|
||||
ILanguage.AST_USE_INDEX |
|
||||
ILanguage.AST_SKIP_INDEXED_HEADERS |
|
||||
ILanguage.AST_SKIP_IF_NO_BUILD_INFO);
|
||||
if (ast == null)
|
||||
return Status.CANCEL_STATUS;
|
||||
|
||||
pdom.removeSymbols(tu);
|
||||
pdom.addSymbols(language, ast);
|
||||
getJobManager().endRule(pdom.getWriterLockRule());
|
||||
return Status.OK_STATUS;
|
||||
} catch (CoreException e) {
|
||||
return e.getStatus();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -16,53 +16,45 @@ import java.util.LinkedList;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICElementDelta;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IResourceProxy;
|
||||
import org.eclipse.core.resources.IResourceProxyVisitor;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.content.IContentType;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
|
||||
class PDOMFastHandleDelta extends Job {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private final PDOM pdom;
|
||||
|
||||
private final ICElementDelta delta;
|
||||
private final IProgressMonitor group;
|
||||
|
||||
private List addedTUs;
|
||||
|
||||
private List changedTUs;
|
||||
|
||||
private List removedTUs;
|
||||
|
||||
public PDOMFastHandleDelta(PDOM pdom, ICElementDelta delta, IProgressMonitor group) {
|
||||
public PDOMFastHandleDelta(PDOM pdom, ICElementDelta delta) {
|
||||
super("Delta Handler");
|
||||
this.pdom = pdom;
|
||||
this.delta = delta;
|
||||
this.group = group;
|
||||
setProgressGroup(group, 1);
|
||||
}
|
||||
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
try {
|
||||
monitor.subTask("Delta");
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
processDelta(delta);
|
||||
|
||||
int count
|
||||
= (addedTUs != null ? addedTUs.size() : 0)
|
||||
int count = (addedTUs != null ? addedTUs.size() : 0)
|
||||
+ (changedTUs != null ? changedTUs.size() : 0)
|
||||
+ (removedTUs != null ? removedTUs.size() : 0);
|
||||
|
||||
|
@ -75,22 +67,20 @@ class PDOMFastHandleDelta extends Job {
|
|||
for (Iterator i = addedTUs.iterator(); i.hasNext();) {
|
||||
if (monitor.isCanceled())
|
||||
return Status.CANCEL_STATUS;
|
||||
ITranslationUnit tu = (ITranslationUnit)i.next();
|
||||
monitor.subTask(String.valueOf(count--)
|
||||
+" files remaining - "
|
||||
ITranslationUnit tu = (ITranslationUnit) i.next();
|
||||
monitor.subTask(String.valueOf(count--) + " files remaining - "
|
||||
+ tu.getPath().toString());
|
||||
new PDOMFastAddTU(pdom, tu, group).schedule();
|
||||
addTU(tu);
|
||||
}
|
||||
|
||||
if (changedTUs != null)
|
||||
for (Iterator i = changedTUs.iterator(); i.hasNext();) {
|
||||
if (monitor.isCanceled())
|
||||
return Status.CANCEL_STATUS;
|
||||
ITranslationUnit tu = (ITranslationUnit)i.next();
|
||||
monitor.subTask(String.valueOf(count--)
|
||||
+" files remaining - "
|
||||
ITranslationUnit tu = (ITranslationUnit) i.next();
|
||||
monitor.subTask(String.valueOf(count--) + " files remaining - "
|
||||
+ tu.getPath().toString());
|
||||
new PDOMFastChangeTU(pdom, tu).schedule();
|
||||
changeTU(tu);
|
||||
monitor.worked(1);
|
||||
}
|
||||
|
||||
|
@ -98,27 +88,37 @@ class PDOMFastHandleDelta extends Job {
|
|||
for (Iterator i = removedTUs.iterator(); i.hasNext();) {
|
||||
if (monitor.isCanceled())
|
||||
return Status.CANCEL_STATUS;
|
||||
ITranslationUnit tu = (ITranslationUnit)i.next();
|
||||
monitor.subTask(String.valueOf(count--)
|
||||
+" files remaining - "
|
||||
ITranslationUnit tu = (ITranslationUnit) i.next();
|
||||
monitor.subTask(String.valueOf(count--) + " files remaining - "
|
||||
+ tu.getPath().toString());
|
||||
new PDOMFastRemoveTU(pdom, tu).schedule();
|
||||
removeTU(tu);
|
||||
monitor.worked(1);
|
||||
}
|
||||
|
||||
String showTimings = Platform.getDebugOption(CCorePlugin.PLUGIN_ID + "/debug/pdomtimings"); //$NON-NLS-1$
|
||||
if (showTimings!= null)
|
||||
String showTimings = Platform.getDebugOption(CCorePlugin.PLUGIN_ID
|
||||
+ "/debug/pdomtimings"); //$NON-NLS-1$
|
||||
if (showTimings != null)
|
||||
if (showTimings.equalsIgnoreCase("true")) //$NON-NLS-1$
|
||||
System.out.println("Updator Time: " + (System.currentTimeMillis() - start)); //$NON-NLS-1$
|
||||
System.out
|
||||
.println("Updator Time: " + (System.currentTimeMillis() - start)); //$NON-NLS-1$
|
||||
|
||||
return Status.OK_STATUS;
|
||||
} catch (CoreException e) {
|
||||
return e.getStatus();
|
||||
} catch (InterruptedException e) {
|
||||
return Status.CANCEL_STATUS;
|
||||
}
|
||||
}
|
||||
|
||||
private void processDelta(ICElementDelta delta) {
|
||||
// First make sure this project is PDOMable
|
||||
ICElement element = delta.getElement();
|
||||
if (element instanceof ICProject && CCorePlugin.getPDOMManager().getPDOM((ICProject)element) == null)
|
||||
|
||||
// If this is a project add skip over to the reindex job
|
||||
if (element.getElementType() == ICElement.C_PROJECT
|
||||
&& delta.getKind() == ICElementDelta.ADDED) {
|
||||
new PDOMFastReindex(pdom).schedule();
|
||||
return;
|
||||
}
|
||||
|
||||
// process the children first
|
||||
ICElementDelta[] children = delta.getAffectedChildren();
|
||||
|
@ -126,14 +126,8 @@ class PDOMFastHandleDelta extends Job {
|
|||
processDelta(children[i]);
|
||||
|
||||
// what have we got
|
||||
if (element.getElementType() == ICElement.C_PROJECT) {
|
||||
switch (delta.getKind()) {
|
||||
case ICElementDelta.ADDED:
|
||||
processNewProject((ICProject)element);
|
||||
break;
|
||||
}
|
||||
} else if (element.getElementType() == ICElement.C_UNIT) {
|
||||
ITranslationUnit tu = (ITranslationUnit)element;
|
||||
if (element.getElementType() == ICElement.C_UNIT) {
|
||||
ITranslationUnit tu = (ITranslationUnit) element;
|
||||
if (tu.isWorkingCopy())
|
||||
// Don't care about working copies either
|
||||
return;
|
||||
|
@ -158,32 +152,58 @@ class PDOMFastHandleDelta extends Job {
|
|||
}
|
||||
}
|
||||
|
||||
private void processNewProject(final ICProject project) {
|
||||
try {
|
||||
project.getProject().accept(new IResourceProxyVisitor() {
|
||||
public boolean visit(IResourceProxy proxy) throws CoreException {
|
||||
if (proxy.getType() == IResource.FILE) {
|
||||
String fileName = proxy.getName();
|
||||
IContentType contentType = Platform.getContentTypeManager().findContentTypeFor(fileName);
|
||||
if (contentType == null)
|
||||
return true;
|
||||
String contentTypeId = contentType.getId();
|
||||
protected void addTU(ITranslationUnit tu) throws InterruptedException, CoreException {
|
||||
ILanguage language = tu.getLanguage();
|
||||
if (language == null)
|
||||
return;
|
||||
|
||||
if (CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(contentTypeId)
|
||||
|| CCorePlugin.CONTENT_TYPE_CSOURCE.equals(contentTypeId)) {
|
||||
if (addedTUs == null)
|
||||
addedTUs = new LinkedList();
|
||||
addedTUs.add(CoreModel.getDefault().create((IFile)proxy.requestResource()));
|
||||
}
|
||||
// TODO handle header files
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
// get the AST in a "Fast" way
|
||||
IASTTranslationUnit ast = language.getASTTranslationUnit(tu,
|
||||
ILanguage.AST_USE_INDEX
|
||||
| ILanguage.AST_SKIP_INDEXED_HEADERS
|
||||
| ILanguage.AST_SKIP_IF_NO_BUILD_INFO);
|
||||
if (ast == null)
|
||||
return;
|
||||
|
||||
pdom.acquireWriteLock();
|
||||
try {
|
||||
pdom.addSymbols(language, ast);
|
||||
} finally {
|
||||
pdom.releaseWriteLock();
|
||||
}
|
||||
}
|
||||
}, 0);
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
|
||||
protected void changeTU(ITranslationUnit tu) throws InterruptedException, CoreException {
|
||||
ILanguage language = tu.getLanguage();
|
||||
if (language == null)
|
||||
return;
|
||||
|
||||
// get the AST in a "Fast" way
|
||||
IASTTranslationUnit ast = language.getASTTranslationUnit(tu,
|
||||
ILanguage.AST_USE_INDEX |
|
||||
ILanguage.AST_SKIP_INDEXED_HEADERS |
|
||||
ILanguage.AST_SKIP_IF_NO_BUILD_INFO);
|
||||
|
||||
if (ast == null)
|
||||
return;
|
||||
|
||||
pdom.acquireWriteLock();
|
||||
try {
|
||||
pdom.removeSymbols(tu);
|
||||
pdom.addSymbols(language, ast);
|
||||
} finally {
|
||||
pdom.releaseWriteLock();
|
||||
}
|
||||
}
|
||||
|
||||
protected void removeTU(ITranslationUnit tu) throws InterruptedException, CoreException {
|
||||
pdom.acquireWriteLock();
|
||||
try {
|
||||
pdom.removeSymbols(tu);
|
||||
// TODO delete the file itself from the database
|
||||
// the removeSymbols only removes the names in the file
|
||||
} finally {
|
||||
pdom.releaseWriteLock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,14 +34,11 @@ public class PDOMFastIndexer implements IPDOMIndexer {
|
|||
}
|
||||
|
||||
public void handleDelta(ICElementDelta delta) {
|
||||
IProgressMonitor group = Platform.getJobManager().createProgressGroup();
|
||||
new PDOMFastHandleDelta(pdom, delta, group).schedule();
|
||||
new PDOMFastHandleDelta(pdom, delta).schedule();
|
||||
}
|
||||
|
||||
public void reindex() throws CoreException {
|
||||
IProgressMonitor group = Platform.getJobManager().createProgressGroup();
|
||||
group.beginTask("Reindexing", 100);
|
||||
new PDOMFastReindex(pdom, group).schedule();
|
||||
new PDOMFastReindex(pdom).schedule();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,8 +11,14 @@
|
|||
|
||||
package org.eclipse.cdt.internal.core.pdom.indexer.fast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
@ -34,17 +40,16 @@ import org.eclipse.core.runtime.jobs.Job;
|
|||
public class PDOMFastReindex extends Job {
|
||||
|
||||
private final PDOM pdom;
|
||||
private final IProgressMonitor group;
|
||||
|
||||
public PDOMFastReindex(PDOM pdom, IProgressMonitor group) {
|
||||
public PDOMFastReindex(PDOM pdom) {
|
||||
super("Reindex");
|
||||
this.pdom = pdom;
|
||||
this.group = group;
|
||||
setProgressGroup(group, 1);
|
||||
}
|
||||
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
try {
|
||||
final List addedTUs = new ArrayList();
|
||||
|
||||
// First clear out the DB
|
||||
pdom.delete();
|
||||
|
||||
|
@ -60,20 +65,47 @@ public class PDOMFastReindex extends Job {
|
|||
|
||||
if (CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(contentTypeId)
|
||||
|| CCorePlugin.CONTENT_TYPE_CSOURCE.equals(contentTypeId)) {
|
||||
new PDOMFastAddTU(pdom, (ITranslationUnit)CoreModel.getDefault().create((IFile)proxy.requestResource()), group).schedule();
|
||||
}
|
||||
// TODO handle header files
|
||||
addedTUs.add((ITranslationUnit)CoreModel.getDefault().create((IFile)proxy.requestResource()));
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}, 0);
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
|
||||
for (Iterator i = addedTUs.iterator(); i.hasNext();)
|
||||
addTU((ITranslationUnit)i.next());
|
||||
|
||||
monitor.done();
|
||||
return Status.OK_STATUS;
|
||||
} catch (CoreException e) {
|
||||
return e.getStatus();
|
||||
} catch (InterruptedException e) {
|
||||
return Status.CANCEL_STATUS;
|
||||
}
|
||||
}
|
||||
|
||||
protected void addTU(ITranslationUnit tu) throws InterruptedException, CoreException {
|
||||
ILanguage language = tu.getLanguage();
|
||||
if (language == null)
|
||||
return;
|
||||
|
||||
// get the AST in a "Fast" way
|
||||
IASTTranslationUnit ast = language.getASTTranslationUnit(tu,
|
||||
ILanguage.AST_USE_INDEX
|
||||
| ILanguage.AST_SKIP_INDEXED_HEADERS
|
||||
| ILanguage.AST_SKIP_IF_NO_BUILD_INFO);
|
||||
if (ast == null)
|
||||
return;
|
||||
|
||||
pdom.acquireWriteLock();
|
||||
try {
|
||||
pdom.addSymbols(language, ast);
|
||||
} finally {
|
||||
pdom.releaseWriteLock();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom.indexer.fast;
|
||||
|
||||
import org.eclipse.cdt.core.dom.IPDOM;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
*
|
||||
*/
|
||||
public class PDOMFastRemoveTU extends Job {
|
||||
|
||||
private final PDOM pdom;
|
||||
private final ITranslationUnit tu;
|
||||
|
||||
public PDOMFastRemoveTU(IPDOM pdom, ITranslationUnit tu) {
|
||||
super("PDOM Fast Remove TU");
|
||||
this.pdom = (pdom instanceof PDOM) ? (PDOM)pdom : null;
|
||||
this.tu = tu;
|
||||
}
|
||||
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
if (pdom == null)
|
||||
return Status.CANCEL_STATUS;
|
||||
try {
|
||||
getJobManager().beginRule(pdom.getWriterLockRule(), monitor);
|
||||
pdom.removeSymbols(tu);
|
||||
// TODO delete the file itself from the database
|
||||
// the removeSymbols only removes the names in the file
|
||||
getJobManager().endRule(pdom.getWriterLockRule());
|
||||
return Status.OK_STATUS;
|
||||
} catch (CoreException e) {
|
||||
return e.getStatus();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -16,10 +16,10 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.IPDOM;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
|
@ -82,25 +82,35 @@ public class PDOMSearchPatternQuery extends PDOMSearchQuery {
|
|||
|
||||
try {
|
||||
for (Iterator iproject = projects.iterator(); iproject.hasNext();)
|
||||
searchProject((IProject)iproject.next());
|
||||
searchProject((IProject)iproject.next(), monitor);
|
||||
return Status.OK_STATUS;
|
||||
} catch (CoreException e) {
|
||||
return e.getStatus();
|
||||
}
|
||||
}
|
||||
|
||||
private void searchProject(IProject project) throws CoreException {
|
||||
private void searchProject(IProject project, IProgressMonitor monitor) throws CoreException {
|
||||
if (!CoreModel.hasCNature(project))
|
||||
// Not a CDT project
|
||||
return;
|
||||
|
||||
ICProject cproject = CoreModel.getDefault().create(project);
|
||||
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(cproject);
|
||||
PDOMBinding[] bindings = pdom.findBindings(pattern);
|
||||
IPDOM pdom = CCorePlugin.getPDOMManager().getPDOM(cproject);
|
||||
|
||||
try {
|
||||
pdom.acquireReadLock();
|
||||
} catch (InterruptedException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
IBinding[] bindings = pdom.findBindings(pattern);
|
||||
for (int i = 0; i < bindings.length; ++i) {
|
||||
createMatches(bindings[i]);
|
||||
}
|
||||
} finally {
|
||||
pdom.releaseReadLock();
|
||||
}
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
package org.eclipse.cdt.internal.ui.search;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -79,17 +80,19 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
|||
}
|
||||
}
|
||||
|
||||
protected void createMatches(PDOMBinding binding) throws CoreException {
|
||||
protected void createMatches(IBinding binding) throws CoreException {
|
||||
if (binding instanceof PDOMBinding) {
|
||||
PDOMBinding pdomBinding = (PDOMBinding)binding;
|
||||
if ((flags & FIND_DECLARATIONS) != 0) {
|
||||
collectNames(binding.getFirstDeclaration());
|
||||
collectNames(pdomBinding.getFirstDeclaration());
|
||||
}
|
||||
if ((flags & FIND_DECLARATIONS) != 0) {
|
||||
collectNames(binding.getFirstDefinition());
|
||||
collectNames(pdomBinding.getFirstDefinition());
|
||||
}
|
||||
if ((flags & FIND_REFERENCES) != 0) {
|
||||
collectNames(binding.getFirstReference());
|
||||
collectNames(pdomBinding.getFirstReference());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue