Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Leherbauer2008-01-24 04:18:08 -0500
committerAnton Leherbauer2008-01-24 04:18:08 -0500
commit1d25bf5abce25919c43b8a916b6841e8c4b6f24b (patch)
treefd2bef545ca623ed538c1fc53da0648745074bd0
parentc0a19d0e10b00f7fad875aee2b44f60341605fb3 (diff)
downloadorg.eclipse.cdt-1d25bf5abce25919c43b8a916b6841e8c4b6f24b.tar.gz
org.eclipse.cdt-1d25bf5abce25919c43b8a916b6841e8c4b6f24b.tar.xz
org.eclipse.cdt-1d25bf5abce25919c43b8a916b6841e8c4b6f24b.zip
Fix for 216186: [patch] EditorUtility.getWorkspaceFileAtLocation gets wrong IFile in some cases
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java62
1 files changed, 35 insertions, 27 deletions
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java
index 134badda1e..247fbc1e37 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 QNX Software Systems and others.
+ * Copyright (c) 2000, 2008 QNX Software Systems 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
@@ -19,7 +19,6 @@ import java.io.File;
import java.io.IOException;
import java.text.MessageFormat;
-import org.eclipse.core.filebuffers.FileBuffers;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
@@ -343,37 +342,46 @@ public class EditorUtility {
* @return an <code>IFile</code> or <code>null</code>
*/
private static IFile getWorkspaceFileAtLocation(IPath location, ICElement context) {
- IFile file= FileBuffers.getWorkspaceFileAtLocation(location);
- if (file == null) {
- // try to find a linked resource
- IProject project= null;
- if (context != null) {
- ICProject cProject= context.getCProject();
- if (cProject != null) {
- project= cProject.getProject();
- }
+ IProject project= null;
+ if (context != null) {
+ ICProject cProject= context.getCProject();
+ if (cProject != null) {
+ project= cProject.getProject();
}
- IFile bestMatch= null;
- IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
- IFile[] files= root.findFilesForLocation(location);
- for (int i= 0; i < files.length; i++) {
- file= files[i];
- if (file.isAccessible()) {
- if (project != null && file.getProject() == project) {
- bestMatch= file;
+ }
+ IFile bestMatch= null;
+ IFile secondBestMatch= null;
+ IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
+ IFile[] files= root.findFilesForLocation(location);
+ for (int i= 0; i < files.length; i++) {
+ IFile file= files[i];
+ if (file.isAccessible()) {
+ if (project != null && file.getProject().equals(project)) {
+ bestMatch= file;
+ break;
+ } else if (CoreModel.hasCNature(file.getProject())) {
+ bestMatch= file;
+ if (project == null) {
break;
}
- if (bestMatch == null) {
- bestMatch= file;
- if (project == null) {
- break;
- }
- }
+ } else {
+ // match in non-CDT project
+ secondBestMatch= file;
+ }
+ }
+ }
+ bestMatch= bestMatch != null ? bestMatch : secondBestMatch;
+ if (bestMatch == null) {
+ // try workspace relative path
+ if (location.segmentCount() >= 2) {
+ // @see IContainer#getFile for the required number of segments
+ IFile file= root.getFile(location);
+ if (file != null && file.isAccessible()) {
+ bestMatch= file;
}
}
- return bestMatch;
}
- return file;
+ return bestMatch;
}
/**

Back to the top