1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +02:00

Allow to update external translation units, bug 237991.

This commit is contained in:
Markus Schorn 2008-07-09 11:53:30 +00:00
parent 51c06fe8cc
commit 7831aed88d
4 changed files with 44 additions and 7 deletions

View file

@ -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 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$

View file

@ -18,11 +18,18 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMIndexer; import org.eclipse.cdt.core.dom.IPDOMIndexer;
import org.eclipse.cdt.core.dom.IPDOMIndexerTask; import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
import org.eclipse.cdt.core.dom.IPDOMManager; 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.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.core.pdom.IndexerProgress; 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.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.osgi.util.NLS; 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<ITranslationUnit> set= new HashSet<ITranslationUnit>(); HashSet<ITranslationUnit> set= new HashSet<ITranslationUnit>();
TranslationUnitCollector collector= new TranslationUnitCollector(set, set, monitor); TranslationUnitCollector collector= new TranslationUnitCollector(set, set, monitor);
boolean haveProject= false;
if (fFilesAndFolders == null) { if (fFilesAndFolders == null) {
project.accept(collector); project.accept(collector);
} }
else { else {
for (ICElement elem : fFilesAndFolders) { for (ICElement elem : fFilesAndFolders) {
if (elem.getElementType() == ICElement.C_PROJECT) {
haveProject= true;
}
elem.accept(collector); 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()]); ITranslationUnit[] tus= set.toArray(new ITranslationUnit[set.size()]);
IPDOMIndexerTask delegate= fIndexer.createTask(NO_TUS, tus, NO_TUS); IPDOMIndexerTask delegate= fIndexer.createTask(NO_TUS, tus, NO_TUS);
if (delegate instanceof PDOMIndexerTask) { if (delegate instanceof PDOMIndexerTask) {

View file

@ -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 * 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
@ -8,15 +8,16 @@
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.actions; package org.eclipse.cdt.internal.ui.actions;
import org.eclipse.cdt.core.index.IIndexManager; import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.internal.core.pdom.PDOMManager;
public class FreshenIndexAction extends AbstractUpdateIndexAction { public class FreshenIndexAction extends AbstractUpdateIndexAction {
@Override @Override
protected int getUpdateOptions() { protected int getUpdateOptions() {
return IIndexManager.UPDATE_ALL; return IIndexManager.UPDATE_ALL | PDOMManager.UPDATE_EXTERNAL_FILES_FOR_PROJECT;
} }
} }

View file

@ -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 * 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
@ -8,15 +8,16 @@
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.actions; package org.eclipse.cdt.internal.ui.actions;
import org.eclipse.cdt.core.index.IIndexManager; import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.internal.core.pdom.PDOMManager;
public class UpdateIndexWithModifiedFilesAction extends AbstractUpdateIndexAction { public class UpdateIndexWithModifiedFilesAction extends AbstractUpdateIndexAction {
@Override @Override
protected int getUpdateOptions() { 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;
} }
} }