mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-10 09:45:39 +02:00
Fix for 104583, part I: indexer policy core implementation
This commit is contained in:
parent
f7f9021075
commit
f7d244ff58
11 changed files with 452 additions and 254 deletions
|
@ -17,13 +17,15 @@ import org.eclipse.cdt.core.model.ICElement;
|
||||||
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;
|
||||||
import org.eclipse.cdt.core.model.IElementChangedListener;
|
import org.eclipse.cdt.core.model.IElementChangedListener;
|
||||||
|
import org.eclipse.core.resources.IResourceChangeEvent;
|
||||||
|
import org.eclipse.core.resources.IResourceChangeListener;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CModel listener used for the PDOMManager.
|
* CModel listener used for the PDOMManager.
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
public class CModelListener implements IElementChangedListener {
|
public class CModelListener implements IElementChangedListener, IResourceChangeListener {
|
||||||
|
|
||||||
private PDOMManager fManager;
|
private PDOMManager fManager;
|
||||||
|
|
||||||
|
@ -58,7 +60,7 @@ public class CModelListener implements IElementChangedListener {
|
||||||
final ICProject project = (ICProject)delta.getElement();
|
final ICProject project = (ICProject)delta.getElement();
|
||||||
switch (delta.getKind()) {
|
switch (delta.getKind()) {
|
||||||
case ICElementDelta.ADDED:
|
case ICElementDelta.ADDED:
|
||||||
fManager.addProject(project.getProject());
|
fManager.addProject(project);
|
||||||
break;
|
break;
|
||||||
case ICElementDelta.CHANGED:
|
case ICElementDelta.CHANGED:
|
||||||
fManager.changeProject(project, delta);
|
fManager.changeProject(project, delta);
|
||||||
|
@ -69,4 +71,10 @@ public class CModelListener implements IElementChangedListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resourceChanged(IResourceChangeEvent event) {
|
||||||
|
if (event.getType() == IResourceChangeEvent.POST_BUILD) {
|
||||||
|
fManager.handlePostBuildEvent();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,128 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2007 Wind River Systems, Inc. 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:
|
||||||
|
* Markus Schorn - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
package org.eclipse.cdt.internal.core.pdom;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.IPDOMIndexer;
|
||||||
|
import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
|
||||||
|
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||||
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
|
||||||
|
public class IndexUpdatePolicy {
|
||||||
|
|
||||||
|
public static final int POST_CHANGE = 0;
|
||||||
|
public static final int POST_BUILD = 1;
|
||||||
|
public static final int MANUAL= 2;
|
||||||
|
|
||||||
|
private final ICProject fCProject;
|
||||||
|
private int fKind;
|
||||||
|
|
||||||
|
private HashSet fAdded= new HashSet();
|
||||||
|
private HashSet fChanged= new HashSet();
|
||||||
|
private HashSet fRemoved= new HashSet();
|
||||||
|
private IPDOMIndexer fIndexer;
|
||||||
|
|
||||||
|
public IndexUpdatePolicy(ICProject project, int kind) {
|
||||||
|
fCProject= project;
|
||||||
|
fKind= kind;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ICProject getProject() {
|
||||||
|
return fCProject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getKind() {
|
||||||
|
return fKind;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IPDOMIndexerTask addDelta(ITranslationUnit[] added, ITranslationUnit[] changed,
|
||||||
|
ITranslationUnit[] removed) {
|
||||||
|
if (fIndexer != null && fIndexer.getID().equals(IPDOMManager.ID_NO_INDEXER)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(fKind) {
|
||||||
|
case IndexUpdatePolicy.MANUAL:
|
||||||
|
return null;
|
||||||
|
case IndexUpdatePolicy.POST_CHANGE:
|
||||||
|
if (fIndexer != null) {
|
||||||
|
return fIndexer.createTask(added, changed, removed);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < removed.length; i++) {
|
||||||
|
ITranslationUnit tu = removed[i];
|
||||||
|
fAdded.remove(tu);
|
||||||
|
fChanged.remove(tu);
|
||||||
|
fRemoved.add(tu);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < added.length; i++) {
|
||||||
|
ITranslationUnit tu = added[i];
|
||||||
|
if (!fChanged.contains(tu)) {
|
||||||
|
fAdded.add(tu);
|
||||||
|
}
|
||||||
|
fRemoved.remove(tu);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < changed.length; i++) {
|
||||||
|
ITranslationUnit tu = changed[i];
|
||||||
|
if (!fAdded.contains(tu)) {
|
||||||
|
fChanged.add(tu);
|
||||||
|
}
|
||||||
|
fRemoved.remove(tu);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearTUs() {
|
||||||
|
fAdded.clear();
|
||||||
|
fChanged.clear();
|
||||||
|
fRemoved.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasTUs() {
|
||||||
|
return !(fAdded.isEmpty() && fChanged.isEmpty() && fRemoved.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
public IPDOMIndexerTask createTask() {
|
||||||
|
if (fIndexer != null && hasTUs()) {
|
||||||
|
if (getKind() != IndexUpdatePolicy.MANUAL &&
|
||||||
|
!fIndexer.getID().equals(IPDOMManager.ID_NO_INDEXER)) {
|
||||||
|
return fIndexer.createTask(getAdded(), getChanged(), getRemoved());
|
||||||
|
}
|
||||||
|
clearTUs();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ITranslationUnit[] getAdded() {
|
||||||
|
return (ITranslationUnit[]) fAdded.toArray(new ITranslationUnit[fAdded.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ITranslationUnit[] getChanged() {
|
||||||
|
return (ITranslationUnit[]) fChanged.toArray(new ITranslationUnit[fChanged.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ITranslationUnit[] getRemoved() {
|
||||||
|
return (ITranslationUnit[]) fRemoved.toArray(new ITranslationUnit[fRemoved.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndexer(IPDOMIndexer indexer) {
|
||||||
|
fIndexer= indexer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IPDOMIndexer getIndexer() {
|
||||||
|
return fIndexer;
|
||||||
|
}
|
||||||
|
}
|
|
@ -149,16 +149,19 @@ public class PDOMIndexerJob extends Job {
|
||||||
return monitorJob;
|
return monitorJob;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelJobs(IPDOMIndexer indexer) {
|
public void cancelJobs(IPDOMIndexer indexer, boolean waitUntilCancelled) {
|
||||||
synchronized (taskMutex) {
|
synchronized (taskMutex) {
|
||||||
if (currentTask != null && currentTask.getIndexer() == indexer) {
|
if (currentTask != null &&
|
||||||
|
(indexer == null || currentTask.getIndexer() == indexer)) {
|
||||||
fMonitor.setCanceled(true);
|
fMonitor.setCanceled(true);
|
||||||
cancelledByManager = true;
|
cancelledByManager = true;
|
||||||
while (currentTask != null && currentTask.getIndexer() == indexer) {
|
if (waitUntilCancelled) {
|
||||||
try {
|
while (currentTask != null && currentTask.getIndexer() == indexer) {
|
||||||
taskMutex.wait();
|
try {
|
||||||
} catch (InterruptedException e) {
|
taskMutex.wait();
|
||||||
return;
|
} catch (InterruptedException e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,12 +38,12 @@ import org.eclipse.cdt.core.index.IIndex;
|
||||||
import org.eclipse.cdt.core.index.IIndexChangeListener;
|
import org.eclipse.cdt.core.index.IIndexChangeListener;
|
||||||
import org.eclipse.cdt.core.index.IIndexLocationConverter;
|
import org.eclipse.cdt.core.index.IIndexLocationConverter;
|
||||||
import org.eclipse.cdt.core.index.IIndexerStateListener;
|
import org.eclipse.cdt.core.index.IIndexerStateListener;
|
||||||
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ICContainer;
|
import org.eclipse.cdt.core.model.ICContainer;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
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;
|
||||||
import org.eclipse.cdt.core.model.IElementChangedListener;
|
|
||||||
import org.eclipse.cdt.core.model.ILanguageMappingChangeListener;
|
import org.eclipse.cdt.core.model.ILanguageMappingChangeListener;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.model.LanguageManager;
|
import org.eclipse.cdt.core.model.LanguageManager;
|
||||||
|
@ -58,9 +58,9 @@ import org.eclipse.cdt.internal.core.index.provider.IndexProviderManager;
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM.IListener;
|
import org.eclipse.cdt.internal.core.pdom.PDOM.IListener;
|
||||||
import org.eclipse.cdt.internal.core.pdom.db.ChunkCache;
|
import org.eclipse.cdt.internal.core.pdom.db.ChunkCache;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMProjectIndexLocationConverter;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMProjectIndexLocationConverter;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.indexer.DeltaAnalyzer;
|
||||||
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
|
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
|
||||||
import org.eclipse.cdt.internal.core.pdom.indexer.PDOMRebuildTask;
|
import org.eclipse.cdt.internal.core.pdom.indexer.PDOMRebuildTask;
|
||||||
import org.eclipse.cdt.internal.core.pdom.indexer.PDOMResourceDeltaTask;
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.indexer.PDOMUpdateTask;
|
import org.eclipse.cdt.internal.core.pdom.indexer.PDOMUpdateTask;
|
||||||
import org.eclipse.cdt.internal.core.pdom.indexer.nulli.PDOMNullIndexer;
|
import org.eclipse.cdt.internal.core.pdom.indexer.nulli.PDOMNullIndexer;
|
||||||
import org.eclipse.core.resources.IFolder;
|
import org.eclipse.core.resources.IFolder;
|
||||||
|
@ -98,8 +98,6 @@ import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChange
|
||||||
*/
|
*/
|
||||||
public class PDOMManager implements IWritableIndexManager, IListener {
|
public class PDOMManager implements IWritableIndexManager, IListener {
|
||||||
|
|
||||||
private static final String SETTINGS_FOLDER_NAME = ".settings"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
private static final class PerInstanceSchedulingRule implements ISchedulingRule {
|
private static final class PerInstanceSchedulingRule implements ISchedulingRule {
|
||||||
public boolean contains(ISchedulingRule rule) {
|
public boolean contains(ISchedulingRule rule) {
|
||||||
return rule == this;
|
return rule == this;
|
||||||
|
@ -120,7 +118,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static final QualifiedName indexerProperty= new QualifiedName(CCorePlugin.PLUGIN_ID, "pdomIndexer"); //$NON-NLS-1$
|
private static final String SETTINGS_FOLDER_NAME = ".settings"; //$NON-NLS-1$
|
||||||
private static final QualifiedName dbNameProperty= new QualifiedName(CCorePlugin.PLUGIN_ID, "pdomName"); //$NON-NLS-1$
|
private static final QualifiedName dbNameProperty= new QualifiedName(CCorePlugin.PLUGIN_ID, "pdomName"); //$NON-NLS-1$
|
||||||
|
|
||||||
private static final ISchedulingRule NOTIFICATION_SCHEDULING_RULE = new PerInstanceSchedulingRule();
|
private static final ISchedulingRule NOTIFICATION_SCHEDULING_RULE = new PerInstanceSchedulingRule();
|
||||||
|
@ -147,17 +145,17 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
||||||
private IndexChangeEvent fIndexChangeEvent= new IndexChangeEvent();
|
private IndexChangeEvent fIndexChangeEvent= new IndexChangeEvent();
|
||||||
private IndexerStateEvent fIndexerStateEvent= new IndexerStateEvent();
|
private IndexerStateEvent fIndexerStateEvent= new IndexerStateEvent();
|
||||||
|
|
||||||
private IElementChangedListener fCModelListener= new CModelListener(this);
|
private CModelListener fCModelListener= new CModelListener(this);
|
||||||
private ILanguageMappingChangeListener fLanguageChangeListener = new LanguageMappingChangeListener(this);
|
private ILanguageMappingChangeListener fLanguageChangeListener = new LanguageMappingChangeListener(this);
|
||||||
private IndexFactory fIndexFactory= new IndexFactory(this);
|
private IndexFactory fIndexFactory= new IndexFactory(this);
|
||||||
private IndexProviderManager manager = new IndexProviderManager();
|
private IndexProviderManager fIndexProviderManager = new IndexProviderManager();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serializes creation of new indexer, when acquiring the lock you are
|
* Serializes creation of new indexer, when acquiring the lock you are
|
||||||
* not allowed to hold a lock on fPDOMs.
|
* not allowed to hold a lock on fPDOMs.
|
||||||
*/
|
*/
|
||||||
private Object fIndexerMutex= new Object();
|
private HashMap fUpdatePolicies= new HashMap();
|
||||||
private HashMap fPrefListeners= new HashMap();
|
private HashMap fPrefListeners= new HashMap();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -171,13 +169,34 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
||||||
initializeDatabaseCache();
|
initializeDatabaseCache();
|
||||||
|
|
||||||
final CoreModel model = CoreModel.getDefault();
|
final CoreModel model = CoreModel.getDefault();
|
||||||
|
ResourcesPlugin.getWorkspace().addResourceChangeListener(fCModelListener);
|
||||||
model.addElementChangedListener(fCModelListener);
|
model.addElementChangedListener(fCModelListener);
|
||||||
LanguageManager.getInstance().registerLanguageChangeListener(fLanguageChangeListener);
|
LanguageManager.getInstance().registerLanguageChangeListener(fLanguageChangeListener);
|
||||||
|
|
||||||
IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
|
try {
|
||||||
for (int i = 0; i < projects.length; i++) {
|
ICProject[] projects= model.getCModel().getCProjects();
|
||||||
IProject project = projects[i];
|
for (int i = 0; i < projects.length; i++) {
|
||||||
addProject(project);
|
addProject(projects[i]);
|
||||||
|
}
|
||||||
|
} catch (CModelException e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void shutdown() {
|
||||||
|
final CoreModel model = CoreModel.getDefault();
|
||||||
|
model.removeElementChangedListener(fCModelListener);
|
||||||
|
ResourcesPlugin.getWorkspace().removeResourceChangeListener(fCModelListener);
|
||||||
|
LanguageManager.getInstance().unregisterLanguageChangeListener(fLanguageChangeListener);
|
||||||
|
PDOMIndexerJob jobToCancel= null;
|
||||||
|
synchronized (fTaskQueueMutex) {
|
||||||
|
fTaskQueue.clear();
|
||||||
|
jobToCancel= fIndexerJob;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jobToCancel != null) {
|
||||||
|
assert !Thread.holdsLock(fTaskQueueMutex);
|
||||||
|
jobToCancel.cancelJobs(null, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +227,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IndexProviderManager getIndexProviderManager() {
|
public IndexProviderManager getIndexProviderManager() {
|
||||||
return manager;
|
return fIndexProviderManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -230,16 +249,22 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
||||||
File dbFile= null;
|
File dbFile= null;
|
||||||
if (dbName != null) {
|
if (dbName != null) {
|
||||||
dbFile= fileFromDatabaseName(dbName);
|
dbFile= fileFromDatabaseName(dbName);
|
||||||
ICProject currentCOwner= (ICProject) fFileToProject.get(dbFile);
|
if (!dbFile.exists()) {
|
||||||
if (currentCOwner != null) {
|
dbFile= null;
|
||||||
IProject currentOwner= currentCOwner.getProject();
|
dbName= null;
|
||||||
if (currentOwner.exists()) {
|
}
|
||||||
dbName= null;
|
else {
|
||||||
dbFile= null;
|
ICProject currentCOwner= (ICProject) fFileToProject.get(dbFile);
|
||||||
}
|
if (currentCOwner != null) {
|
||||||
else {
|
IProject currentOwner= currentCOwner.getProject();
|
||||||
pdom= (WritablePDOM) fProjectToPDOM.remove(currentOwner);
|
if (currentOwner.exists()) {
|
||||||
fFileToProject.remove(dbFile);
|
dbName= null;
|
||||||
|
dbFile= null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pdom= (WritablePDOM) fProjectToPDOM.remove(currentOwner);
|
||||||
|
fFileToProject.remove(dbFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -343,7 +368,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
||||||
String newid= IndexerPreferences.get(prj, IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_NO_INDEXER);
|
String newid= IndexerPreferences.get(prj, IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_NO_INDEXER);
|
||||||
Properties props= IndexerPreferences.getProperties(prj);
|
Properties props= IndexerPreferences.getProperties(prj);
|
||||||
|
|
||||||
synchronized (fIndexerMutex) {
|
synchronized (fUpdatePolicies) {
|
||||||
oldIndexer= getIndexer(cproject);
|
oldIndexer= getIndexer(cproject);
|
||||||
if (oldIndexer != null) {
|
if (oldIndexer != null) {
|
||||||
if (oldIndexer.getID().equals(newid)) {
|
if (oldIndexer.getID().equals(newid)) {
|
||||||
|
@ -354,6 +379,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
||||||
}
|
}
|
||||||
IPDOMIndexer indexer= createIndexer(cproject, newid, props);
|
IPDOMIndexer indexer= createIndexer(cproject, newid, props);
|
||||||
registerIndexer(cproject, indexer);
|
registerIndexer(cproject, indexer);
|
||||||
|
createPolicy(cproject).clearTUs();
|
||||||
enqueue(new PDOMRebuildTask(indexer));
|
enqueue(new PDOMRebuildTask(indexer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -364,41 +390,28 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerIndexer(ICProject project, IPDOMIndexer indexer) throws CoreException {
|
private void registerIndexer(ICProject project, IPDOMIndexer indexer) throws CoreException {
|
||||||
assert Thread.holdsLock(fIndexerMutex);
|
assert Thread.holdsLock(fUpdatePolicies);
|
||||||
indexer.setProject(project);
|
indexer.setProject(project);
|
||||||
registerPreferenceListener(project);
|
registerPreferenceListener(project);
|
||||||
project.getProject().setSessionProperty(indexerProperty, indexer);
|
createPolicy(project).setIndexer(indexer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IPDOMIndexer getIndexer(ICProject project) {
|
private IPDOMIndexer getIndexer(ICProject project) {
|
||||||
assert !Thread.holdsLock(fProjectToPDOM);
|
assert !Thread.holdsLock(fProjectToPDOM);
|
||||||
synchronized (fIndexerMutex) {
|
synchronized (fUpdatePolicies) {
|
||||||
IProject prj = project.getProject();
|
IndexUpdatePolicy policy= getPolicy(project);
|
||||||
if (!prj.isOpen()) {
|
if (policy != null) {
|
||||||
return null;
|
return policy.getIndexer();
|
||||||
}
|
}
|
||||||
|
|
||||||
IPDOMIndexer indexer;
|
|
||||||
try {
|
|
||||||
indexer = (IPDOMIndexer)prj.getSessionProperty(indexerProperty);
|
|
||||||
} catch (CoreException e) {
|
|
||||||
CCorePlugin.log(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (indexer != null && indexer.getProject().equals(project)) {
|
|
||||||
return indexer;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createIndexer(ICProject project, IProgressMonitor pm) {
|
private void createIndexer(ICProject project, IProgressMonitor pm) {
|
||||||
assert !Thread.holdsLock(fProjectToPDOM);
|
assert !Thread.holdsLock(fProjectToPDOM);
|
||||||
IProject prj= project.getProject();
|
IProject prj= project.getProject();
|
||||||
try {
|
try {
|
||||||
synchronized (fIndexerMutex) {
|
synchronized (fUpdatePolicies) {
|
||||||
WritablePDOM pdom= (WritablePDOM) getPDOM(project);
|
WritablePDOM pdom= (WritablePDOM) getPDOM(project);
|
||||||
Properties props= IndexerPreferences.getProperties(prj);
|
Properties props= IndexerPreferences.getProperties(prj);
|
||||||
IPDOMIndexer indexer= createIndexer(project, getIndexerId(project), props);
|
IPDOMIndexer indexer= createIndexer(project, getIndexerId(project), props);
|
||||||
|
@ -415,22 +428,27 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
||||||
}
|
}
|
||||||
if (!rebuild) {
|
if (!rebuild) {
|
||||||
registerIndexer(project, indexer);
|
registerIndexer(project, indexer);
|
||||||
|
IPDOMIndexerTask task= createPolicy(project).createTask();
|
||||||
|
if (task != null) {
|
||||||
|
enqueue(task);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// perform import
|
// rebuild is required, try import first.
|
||||||
TeamPDOMImportOperation operation= new TeamPDOMImportOperation(project);
|
TeamPDOMImportOperation operation= new TeamPDOMImportOperation(project);
|
||||||
operation.run(pm);
|
operation.run(pm);
|
||||||
|
|
||||||
synchronized (fIndexerMutex) {
|
synchronized (fUpdatePolicies) {
|
||||||
Properties props= IndexerPreferences.getProperties(prj);
|
Properties props= IndexerPreferences.getProperties(prj);
|
||||||
IPDOMIndexer indexer= createIndexer(project, getIndexerId(project), props);
|
IPDOMIndexer indexer = createIndexer(project, getIndexerId(project), props);
|
||||||
|
|
||||||
registerIndexer(project, indexer);
|
registerIndexer(project, indexer);
|
||||||
|
createPolicy(project).clearTUs();
|
||||||
|
|
||||||
IPDOMIndexerTask task= null;
|
IPDOMIndexerTask task= null;
|
||||||
if (operation.wasSuccessful()) {
|
if (operation.wasSuccessful()) {
|
||||||
task= new PDOMUpdateTask(indexer);
|
task= new PDOMUpdateTask(indexer, true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
task= new PDOMRebuildTask(indexer);
|
task= new PDOMRebuildTask(indexer);
|
||||||
|
@ -526,18 +544,16 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
||||||
return fCurrentTask == null && fTaskQueue.isEmpty();
|
return fCurrentTask == null && fTaskQueue.isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addProject(final IProject project) {
|
void addProject(final ICProject cproject) {
|
||||||
|
final IProject project = cproject.getProject();
|
||||||
Job addProject= new Job(Messages.PDOMManager_StartJob_name) {
|
Job addProject= new Job(Messages.PDOMManager_StartJob_name) {
|
||||||
protected IStatus run(IProgressMonitor monitor) {
|
protected IStatus run(IProgressMonitor monitor) {
|
||||||
monitor.beginTask("", 100); //$NON-NLS-1$
|
monitor.beginTask("", 100); //$NON-NLS-1$
|
||||||
if (project.isOpen() && CoreModel.hasCNature(project)) {
|
if (project.isOpen()) {
|
||||||
ICProject cproject= CoreModel.getDefault().create(project);
|
syncronizeProjectSettings(project, new SubProgressMonitor(monitor, 1));
|
||||||
if (cproject != null) {
|
if (getIndexer(cproject) == null) {
|
||||||
syncronizeProjectSettings(project, new SubProgressMonitor(monitor, 1));
|
createIndexer(cproject, new SubProgressMonitor(monitor, 99));
|
||||||
if (getIndexer(cproject) == null) {
|
|
||||||
createIndexer(cproject, new SubProgressMonitor(monitor, 99));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
|
@ -590,34 +606,66 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeProject(ICProject project, ICElementDelta delta) throws CoreException {
|
void changeProject(ICProject project, ICElementDelta delta) throws CoreException {
|
||||||
|
assert !Thread.holdsLock(fProjectToPDOM);
|
||||||
IPDOMIndexer indexer = getIndexer(project);
|
IPDOMIndexer indexer = getIndexer(project);
|
||||||
if (indexer != null) {
|
if (indexer != null && indexer.getID().equals(IPDOMManager.ID_NO_INDEXER)) {
|
||||||
PDOMResourceDeltaTask resourceDeltaTask = new PDOMResourceDeltaTask(indexer, delta);
|
return;
|
||||||
if (!resourceDeltaTask.isEmpty()) {
|
}
|
||||||
enqueue(resourceDeltaTask);
|
|
||||||
|
boolean allFiles= IndexerPreferences.getIndexAllFiles(project.getProject());
|
||||||
|
DeltaAnalyzer deltaAnalyzer = new DeltaAnalyzer(allFiles);
|
||||||
|
deltaAnalyzer.analyzeDelta(delta);
|
||||||
|
ITranslationUnit[] added= deltaAnalyzer.getAddedTUs();
|
||||||
|
ITranslationUnit[] changed= deltaAnalyzer.getChangedTUs();
|
||||||
|
ITranslationUnit[] removed= deltaAnalyzer.getRemovedTUs();
|
||||||
|
if (added.length > 0 || changed.length > 0 || removed.length > 0) {
|
||||||
|
synchronized (fUpdatePolicies) {
|
||||||
|
IndexUpdatePolicy policy= createPolicy(project);
|
||||||
|
IPDOMIndexerTask task= policy.addDelta(added, changed, removed);
|
||||||
|
if (task != null) {
|
||||||
|
enqueue(task);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IndexUpdatePolicy createPolicy(final ICProject project) {
|
||||||
|
assert !Thread.holdsLock(fProjectToPDOM);
|
||||||
|
synchronized (fUpdatePolicies) {
|
||||||
|
IndexUpdatePolicy policy= (IndexUpdatePolicy) fUpdatePolicies.get(project);
|
||||||
|
if (policy == null) {
|
||||||
|
policy= new IndexUpdatePolicy(project, IndexerPreferences.getUpdatePolicy(project.getProject()));
|
||||||
|
fUpdatePolicies.put(project, policy);
|
||||||
|
}
|
||||||
|
return policy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IndexUpdatePolicy getPolicy(final ICProject project) {
|
||||||
|
synchronized (fUpdatePolicies) {
|
||||||
|
return (IndexUpdatePolicy) fUpdatePolicies.get(project);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void deleteProject(ICProject cproject) {
|
public void deleteProject(ICProject cproject) {
|
||||||
removeProject(cproject, true);
|
removeProject(cproject, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closeProject(ICProject cproject) {
|
public void closeProject(ICProject cproject) {
|
||||||
removeProject(cproject, false);
|
removeProject(cproject, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removeProject(ICProject cproject, final boolean delete) {
|
||||||
private void removeProject(ICProject project, final boolean delete) {
|
assert !Thread.holdsLock(fProjectToPDOM);
|
||||||
IPDOMIndexer indexer= getIndexer(project);
|
IPDOMIndexer indexer= getIndexer(cproject);
|
||||||
if (indexer != null) {
|
if (indexer != null) {
|
||||||
stopIndexer(indexer);
|
stopIndexer(indexer);
|
||||||
}
|
}
|
||||||
unregisterPreferenceListener(project);
|
unregisterPreferenceListener(cproject);
|
||||||
WritablePDOM pdom= null;
|
WritablePDOM pdom= null;
|
||||||
synchronized (fProjectToPDOM) {
|
synchronized (fProjectToPDOM) {
|
||||||
IProject rproject= project.getProject();
|
IProject rproject= cproject.getProject();
|
||||||
pdom = (WritablePDOM) fProjectToPDOM.remove(rproject);
|
pdom = (WritablePDOM) fProjectToPDOM.remove(rproject);
|
||||||
if (pdom != null) {
|
if (pdom != null) {
|
||||||
fFileToProject.remove(pdom.getDB().getLocation());
|
fFileToProject.remove(pdom.getDB().getLocation());
|
||||||
|
@ -649,22 +697,22 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
||||||
job.setSystem(true);
|
job.setSystem(true);
|
||||||
job.schedule();
|
job.schedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
synchronized (fUpdatePolicies) {
|
||||||
|
fUpdatePolicies.remove(cproject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopIndexer(IPDOMIndexer indexer) {
|
private void stopIndexer(IPDOMIndexer indexer) {
|
||||||
|
assert !Thread.holdsLock(fProjectToPDOM);
|
||||||
ICProject project= indexer.getProject();
|
ICProject project= indexer.getProject();
|
||||||
synchronized (fIndexerMutex) {
|
synchronized (fUpdatePolicies) {
|
||||||
IProject rp= project.getProject();
|
IndexUpdatePolicy policy= getPolicy(project);
|
||||||
if (rp.isOpen()) {
|
if (policy != null) {
|
||||||
try {
|
if (policy.getIndexer() == indexer) {
|
||||||
if (rp.getSessionProperty(indexerProperty) == indexer) {
|
policy.setIndexer(null);
|
||||||
rp.setSessionProperty(indexerProperty, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (CoreException e) {
|
}
|
||||||
CCorePlugin.log(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
cancelIndexerJobs(indexer);
|
cancelIndexerJobs(indexer);
|
||||||
}
|
}
|
||||||
|
@ -683,14 +731,14 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
||||||
|
|
||||||
if (jobToCancel != null) {
|
if (jobToCancel != null) {
|
||||||
assert !Thread.holdsLock(fTaskQueueMutex);
|
assert !Thread.holdsLock(fTaskQueueMutex);
|
||||||
jobToCancel.cancelJobs(indexer);
|
jobToCancel.cancelJobs(indexer, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reindex(ICProject project) throws CoreException {
|
public void reindex(ICProject project) throws CoreException {
|
||||||
assert !Thread.holdsLock(fProjectToPDOM);
|
assert !Thread.holdsLock(fProjectToPDOM);
|
||||||
IPDOMIndexer indexer= null;
|
IPDOMIndexer indexer= null;
|
||||||
synchronized (fIndexerMutex) {
|
synchronized (fUpdatePolicies) {
|
||||||
indexer= getIndexer(project);
|
indexer= getIndexer(project);
|
||||||
}
|
}
|
||||||
// don't attempt to hold lock on indexerMutex while cancelling
|
// don't attempt to hold lock on indexerMutex while cancelling
|
||||||
|
@ -698,9 +746,10 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
||||||
cancelIndexerJobs(indexer);
|
cancelIndexerJobs(indexer);
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized(fIndexerMutex) {
|
synchronized(fUpdatePolicies) {
|
||||||
indexer= getIndexer(project);
|
indexer= getIndexer(project);
|
||||||
if (indexer != null) {
|
if (indexer != null) {
|
||||||
|
createPolicy(project).clearTUs();
|
||||||
enqueue(new PDOMRebuildTask(indexer));
|
enqueue(new PDOMRebuildTask(indexer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1127,10 +1176,9 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assert !Thread.holdsLock(fProjectToPDOM);
|
assert !Thread.holdsLock(fProjectToPDOM);
|
||||||
synchronized (fIndexerMutex) {
|
synchronized (fUpdatePolicies) {
|
||||||
IPDOMIndexer indexer= getIndexer(project);
|
IPDOMIndexer indexer= getIndexer(project);
|
||||||
PDOMUpdateTask task= new PDOMUpdateTask(indexer);
|
PDOMUpdateTask task= new PDOMUpdateTask(indexer, timestamps);
|
||||||
task.setCheckTimestamps(timestamps);
|
|
||||||
task.setTranslationUnitSelection(filesAndFolders);
|
task.setTranslationUnitSelection(filesAndFolders);
|
||||||
if (indexer != null) {
|
if (indexer != null) {
|
||||||
enqueue(task);
|
enqueue(task);
|
||||||
|
@ -1139,4 +1187,16 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void handlePostBuildEvent() {
|
||||||
|
assert !Thread.holdsLock(fProjectToPDOM);
|
||||||
|
synchronized (fUpdatePolicies) {
|
||||||
|
for (Iterator i = fUpdatePolicies.values().iterator(); i.hasNext();) {
|
||||||
|
IndexUpdatePolicy policy= (IndexUpdatePolicy) i.next();
|
||||||
|
IPDOMIndexerTask task= policy.createTask();
|
||||||
|
if (task != null) {
|
||||||
|
enqueue(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006 Symbian Software Ltd. and others.
|
* Copyright (c) 2006, 2007 Symbian Software Ltd. and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Andrew Ferguson (Symbian) - initial API and implementation
|
* Andrew Ferguson (Symbian) - initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.pdom.dom;
|
package org.eclipse.cdt.internal.core.pdom.dom;
|
||||||
|
|
||||||
|
@ -50,7 +51,7 @@ public class PDOMProjectIndexLocationConverter implements IIndexLocationConverte
|
||||||
IResource member= root.getFile(new Path(raw));
|
IResource member= root.getFile(new Path(raw));
|
||||||
uri = member.getLocationURI();
|
uri = member.getLocationURI();
|
||||||
}
|
}
|
||||||
return new IndexFileLocation(uri, fullPath);
|
return uri == null ? null : new IndexFileLocation(uri, fullPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|
|
@ -0,0 +1,98 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2007 Wind River Systems, Inc. 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:
|
||||||
|
* Markus Schorn - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
package org.eclipse.cdt.internal.core.pdom.indexer;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
|
import org.eclipse.cdt.core.model.ICContainer;
|
||||||
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
import org.eclipse.cdt.core.model.ICElementDelta;
|
||||||
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
|
|
||||||
|
public class DeltaAnalyzer {
|
||||||
|
private boolean fAllFiles;
|
||||||
|
private List fAdded= new ArrayList();
|
||||||
|
private List fChanged= new ArrayList();
|
||||||
|
private List fRemoved= new ArrayList();
|
||||||
|
|
||||||
|
public DeltaAnalyzer(boolean allFiles) {
|
||||||
|
fAllFiles= allFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void analyzeDelta(ICElementDelta delta) throws CoreException {
|
||||||
|
processDelta(delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processDelta(ICElementDelta delta) throws CoreException {
|
||||||
|
int flags = delta.getFlags();
|
||||||
|
|
||||||
|
if ((flags & ICElementDelta.F_CHILDREN) != 0) {
|
||||||
|
ICElementDelta[] children = delta.getAffectedChildren();
|
||||||
|
for (int i = 0; i < children.length; ++i) {
|
||||||
|
processDelta(children[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ICElement element = delta.getElement();
|
||||||
|
switch (element.getElementType()) {
|
||||||
|
case ICElement.C_UNIT:
|
||||||
|
ITranslationUnit tu = (ITranslationUnit)element;
|
||||||
|
if (!tu.isWorkingCopy()) {
|
||||||
|
switch (delta.getKind()) {
|
||||||
|
case ICElementDelta.CHANGED:
|
||||||
|
if ((flags & ICElementDelta.F_CONTENT) != 0) {
|
||||||
|
if (fAllFiles || !CoreModel.isScannerInformationEmpty(tu.getResource()) || tu.isHeaderUnit()) {
|
||||||
|
fChanged.add(tu);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ICElementDelta.ADDED:
|
||||||
|
if (fAllFiles || !CoreModel.isScannerInformationEmpty(tu.getResource()) || tu.isHeaderUnit()) {
|
||||||
|
fAdded.add(tu);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ICElementDelta.REMOVED:
|
||||||
|
fRemoved.add(tu);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ICElement.C_CCONTAINER:
|
||||||
|
ICContainer folder= (ICContainer) element;
|
||||||
|
if (delta.getKind() == ICElementDelta.ADDED) {
|
||||||
|
collectSources(folder, fAdded);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void collectSources(ICContainer container, Collection sources) throws CoreException {
|
||||||
|
container.accept(new TranslationUnitCollector(sources, sources, fAllFiles, new NullProgressMonitor()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ITranslationUnit[] getAddedTUs() {
|
||||||
|
return (ITranslationUnit[]) fAdded.toArray(new ITranslationUnit[fAdded.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ITranslationUnit[] getChangedTUs() {
|
||||||
|
return (ITranslationUnit[]) fChanged.toArray(new ITranslationUnit[fChanged.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ITranslationUnit[] getRemovedTUs() {
|
||||||
|
return (ITranslationUnit[]) fRemoved.toArray(new ITranslationUnit[fRemoved.size()]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,6 +19,7 @@ import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||||
import org.eclipse.cdt.internal.core.CCoreInternals;
|
import org.eclipse.cdt.internal.core.CCoreInternals;
|
||||||
import org.eclipse.cdt.internal.core.LocalProjectScope;
|
import org.eclipse.cdt.internal.core.LocalProjectScope;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.IndexUpdatePolicy;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.ProjectScope;
|
import org.eclipse.core.resources.ProjectScope;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
@ -45,14 +46,17 @@ public class IndexerPreferences {
|
||||||
public static final String KEY_FILES_TO_PARSE_UP_FRONT= "filesToParseUpFront"; //$NON-NLS-1$
|
public static final String KEY_FILES_TO_PARSE_UP_FRONT= "filesToParseUpFront"; //$NON-NLS-1$
|
||||||
public static final String KEY_SKIP_ALL_REFERENCES= "skipReferences"; //$NON-NLS-1$
|
public static final String KEY_SKIP_ALL_REFERENCES= "skipReferences"; //$NON-NLS-1$
|
||||||
public static final String KEY_SKIP_TYPE_REFERENCES= "skipTypeReferences"; //$NON-NLS-1$
|
public static final String KEY_SKIP_TYPE_REFERENCES= "skipTypeReferences"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
private static final String KEY_INDEXER_PREFS_SCOPE = "preferenceScope"; //$NON-NLS-1$
|
||||||
|
private static final String KEY_INDEX_IMPORT_LOCATION = "indexImportLocation"; //$NON-NLS-1$
|
||||||
|
private static final String KEY_UPDATE_POLICY= "updatePolicy"; //$NON-NLS-1$
|
||||||
|
|
||||||
private static final String DEFAULT_INDEX_IMPORT_LOCATION = ".settings/cdt-index.zip"; //$NON-NLS-1$
|
private static final String DEFAULT_INDEX_IMPORT_LOCATION = ".settings/cdt-index.zip"; //$NON-NLS-1$
|
||||||
private static final String DEFAULT_FILES_TO_PARSE_UP_FRONT= "stdarg.h, stddef.h, sys/types.h"; //$NON-NLS-1$
|
private static final String DEFAULT_FILES_TO_PARSE_UP_FRONT= "stdarg.h, stddef.h, sys/types.h"; //$NON-NLS-1$
|
||||||
|
private static final int DEFAULT_UPDATE_POLICY= 0;
|
||||||
|
|
||||||
private static final String QUALIFIER = CCorePlugin.PLUGIN_ID;
|
private static final String QUALIFIER = CCorePlugin.PLUGIN_ID;
|
||||||
private static final String INDEXER_NODE = "indexer"; //$NON-NLS-1$
|
private static final String INDEXER_NODE = "indexer"; //$NON-NLS-1$
|
||||||
private static final String KEY_INDEXER_PREFS_SCOPE = "preferenceScope"; //$NON-NLS-1$
|
|
||||||
private static final String KEY_INDEX_IMPORT_LOCATION = "indexImportLocation"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -344,4 +348,43 @@ public class IndexerPreferences {
|
||||||
CCoreInternals.savePreferences(project);
|
CCoreInternals.savePreferences(project);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getUpdatePolicy(IProject project) {
|
||||||
|
Preferences[] prefs;
|
||||||
|
if (project != null) {
|
||||||
|
prefs= new Preferences[] {
|
||||||
|
getProjectPreferences(project),
|
||||||
|
getInstancePreferences(),
|
||||||
|
getConfigurationPreferences(),
|
||||||
|
getDefaultPreferences()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
prefs= new Preferences[] {
|
||||||
|
getInstancePreferences(),
|
||||||
|
getConfigurationPreferences(),
|
||||||
|
getDefaultPreferences()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
String val= Platform.getPreferencesService().get(KEY_UPDATE_POLICY, null, prefs);
|
||||||
|
if (val != null) {
|
||||||
|
try {
|
||||||
|
int result= Integer.parseInt(val);
|
||||||
|
switch(result) {
|
||||||
|
case IndexUpdatePolicy.POST_CHANGE:
|
||||||
|
case IndexUpdatePolicy.POST_BUILD:
|
||||||
|
case IndexUpdatePolicy.MANUAL:
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DEFAULT_UPDATE_POLICY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean getIndexAllFiles(IProject project) {
|
||||||
|
return "true".equals(IndexerPreferences.get(project.getProject(), IndexerPreferences.KEY_INDEX_ALL_FILES, null)); //$NON-NLS-1$
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,147 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2007 Wind River Systems, Inc. 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:
|
|
||||||
* Markus Schorn - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.core.pdom.indexer;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
|
||||||
import org.eclipse.cdt.core.dom.IPDOMIndexer;
|
|
||||||
import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
|
|
||||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
|
||||||
import org.eclipse.cdt.core.model.ICContainer;
|
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
|
||||||
import org.eclipse.cdt.core.model.ICElementDelta;
|
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.IndexerProgress;
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
|
||||||
|
|
||||||
public class PDOMResourceDeltaTask implements IPDOMIndexerTask {
|
|
||||||
private static final String TRUE = String.valueOf(true);
|
|
||||||
|
|
||||||
final private IPDOMIndexer fIndexer;
|
|
||||||
final private boolean fAllFiles;
|
|
||||||
final private IPDOMIndexerTask fDelegate;
|
|
||||||
final private IndexerProgress fProgress;
|
|
||||||
|
|
||||||
private IIndex fIndex;
|
|
||||||
|
|
||||||
public PDOMResourceDeltaTask(IPDOMIndexer indexer, ICElementDelta delta) throws CoreException {
|
|
||||||
fIndexer= indexer;
|
|
||||||
fProgress= new IndexerProgress();
|
|
||||||
fAllFiles= TRUE.equals(getIndexer().getProperty(IndexerPreferences.KEY_INDEX_ALL_FILES));
|
|
||||||
if (!IPDOMManager.ID_NO_INDEXER.equals(fIndexer.getID())) {
|
|
||||||
List a= new ArrayList();
|
|
||||||
List c= new ArrayList();
|
|
||||||
List r= new ArrayList();
|
|
||||||
|
|
||||||
fIndex= CCorePlugin.getIndexManager().getIndex(indexer.getProject());
|
|
||||||
try {
|
|
||||||
fIndex.acquireReadLock();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
fDelegate= null;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
processDelta(delta, a, c, r, new NullProgressMonitor());
|
|
||||||
if (!a.isEmpty() || !c.isEmpty() || !r.isEmpty()) {
|
|
||||||
ITranslationUnit[] aa= (ITranslationUnit[]) a.toArray(new ITranslationUnit[a.size()]);
|
|
||||||
ITranslationUnit[] ca= (ITranslationUnit[]) c.toArray(new ITranslationUnit[c.size()]);
|
|
||||||
ITranslationUnit[] ra= (ITranslationUnit[]) r.toArray(new ITranslationUnit[r.size()]);
|
|
||||||
fDelegate= indexer.createTask(aa, ca, ra);
|
|
||||||
if (fDelegate instanceof PDOMIndexerTask) {
|
|
||||||
((PDOMIndexerTask) fDelegate).setCheckTimestamps(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fDelegate= null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
fIndex.releaseReadLock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fDelegate= null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void processDelta(ICElementDelta delta, List added, List changed, List removed, IProgressMonitor pm) throws CoreException {
|
|
||||||
int flags = delta.getFlags();
|
|
||||||
|
|
||||||
if ((flags & ICElementDelta.F_CHILDREN) != 0) {
|
|
||||||
ICElementDelta[] children = delta.getAffectedChildren();
|
|
||||||
for (int i = 0; i < children.length; ++i) {
|
|
||||||
processDelta(children[i], added, changed, removed, pm);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ICElement element = delta.getElement();
|
|
||||||
switch (element.getElementType()) {
|
|
||||||
case ICElement.C_UNIT:
|
|
||||||
ITranslationUnit tu = (ITranslationUnit)element;
|
|
||||||
if (!tu.isWorkingCopy()) {
|
|
||||||
switch (delta.getKind()) {
|
|
||||||
case ICElementDelta.CHANGED:
|
|
||||||
if ((flags & ICElementDelta.F_CONTENT) != 0) {
|
|
||||||
if (fAllFiles || !CoreModel.isScannerInformationEmpty(tu.getResource()) || tu.isHeaderUnit()) {
|
|
||||||
changed.add(tu);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ICElementDelta.ADDED:
|
|
||||||
if (fAllFiles || !CoreModel.isScannerInformationEmpty(tu.getResource()) || tu.isHeaderUnit()) {
|
|
||||||
added.add(tu);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ICElementDelta.REMOVED:
|
|
||||||
removed.add(tu);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ICElement.C_CCONTAINER:
|
|
||||||
ICContainer folder= (ICContainer) element;
|
|
||||||
if (delta.getKind() == ICElementDelta.ADDED) {
|
|
||||||
collectSources(folder, added, pm);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void collectSources(ICContainer container, Collection sources, IProgressMonitor pm) throws CoreException {
|
|
||||||
container.accept(new TranslationUnitCollector(sources, sources, fAllFiles, pm));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run(IProgressMonitor monitor) {
|
|
||||||
if (fDelegate != null) {
|
|
||||||
fDelegate.run(monitor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public IPDOMIndexer getIndexer() {
|
|
||||||
return fIndexer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IndexerProgress getProgressInformation() {
|
|
||||||
return fDelegate != null ? fDelegate.getProgressInformation() : fProgress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return fDelegate == null;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -34,13 +34,14 @@ public class PDOMUpdateTask implements IPDOMIndexerTask {
|
||||||
|
|
||||||
private final IPDOMIndexer fIndexer;
|
private final IPDOMIndexer fIndexer;
|
||||||
private final IndexerProgress fProgress;
|
private final IndexerProgress fProgress;
|
||||||
|
private final boolean fCheckTimestamps;
|
||||||
private volatile IPDOMIndexerTask fDelegate;
|
private volatile IPDOMIndexerTask fDelegate;
|
||||||
private boolean fCheckTimestamps= true;
|
|
||||||
private ArrayList fFilesAndFolders= null;
|
private ArrayList fFilesAndFolders= null;
|
||||||
|
|
||||||
public PDOMUpdateTask(IPDOMIndexer indexer) {
|
public PDOMUpdateTask(IPDOMIndexer indexer, boolean checkTimestamps) {
|
||||||
fIndexer= indexer;
|
fIndexer= indexer;
|
||||||
fProgress= createProgress();
|
fProgress= createProgress();
|
||||||
|
fCheckTimestamps= checkTimestamps;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IndexerProgress createProgress() {
|
private IndexerProgress createProgress() {
|
||||||
|
@ -98,10 +99,6 @@ public class PDOMUpdateTask implements IPDOMIndexerTask {
|
||||||
return fDelegate != null ? fDelegate.getProgressInformation() : fProgress;
|
return fDelegate != null ? fDelegate.getProgressInformation() : fProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCheckTimestamps(boolean timestamps) {
|
|
||||||
fCheckTimestamps= timestamps;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTranslationUnitSelection(List filesAndFolders) {
|
public void setTranslationUnitSelection(List filesAndFolders) {
|
||||||
fFilesAndFolders= new ArrayList(filesAndFolders.size());
|
fFilesAndFolders= new ArrayList(filesAndFolders.size());
|
||||||
fFilesAndFolders.addAll(filesAndFolders);
|
fFilesAndFolders.addAll(filesAndFolders);
|
||||||
|
|
|
@ -303,6 +303,8 @@ public class CCorePlugin extends Plugin {
|
||||||
*/
|
*/
|
||||||
public void stop(BundleContext context) throws Exception {
|
public void stop(BundleContext context) throws Exception {
|
||||||
try {
|
try {
|
||||||
|
pdomManager.shutdown();
|
||||||
|
|
||||||
PositionTrackerManager.getInstance().uninstall();
|
PositionTrackerManager.getInstance().uninstall();
|
||||||
|
|
||||||
// if (fDescriptorManager != null) {
|
// if (fDescriptorManager != null) {
|
||||||
|
|
|
@ -1180,6 +1180,11 @@
|
||||||
contextId="org.eclipse.cdt.ui.cEditorScope"
|
contextId="org.eclipse.cdt.ui.cEditorScope"
|
||||||
commandId="org.eclipse.cdt.ui.navigate.opentype"
|
commandId="org.eclipse.cdt.ui.navigate.opentype"
|
||||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
|
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
|
||||||
|
<key
|
||||||
|
sequence="M1+M2+T"
|
||||||
|
contextId="org.eclipse.cdt.ui.cViewScope"
|
||||||
|
commandId="org.eclipse.cdt.ui.navigate.opentype"
|
||||||
|
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
|
||||||
<key
|
<key
|
||||||
commandId="org.eclipse.cdt.ui.search.findrefs"
|
commandId="org.eclipse.cdt.ui.search.findrefs"
|
||||||
sequence="M1+M2+G"
|
sequence="M1+M2+G"
|
||||||
|
|
Loading…
Add table
Reference in a new issue