diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IWritableIndexManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IWritableIndexManager.java index bda7cfd95a0..ff7be452df5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IWritableIndexManager.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IWritableIndexManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 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 @@ -17,6 +17,9 @@ import org.eclipse.core.runtime.CoreException; public interface IWritableIndexManager extends IIndexManager { + /** + * Returns a writable index or null if the project does not exist or is not yet + * registered with the pdom manager. + */ IWritableIndex getWritableIndex(ICProject project) throws CoreException; - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMRebuildTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMRebuildTask.java index ddbb9c4b681..aa8ba589a44 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMRebuildTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMRebuildTask.java @@ -27,6 +27,7 @@ import org.eclipse.cdt.internal.core.index.IWritableIndexManager; 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.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.osgi.util.NLS; @@ -58,13 +59,19 @@ public class PDOMRebuildTask implements IPDOMIndexerTask { monitor.subTask(NLS.bind(Messages.PDOMIndexerTask_collectingFilesTask, fIndexer.getProject().getElementName())); - ICProject project= fIndexer.getProject(); - if (project.getProject().isOpen()) { + ICProject cproject= fIndexer.getProject(); + IProject project= cproject.getProject(); + if (project.isOpen() && project.exists()) { try { - clearIndex(project); - if (!IPDOMManager.ID_NO_INDEXER.equals(fIndexer.getID())) { - createDelegate(project, monitor); + IWritableIndex index= ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(cproject); + if (index != null) { + clearIndex(cproject, index); + if (!IPDOMManager.ID_NO_INDEXER.equals(fIndexer.getID())) { + createDelegate(cproject, monitor); + } } + // remove task-tags. + TodoTaskUpdater.removeTasksFor(project); } catch (CoreException e) { CCorePlugin.log(e); } catch (InterruptedException e) { @@ -76,8 +83,7 @@ public class PDOMRebuildTask implements IPDOMIndexerTask { } } - private void clearIndex(ICProject project) throws CoreException, InterruptedException { - IWritableIndex index= ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(project); + private void clearIndex(ICProject project, IWritableIndex index) throws CoreException, InterruptedException { // First clear the pdom index.acquireWriteLock(0); try { @@ -90,8 +96,6 @@ public class PDOMRebuildTask implements IPDOMIndexerTask { finally { index.releaseWriteLock(0); } - // remove task-tags. - TodoTaskUpdater.removeTasksFor(project.getProject()); } private synchronized void createDelegate(ICProject project, IProgressMonitor monitor) throws CoreException { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerTask.java index ce8cd92671c..ffb1ee84885 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerTask.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation - * Markus Schorn (Wind River Systems) + * QNX - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.indexer.fast; @@ -79,7 +79,9 @@ class PDOMFastIndexerTask extends PDOMIndexerTask implements CallbackHandler { } } - setupIndexAndReaderFactory(); + if (!setupIndexAndReaderFactory()) { + return; + } fIndex.acquireReadLock(); try { registerTUsInReaderFactory(sources); @@ -114,12 +116,16 @@ class PDOMFastIndexerTask extends PDOMIndexerTask implements CallbackHandler { traceEnd(start, fIndex); } - private void setupIndexAndReaderFactory() throws CoreException { + private boolean setupIndexAndReaderFactory() throws CoreException { fIndex= ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(getProject()); + if (fIndex == null) { + return false; + } fIndex.resetCacheCounters(); fIflCache = new HashMap/**/(); fCodeReaderFactory = new IndexBasedCodeReaderFactory(getCProject(), fIndex, fIflCache); fCodeReaderFactory.setCallbackHandler(this); + return true; } private void registerTUsInReaderFactory(Collection tus) throws CoreException { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerTask.java index 04a4482638b..e794cc181ac 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerTask.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation - * Markus Schorn (Wind River Systems) + * QNX - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.indexer.full; @@ -86,10 +86,12 @@ class PDOMFullIndexerTask extends PDOMIndexerTask { } } - setupIndex(); + if (!setupIndex()) { + return; + } registerTUsInReaderFactory(sources); registerTUsInReaderFactory(headers); - + Iterator i= fRemoved.iterator(); while (i.hasNext()) { if (monitor.isCanceled()) @@ -118,12 +120,16 @@ class PDOMFullIndexerTask extends PDOMIndexerTask { traceEnd(start, fIndex); } - private void setupIndex() throws CoreException { + private boolean setupIndex() throws CoreException { // there is no mechanism to clear dirty files from the cache, so flush it. SavedCodeReaderFactory.getInstance().getCodeReaderCache().flush(); fIndex = ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(getProject()); + if (fIndex == null) { + return false; + } fIndex.resetCacheCounters(); + return true; } private void registerTUsInReaderFactory(Collection/**/ sources)