1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 04:45:38 +02:00

Bug 306879: Headers duplicated via symbolic links.

This commit is contained in:
Markus Schorn 2010-03-31 12:01:53 +00:00
parent d8c47d612a
commit 38da7f7ebd
3 changed files with 35 additions and 13 deletions

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2002, 2009 QNX Software Systems and others. * Copyright (c) 2002, 2010 QNX Software Systems 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
@ -550,6 +550,7 @@ public class CoreModelUtil {
*/ */
public static ITranslationUnit findTranslationUnitForLocation(IPath location, ICProject preferredProject) throws CModelException { public static ITranslationUnit findTranslationUnitForLocation(IPath location, ICProject preferredProject) throws CModelException {
IFile[] files= ResourceLookup.findFilesForLocation(location); IFile[] files= ResourceLookup.findFilesForLocation(location);
ResourceLookup.sortFilesByRelevance(files, preferredProject != null ? preferredProject.getProject() : null);
boolean oneExisting= false; boolean oneExisting= false;
if (files.length > 0) { if (files.length > 0) {
for (IFile file : files) { for (IFile file : files) {

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. * Copyright (c) 2006, 2010 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
@ -84,6 +84,7 @@ import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IndexLocationFactory; import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.CModelException; 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.CoreModelUtil;
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;
@ -221,15 +222,27 @@ public class IBViewPart extends ViewPart
index.acquireReadLock(); index.acquireReadLock();
try { try {
if (!IndexUI.isIndexed(index, input)) { if (!IndexUI.isIndexed(index, input)) {
final String msg = IndexUI.getFileNotIndexedMessage(input); // Bug 306879: Try to find an alternative translation unit for the file by the location.
display.asyncExec(new Runnable() { final ITranslationUnit alt= CoreModelUtil.findTranslationUnitForLocation(input.getLocation(), input.getCProject());
public void run() { if (alt != null && IndexUI.isIndexed(index, alt)) {
if (fTreeViewer.getInput() == input) { display.asyncExec(new Runnable() {
setMessage(msg); public void run() {
fTreeViewer.setInput(null); if (fTreeViewer.getInput() == input) {
setInput(alt);
}
} }
} });
}); } else {
final String msg = IndexUI.getFileNotIndexedMessage(input);
display.asyncExec(new Runnable() {
public void run() {
if (fTreeViewer.getInput() == input) {
setMessage(msg);
fTreeViewer.setInput(null);
}
}
});
}
} }
return Status.OK_STATUS; return Status.OK_STATUS;
} finally { } finally {

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007, 2009 Wind River Systems, Inc. and others. * Copyright (c) 2007, 2010 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
@ -33,7 +33,6 @@ import org.eclipse.ui.IEditorInput;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.IPositionConverter; import org.eclipse.cdt.core.IPositionConverter;
import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
@ -329,10 +328,19 @@ public class IndexUI {
return null; return null;
} }
public static ITranslationUnit getTranslationUnit(ICProject cproject, IName name) { public static ITranslationUnit getTranslationUnit(ICProject cproject, IASTName name) {
return getTranslationUnit(cproject, name.getFileLocation()); return getTranslationUnit(cproject, name.getFileLocation());
} }
public static ITranslationUnit getTranslationUnit(ICProject cproject, IIndexName name) {
try {
return CoreModelUtil.findTranslationUnitForLocation(name.getFile().getLocation(), cproject);
} catch (CoreException e) {
CUIPlugin.log(e);
}
return null;
}
private static ITranslationUnit getTranslationUnit(ICProject cproject, final IASTFileLocation fileLocation) { private static ITranslationUnit getTranslationUnit(ICProject cproject, final IASTFileLocation fileLocation) {
if (fileLocation != null) { if (fileLocation != null) {
IPath path= Path.fromOSString(fileLocation.getFileName()); IPath path= Path.fromOSString(fileLocation.getFileName());