From 7831aed88db84652d9061b0858861ca986c74b5f Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Wed, 9 Jul 2008 11:53:30 +0000 Subject: [PATCH] Allow to update external translation units, bug 237991. --- .../cdt/internal/core/pdom/PDOMManager.java | 2 ++ .../core/pdom/indexer/PDOMUpdateTask.java | 35 ++++++++++++++++++- .../ui/actions/FreshenIndexAction.java | 7 ++-- .../UpdateIndexWithModifiedFilesAction.java | 7 ++-- 4 files changed, 44 insertions(+), 7 deletions(-) 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 792edac363f..9e04291be40 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 @@ -145,6 +145,8 @@ public class PDOMManager implements IWritableIndexManager, IListener { } } + public static final int UPDATE_EXTERNAL_FILES_FOR_PROJECT = 0x10000; // must not collide with IIndexManager.UPDATE... + 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$ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMUpdateTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMUpdateTask.java index 59f4a15896a..9f0ec8493b5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMUpdateTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMUpdateTask.java @@ -18,11 +18,18 @@ 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.index.IIndexFile; +import org.eclipse.cdt.core.index.IIndexFileLocation; +import org.eclipse.cdt.core.index.IndexLocationFactory; +import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.internal.core.pdom.IndexerProgress; +import org.eclipse.cdt.internal.core.pdom.PDOMManager; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.osgi.util.NLS; @@ -75,17 +82,43 @@ public class PDOMUpdateTask implements IPDOMIndexerTask { } } - private void createDelegate(ICProject project, IProgressMonitor monitor) throws CoreException { + private void createDelegate(ICProject project, IProgressMonitor monitor) throws CoreException, InterruptedException { HashSet set= new HashSet(); TranslationUnitCollector collector= new TranslationUnitCollector(set, set, monitor); + boolean haveProject= false; if (fFilesAndFolders == null) { project.accept(collector); } else { for (ICElement elem : fFilesAndFolders) { + if (elem.getElementType() == ICElement.C_PROJECT) { + haveProject= true; + } elem.accept(collector); } } + if (haveProject && (fUpdateOptions & PDOMManager.UPDATE_EXTERNAL_FILES_FOR_PROJECT) != 0) { + IIndex index= CCorePlugin.getIndexManager().getIndex(project); + index.acquireReadLock(); + try { + IIndexFile[] files= index.getAllFiles(); + for (IIndexFile indexFile : files) { + IIndexFileLocation floc= indexFile.getLocation(); + if (floc.getFullPath() == null) { + IPath path= IndexLocationFactory.getPath(floc); + if (path != null) { + ITranslationUnit tu= CoreModel.getDefault().createTranslationUnitFrom(project, path); + if (tu != null) { + set.add(tu); + } + } + } + } + + } finally { + index.releaseReadLock(); + } + } ITranslationUnit[] tus= set.toArray(new ITranslationUnit[set.size()]); IPDOMIndexerTask delegate= fIndexer.createTask(NO_TUS, tus, NO_TUS); if (delegate instanceof PDOMIndexerTask) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/FreshenIndexAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/FreshenIndexAction.java index c2bb33fb2e2..511484e59f5 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/FreshenIndexAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/FreshenIndexAction.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 @@ -8,15 +8,16 @@ * Contributors: * Markus Schorn - initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.internal.ui.actions; import org.eclipse.cdt.core.index.IIndexManager; +import org.eclipse.cdt.internal.core.pdom.PDOMManager; + public class FreshenIndexAction extends AbstractUpdateIndexAction { @Override protected int getUpdateOptions() { - return IIndexManager.UPDATE_ALL; + return IIndexManager.UPDATE_ALL | PDOMManager.UPDATE_EXTERNAL_FILES_FOR_PROJECT; } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/UpdateIndexWithModifiedFilesAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/UpdateIndexWithModifiedFilesAction.java index d556a25674f..122c4c655f5 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/UpdateIndexWithModifiedFilesAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/UpdateIndexWithModifiedFilesAction.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 @@ -8,15 +8,16 @@ * Contributors: * Markus Schorn - initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.internal.ui.actions; import org.eclipse.cdt.core.index.IIndexManager; +import org.eclipse.cdt.internal.core.pdom.PDOMManager; + public class UpdateIndexWithModifiedFilesAction extends AbstractUpdateIndexAction { @Override protected int getUpdateOptions() { - return IIndexManager.UPDATE_CHECK_TIMESTAMPS | IIndexManager.UPDATE_CHECK_CONFIGURATION; + return IIndexManager.UPDATE_CHECK_TIMESTAMPS | IIndexManager.UPDATE_CHECK_CONFIGURATION | PDOMManager.UPDATE_EXTERNAL_FILES_FOR_PROJECT; } }