Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2008-02-27 10:48:53 +0000
committerMarkus Schorn2008-02-27 10:48:53 +0000
commit8c248ed68bc4382fe6413b58a1391af74a0e1f90 (patch)
tree1f7a7a65111bf4486332c1a05ce8fcc48266223f /core/org.eclipse.cdt.core/parser
parent41becf515a33358e154a13fcba1f6eb0e7920e28 (diff)
downloadorg.eclipse.cdt-8c248ed68bc4382fe6413b58a1391af74a0e1f90.tar.gz
org.eclipse.cdt-8c248ed68bc4382fe6413b58a1391af74a0e1f90.tar.xz
org.eclipse.cdt-8c248ed68bc4382fe6413b58a1391af74a0e1f90.zip
LabelProvider to decorate indexed files, bug 159731.
Diffstat (limited to 'core/org.eclipse.cdt.core/parser')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexChangeEvent.java30
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexerStateEvent.java6
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexChangeEvent.java31
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/JobChangeListener.java53
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java79
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java100
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMProxy.java5
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/WritablePDOM.java9
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java19
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/TriggerNotificationTask.java11
10 files changed, 229 insertions, 114 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexChangeEvent.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexChangeEvent.java
index 2819ffe2ee9..5a4e5806150 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexChangeEvent.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexChangeEvent.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Wind River Systems, Inc. and others.
+ * Copyright (c) 2006, 2008 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
@@ -8,13 +8,14 @@
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
-
package org.eclipse.cdt.core.index;
+import java.util.Set;
+
import org.eclipse.cdt.core.model.ICProject;
/**
- * IndexChangeEvents descrive changes to the index.
+ * IndexChangeEvents describe changes to the index.
* <p>
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
* part of a work in progress. There is no guarantee that this API will work or
@@ -30,4 +31,27 @@ public interface IIndexChangeEvent {
* Returns the project for which the index has changed.
*/
public ICProject getAffectedProject();
+
+ /**
+ * Returns <code>true</code> when the index for the project was loaded for the first time or
+ * reloaded with a different database.
+ */
+ public boolean isReloaded();
+
+ /**
+ * Returns <code>true</code> when the index for the project was cleared.
+ */
+ public boolean isCleared();
+
+ /**
+ * Returns the set of files that has been cleared in the index. When {@link #isCleared()}
+ * returns <code>true</code>, the set will be empty.
+ */
+ public Set<IIndexFileLocation> getFilesCleared();
+
+ /**
+ * Returns the set of files that has been added or updated. When {@link #isCleared()} returns
+ * <code>true</code>, the files of the set have been written after the index was cleared.
+ */
+ public Set<IIndexFileLocation> getFilesWritten();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexerStateEvent.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexerStateEvent.java
index 9543dab11e8..23f8da3ef96 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexerStateEvent.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexerStateEvent.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Wind River Systems, Inc. and others.
+ * Copyright (c) 2006, 2008 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
@@ -8,12 +8,10 @@
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
-
package org.eclipse.cdt.core.index;
-
/**
- * IndexChangeEvents descrive changes to the state of the indexer.
+ * IndexChangeEvents describe changes to the state of the indexer.
* <p>
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
* part of a work in progress. There is no guarantee that this API will work or
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexChangeEvent.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexChangeEvent.java
index e508e463e5b..31db4631674 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexChangeEvent.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexChangeEvent.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Wind River Systems, Inc. and others.
+ * Copyright (c) 2006, 2008 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
@@ -8,29 +8,52 @@
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
-
package org.eclipse.cdt.internal.core.index;
+import java.util.Set;
+
import org.eclipse.cdt.core.index.IIndexChangeEvent;
+import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.internal.core.pdom.PDOM.ChangeEvent;
public class IndexChangeEvent implements IIndexChangeEvent {
private ICProject fAffectedProject;
+ private ChangeEvent fChangeEvent;
- public IndexChangeEvent(ICProject projectChanged) {
+ public IndexChangeEvent(ICProject projectChanged, ChangeEvent e) {
fAffectedProject= projectChanged;
+ fChangeEvent= e;
}
public IndexChangeEvent() {
fAffectedProject= null;
+ fChangeEvent= new ChangeEvent();
}
public ICProject getAffectedProject() {
return fAffectedProject;
}
- public void setAffectedProject(ICProject project) {
+ public void setAffectedProject(ICProject project, ChangeEvent e) {
fAffectedProject= project;
+ fChangeEvent= e;
+ }
+
+ public Set<IIndexFileLocation> getFilesCleared() {
+ return fChangeEvent.fClearedFiles;
+ }
+
+ public Set<IIndexFileLocation> getFilesWritten() {
+ return fChangeEvent.fFilesWritten;
+ }
+
+ public boolean isCleared() {
+ return fChangeEvent.fCleared;
+ }
+
+ public boolean isReloaded() {
+ return fChangeEvent.fReloaded;
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/JobChangeListener.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/JobChangeListener.java
new file mode 100644
index 00000000000..73718480512
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/JobChangeListener.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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 org.eclipse.cdt.internal.core.index.IndexerStateEvent;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.IJobChangeListener;
+import org.eclipse.core.runtime.jobs.Job;
+
+/**
+ * Notifies clients of the indexer state.
+ */
+class JobChangeListener implements IJobChangeListener {
+ private final PDOMManager fPDomManager;
+
+ JobChangeListener(PDOMManager pdomManager) {
+ fPDomManager= pdomManager;
+ }
+
+ public void aboutToRun(IJobChangeEvent event) {
+ }
+
+ public void awake(IJobChangeEvent event) {
+ }
+
+ public void done(IJobChangeEvent event) {
+ if (event.getJob().belongsTo(fPDomManager)) {
+ if (Job.getJobManager().find(fPDomManager).length == 0) {
+ fPDomManager.fireStateChange(IndexerStateEvent.STATE_IDLE);
+ }
+ }
+ }
+
+ public void running(IJobChangeEvent event) {
+ }
+
+ public void scheduled(IJobChangeEvent event) {
+ if (event.getJob().belongsTo(fPDomManager)) {
+ fPDomManager.fireStateChange(IndexerStateEvent.STATE_BUSY);
+ }
+ }
+ public void sleeping(IJobChangeEvent event) {
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java
index 79b9a39c3ed..e35b0797f71 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java
@@ -20,15 +20,16 @@ import java.util.Arrays;
import java.util.BitSet;
import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.regex.Pattern;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ILinkage;
-import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.DOMException;
@@ -45,7 +46,6 @@ import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexLinkage;
import org.eclipse.cdt.core.index.IIndexLocationConverter;
import org.eclipse.cdt.core.index.IIndexMacro;
-import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants;
import org.eclipse.cdt.internal.core.index.IIndexFragment;
@@ -168,6 +168,30 @@ public class PDOM extends PlatformObject implements IPDOM {
assert END <= Database.CHUNK_SIZE;
}
+ public static class ChangeEvent {
+ public Set<IIndexFileLocation> fClearedFiles= new HashSet<IIndexFileLocation>();
+ public Set<IIndexFileLocation> fFilesWritten= new HashSet<IIndexFileLocation>();
+ public boolean fCleared= false;
+ public boolean fReloaded= false;
+
+ private void setCleared() {
+ fReloaded= false;
+ fCleared= true;
+ fClearedFiles.clear();
+ fFilesWritten.clear();
+ }
+
+ public void clear() {
+ fReloaded= fCleared= false;
+ fClearedFiles.clear();
+ fFilesWritten.clear();
+ }
+ }
+ public static interface IListener {
+ public void handleChange(PDOM pdom, ChangeEvent event);
+ }
+
+
// Local caches
protected Database db;
private BTree fileIndex;
@@ -177,8 +201,9 @@ public class PDOM extends PlatformObject implements IPDOM {
private IIndexLocationConverter locationConverter;
private Map<String, IPDOMLinkageFactory> fPDOMLinkageFactoryCache;
private HashMap<Object, Object> fResultCache= new HashMap<Object, Object>();
+ private List<IListener> listeners;
+ protected ChangeEvent fEvent= new ChangeEvent();
-
public PDOM(File dbPath, IIndexLocationConverter locationConverter, Map<String, IPDOMLinkageFactory> linkageFactoryMappings) throws CoreException {
this(dbPath, locationConverter, ChunkCache.getSharedInstance(), linkageFactoryMappings);
}
@@ -231,12 +256,6 @@ public class PDOM extends PlatformObject implements IPDOM {
}
}
- public static interface IListener {
- public void handleChange(PDOM pdom);
- }
-
- private List<IListener> listeners;
-
public void addListener(IListener listener) {
if (listeners == null)
listeners = new LinkedList<IListener>();
@@ -249,12 +268,12 @@ public class PDOM extends PlatformObject implements IPDOM {
listeners.remove(listener);
}
- private void fireChange() {
+ private void fireChange(ChangeEvent event) {
if (listeners == null)
return;
Iterator<IListener> i = listeners.iterator();
while (i.hasNext())
- i.next().handleChange(this);
+ i.next().handleChange(this, event);
}
public Database getDB() {
@@ -311,6 +330,7 @@ public class PDOM extends PlatformObject implements IPDOM {
// Clear out the database, everything is set to zero.
db.clear(CURRENT_VERSION);
clearCaches();
+ fEvent.setCleared();
}
void reloadFromFile(File file) throws CoreException {
@@ -325,42 +345,13 @@ public class PDOM extends PlatformObject implements IPDOM {
loadDatabase(file, db.getChunkCache());
db.setExclusiveLock();
oldFile.delete();
+ fEvent.fReloaded= true;
}
public boolean isEmpty() throws CoreException {
return getFirstLinkageRecord() == 0;
}
- /**
- * @deprecated use findDefinitions() instead
- */
- public IName[] getDefinitions(IBinding binding) throws CoreException {
- if (binding instanceof PDOMBinding) {
- List<PDOMName> names = new ArrayList<PDOMName>();
- for (PDOMName name = ((PDOMBinding)binding).getFirstDefinition();
- name != null;
- name = name.getNextInBinding())
- names.add(name);
- return names.toArray(new IIndexName[names.size()]);
- }
- return IIndexFragmentName.EMPTY_NAME_ARRAY;
- }
-
- /**
- * @deprecated use findReferences() instead
- */
- public IName[] getReferences(IBinding binding) throws CoreException {
- if (binding instanceof PDOMBinding) {
- List<PDOMName> names = new ArrayList<PDOMName>();
- for (PDOMName name = ((PDOMBinding)binding).getFirstReference();
- name != null;
- name = name.getNextInBinding())
- names.add(name);
- return names.toArray(new IIndexName[names.size()]);
- }
- return IIndexFragmentName.EMPTY_NAME_ARRAY;
- }
-
public IIndexFragmentBinding findBinding(IASTName name) throws CoreException {
PDOMLinkage linkage= adaptLinkage(name.getLinkage());
if (linkage != null) {
@@ -669,13 +660,15 @@ public class PDOM extends PlatformObject implements IPDOM {
}
assert lockCount == -1;
lastWriteAccess= System.currentTimeMillis();
+ final ChangeEvent event= fEvent;
+ fEvent= new ChangeEvent();
synchronized (mutex) {
if (lockCount < 0)
lockCount= establishReadLocks;
mutex.notifyAll();
db.setLocked(lockCount != 0);
}
- fireChange();
+ fireChange(event);
}
@@ -932,6 +925,7 @@ public class PDOM extends PlatformObject implements IPDOM {
IndexFilter filter= null;
if (binding instanceof IFunction) {
filter= new IndexFilter() {
+ @Override
public boolean acceptBinding(IBinding binding) {
try {
if (binding instanceof ICPPFunction) {
@@ -945,6 +939,7 @@ public class PDOM extends PlatformObject implements IPDOM {
} else if (binding instanceof IVariable) {
if (!(binding instanceof IField) && !(binding instanceof IParameter)) {
filter= new IndexFilter() {
+ @Override
public boolean acceptBinding(IBinding binding) {
try {
if (binding instanceof ICPPVariable) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java
index 077149d3221..94c85b8e71b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java
@@ -143,12 +143,11 @@ public class PDOMManager implements IWritableIndexManager, IListener {
private static final ISchedulingRule INIT_INDEXER_SCHEDULING_RULE = new PerInstanceSchedulingRule();
/**
- * Protects indexerJob, currentTask and taskQueue.
+ * Protects fIndexerJob, fCurrentTask and fTaskQueue.
*/
- private Object fTaskQueueMutex = new Object();
+ private final LinkedList<IPDOMIndexerTask> fTaskQueue = new LinkedList<IPDOMIndexerTask>();
private PDOMIndexerJob fIndexerJob;
private IPDOMIndexerTask fCurrentTask;
- private LinkedList<IPDOMIndexerTask> fTaskQueue = new LinkedList<IPDOMIndexerTask>();
private int fSourceCount, fHeaderCount, fTickCount;
/**
@@ -165,6 +164,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
private CModelListener fCModelListener= new CModelListener(this);
private ILanguageMappingChangeListener fLanguageChangeListener = new LanguageMappingChangeListener(this);
private final ICProjectDescriptionListener fProjectDescriptionListener;
+ private final JobChangeListener fJobChangeListener;
private IndexFactory fIndexFactory= new IndexFactory(this);
private IndexProviderManager fIndexProviderManager = new IndexProviderManager();
@@ -178,9 +178,11 @@ public class PDOMManager implements IWritableIndexManager, IListener {
private HashMap<IProject, PCL> fPrefListeners= new HashMap<IProject, PCL>();
private ArrayList<IndexerSetupParticipant> fSetupParticipants= new ArrayList<IndexerSetupParticipant>();
private HashSet<ICProject> fPostponedProjects= new HashSet<ICProject>();
+ private int fLastNotifiedState= IndexerStateEvent.STATE_IDLE;
public PDOMManager() {
fProjectDescriptionListener= new CProjectDescriptionListener(this);
+ fJobChangeListener= new JobChangeListener(this);
}
public Job startup() {
@@ -207,7 +209,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
// order to avoid a race condition where its not noticed
// that new projects are being created
initializeDatabaseCache();
-
+ Job.getJobManager().addJobChangeListener(fJobChangeListener);
fIndexProviderManager.startup();
final CoreModel model = CoreModel.getDefault();
@@ -234,15 +236,16 @@ public class PDOMManager implements IWritableIndexManager, IListener {
ResourcesPlugin.getWorkspace().removeResourceChangeListener(fCModelListener);
LanguageManager.getInstance().unregisterLanguageChangeListener(fLanguageChangeListener);
PDOMIndexerJob jobToCancel= null;
- synchronized (fTaskQueueMutex) {
+ synchronized (fTaskQueue) {
fTaskQueue.clear();
jobToCancel= fIndexerJob;
}
if (jobToCancel != null) {
- assert !Thread.holdsLock(fTaskQueueMutex);
+ assert !Thread.holdsLock(fTaskQueue);
jobToCancel.cancelJobs(null, false);
}
+ Job.getJobManager().removeJobChangeListener(fJobChangeListener);
}
private void initializeDatabaseCache() {
@@ -589,7 +592,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
if (indexer != null) {
getReferencingProjects(indexer.getProject().getProject(), referencing);
}
- synchronized (fTaskQueueMutex) {
+ synchronized (fTaskQueue) {
int i=0;
for (Iterator<IPDOMIndexerTask> it = fTaskQueue.iterator(); it.hasNext();) {
final IPDOMIndexerTask task= it.next();
@@ -608,7 +611,6 @@ public class PDOMManager implements IWritableIndexManager, IListener {
fIndexerJob = new PDOMIndexerJob(this);
fIndexerJob.setRule(INDEXER_SCHEDULING_RULE);
fIndexerJob.schedule();
- notifyState(IndexerStateEvent.STATE_BUSY);
}
}
}
@@ -626,11 +628,10 @@ public class PDOMManager implements IWritableIndexManager, IListener {
IPDOMIndexerTask getNextTask() {
IPDOMIndexerTask result= null;
- synchronized (fTaskQueueMutex) {
+ synchronized (fTaskQueue) {
if (fTaskQueue.isEmpty()) {
fCurrentTask= null;
fIndexerJob= null;
- notifyState(IndexerStateEvent.STATE_IDLE);
}
else {
if (fCurrentTask != null) {
@@ -647,14 +648,13 @@ public class PDOMManager implements IWritableIndexManager, IListener {
}
void cancelledJob(boolean byManager) {
- synchronized (fTaskQueueMutex) {
+ synchronized (fTaskQueue) {
fCurrentTask= null;
if (!byManager) {
fTaskQueue.clear();
}
if (fTaskQueue.isEmpty()) {
fIndexerJob= null;
- notifyState(IndexerStateEvent.STATE_IDLE);
}
else {
fIndexerJob = new PDOMIndexerJob(this);
@@ -857,7 +857,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
private void cancelIndexerJobs(IPDOMIndexer indexer) {
PDOMIndexerJob jobToCancel= null;
- synchronized (fTaskQueueMutex) {
+ synchronized (fTaskQueue) {
for (Iterator<IPDOMIndexerTask> iter = fTaskQueue.iterator(); iter.hasNext();) {
IPDOMIndexerTask task= iter.next();
if (task.getIndexer() == indexer) {
@@ -868,7 +868,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
}
if (jobToCancel != null) {
- assert !Thread.holdsLock(fTaskQueueMutex);
+ assert !Thread.holdsLock(fTaskQueue);
jobToCancel.cancelJobs(indexer, true);
}
}
@@ -922,43 +922,43 @@ public class PDOMManager implements IWritableIndexManager, IListener {
fStateListeners.remove(listener);
}
- private void notifyState(final int state) {
- if (state == IndexerStateEvent.STATE_IDLE) {
- synchronized(fTaskQueueMutex) {
- fTaskQueueMutex.notifyAll();
+ void fireStateChange(final int state) {
+ synchronized(fStateListeners) {
+ if (fLastNotifiedState == state) {
+ return;
}
- }
-
- if (fStateListeners.isEmpty()) {
- return;
- }
- Job notify= new Job(Messages.PDOMManager_notifyJob_label) {
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- fIndexerStateEvent.setState(state);
- Object[] listeners= fStateListeners.getListeners();
- monitor.beginTask(Messages.PDOMManager_notifyTask_message, listeners.length);
- for (int i = 0; i < listeners.length; i++) {
- final IIndexerStateListener listener = (IIndexerStateListener) listeners[i];
- SafeRunner.run(new ISafeRunnable(){
- public void handleException(Throwable exception) {
- CCorePlugin.log(exception);
- }
- public void run() throws Exception {
- listener.indexChanged(fIndexerStateEvent);
- }
- });
- monitor.worked(1);
- }
- return Status.OK_STATUS;
+ fLastNotifiedState= state;
+ if (fStateListeners.isEmpty()) {
+ return;
}
- };
- notify.setRule(NOTIFICATION_SCHEDULING_RULE);
- notify.setSystem(true);
- notify.schedule();
+ Job notify= new Job(Messages.PDOMManager_notifyJob_label) {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ fIndexerStateEvent.setState(state);
+ Object[] listeners= fStateListeners.getListeners();
+ monitor.beginTask(Messages.PDOMManager_notifyTask_message, listeners.length);
+ for (int i = 0; i < listeners.length; i++) {
+ final IIndexerStateListener listener = (IIndexerStateListener) listeners[i];
+ SafeRunner.run(new ISafeRunnable(){
+ public void handleException(Throwable exception) {
+ CCorePlugin.log(exception);
+ }
+ public void run() throws Exception {
+ listener.indexChanged(fIndexerStateEvent);
+ }
+ });
+ monitor.worked(1);
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ notify.setRule(NOTIFICATION_SCHEDULING_RULE);
+ notify.setSystem(true);
+ notify.schedule();
+ }
}
- public void handleChange(PDOM pdom) {
+ public void handleChange(PDOM pdom, final PDOM.ChangeEvent e) {
if (fChangeListeners.isEmpty()) {
return;
}
@@ -973,7 +973,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
Job notify= new Job(Messages.PDOMManager_notifyJob_label) {
@Override
protected IStatus run(IProgressMonitor monitor) {
- fIndexChangeEvent.setAffectedProject(finalProject);
+ fIndexChangeEvent.setAffectedProject(finalProject, e);
Object[] listeners= fChangeListeners.getListeners();
monitor.beginTask(Messages.PDOMManager_notifyTask_message, listeners.length);
for (int i = 0; i < listeners.length; i++) {
@@ -1032,11 +1032,11 @@ public class PDOMManager implements IWritableIndexManager, IListener {
}
int getMonitorMessage(IProgressMonitor monitor, int currentTicks, int base) {
- assert !Thread.holdsLock(fTaskQueueMutex);
+ assert !Thread.holdsLock(fTaskQueue);
int sourceCount, sourceEstimate, headerCount, tickCount, tickEstimate;
String detail= null;
- synchronized (fTaskQueueMutex) {
+ synchronized (fTaskQueue) {
// add historic data
sourceCount= sourceEstimate= fSourceCount;
headerCount= fHeaderCount;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMProxy.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMProxy.java
index 9dd5700c700..3c33b386b54 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMProxy.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMProxy.java
@@ -26,6 +26,7 @@ import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFileSet;
import org.eclipse.cdt.internal.core.index.IIndexFragmentInclude;
import org.eclipse.cdt.internal.core.index.IIndexFragmentName;
+import org.eclipse.cdt.internal.core.pdom.PDOM.ChangeEvent;
import org.eclipse.cdt.internal.core.pdom.PDOM.IListener;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.core.runtime.CoreException;
@@ -214,9 +215,11 @@ public class PDOMProxy implements IPDOM {
catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
+ ChangeEvent event= new ChangeEvent();
+ event.fReloaded= true;
for (Iterator<IListener> iterator = fListeners.iterator(); iterator.hasNext();) {
IListener listener = iterator.next();
- listener.handleChange(fDelegate);
+ listener.handleChange(fDelegate, event);
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/WritablePDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/WritablePDOM.java
index ccdc925d16f..ebac516694c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/WritablePDOM.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/WritablePDOM.java
@@ -9,7 +9,6 @@
* Markus Schorn - initial API and implementation
* Andrew Ferguson (Symbian)
*******************************************************************************/
-
package org.eclipse.cdt.internal.core.pdom;
import java.io.File;
@@ -75,11 +74,17 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
finally {
fPathResolver= origResolver;
}
+
+ final IIndexFileLocation location = pdomFile.getLocation();
+ fEvent.fClearedFiles.remove(location);
+ fEvent.fFilesWritten.add(location);
}
public void clearFile(IIndexFragmentFile file, Collection<IIndexFileLocation> contextsRemoved) throws CoreException {
assert file.getIndexFragment() == this;
- ((PDOMFile) file).clear(contextsRemoved);
+ ((PDOMFile) file).clear(contextsRemoved);
+
+ fEvent.fClearedFiles.add(file.getLocation());
}
@Override
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java
index 7e3f765d90c..0bd4595e8ce 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java
@@ -52,6 +52,7 @@ import org.eclipse.core.runtime.CoreException;
public class PDOMFile implements IIndexFragmentFile {
private final PDOM pdom;
private final int record;
+ private IIndexFileLocation location;
private static final int FIRST_NAME = 0;
private static final int FIRST_INCLUDE = 4;
@@ -90,6 +91,7 @@ public class PDOMFile implements IIndexFragmentFile {
public PDOMFile(PDOM pdom, IIndexFileLocation location, int linkageID) throws CoreException {
this.pdom = pdom;
+ this.location= location;
Database db = pdom.getDB();
record = db.malloc(RECORD_SIZE);
String locationString = pdom.getLocationConverter().toInternalFormat(location);
@@ -109,6 +111,7 @@ public class PDOMFile implements IIndexFragmentFile {
return record;
}
+ @Override
public boolean equals(Object obj) {
if (obj == this)
return true;
@@ -119,6 +122,7 @@ public class PDOMFile implements IIndexFragmentFile {
return false;
}
+ @Override
public final int hashCode() {
return System.identityHashCode(pdom) + 41*record;
}
@@ -135,6 +139,7 @@ public class PDOMFile implements IIndexFragmentFile {
int oldRecord = db.getInt(record + LOCATION_REPRESENTATION);
db.free(oldRecord);
db.putInt(record + LOCATION_REPRESENTATION, db.newString(internalLocation).getRecord());
+ location= null;
}
public int getLinkageID() throws CoreException {
@@ -491,12 +496,14 @@ public class PDOMFile implements IIndexFragmentFile {
}
public IIndexFileLocation getLocation() throws CoreException {
- Database db = pdom.getDB();
- String raw = db.getString(db.getInt(record + LOCATION_REPRESENTATION)).getString();
- IIndexFileLocation result = pdom.getLocationConverter().fromInternalFormat(raw);
- if(result==null)
- throw new CoreException(CCorePlugin.createStatus(Messages.getString("PDOMFile.toExternalProblem")+raw)); //$NON-NLS-1$
- return result;
+ if (location == null) {
+ Database db = pdom.getDB();
+ String raw = db.getString(db.getInt(record + LOCATION_REPRESENTATION)).getString();
+ location= pdom.getLocationConverter().fromInternalFormat(raw);
+ if(location==null)
+ throw new CoreException(CCorePlugin.createStatus(Messages.getString("PDOMFile.toExternalProblem")+raw)); //$NON-NLS-1$
+ }
+ return location;
}
public boolean hasContent() throws CoreException {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/TriggerNotificationTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/TriggerNotificationTask.java
index d7b7d9eb101..b97cd66487d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/TriggerNotificationTask.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/TriggerNotificationTask.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 2008 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
@@ -15,8 +15,13 @@ import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
import org.eclipse.cdt.internal.core.pdom.IndexerProgress;
import org.eclipse.cdt.internal.core.pdom.PDOMManager;
import org.eclipse.cdt.internal.core.pdom.WritablePDOM;
+import org.eclipse.cdt.internal.core.pdom.PDOM.ChangeEvent;
import org.eclipse.core.runtime.IProgressMonitor;
+/**
+ * Used to trigger a change notification when a pdom is loaded.
+ * In this situation the pdom itself does not generate a notification.
+ */
public class TriggerNotificationTask implements IPDOMIndexerTask {
private WritablePDOM fPDOM;
@@ -36,6 +41,8 @@ public class TriggerNotificationTask implements IPDOMIndexerTask {
}
public void run(IProgressMonitor monitor) {
- fManager.handleChange(fPDOM);
+ ChangeEvent event= new ChangeEvent();
+ event.fReloaded= true;
+ fManager.handleChange(fPDOM, event);
}
}

Back to the top