Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlain Magloire2005-07-06 14:56:14 +0000
committerAlain Magloire2005-07-06 14:56:14 +0000
commit61aa8cb62cda8cc9df1895cdbf3829d3696ce903 (patch)
treea34511e99285b1930e6eeb916ea72cc642799bc4
parent03b2f1de719667a09826e92a3bba11a2cce07c40 (diff)
downloadorg.eclipse.cdt-61aa8cb62cda8cc9df1895cdbf3829d3696ce903.tar.gz
org.eclipse.cdt-61aa8cb62cda8cc9df1895cdbf3829d3696ce903.tar.xz
org.eclipse.cdt-61aa8cb62cda8cc9df1895cdbf3829d3696ce903.zip
2005-07-06 Alain Magloire
PR 102622: OpenIncludeAction improvement, patch from: Robert O'Callahan * src/org/eclipse/cdt/internal/ui/OpenIncludeAction.java
-rw-r--r--core/org.eclipse.cdt.ui/ChangeLog4
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OpenIncludeAction.java45
2 files changed, 44 insertions, 5 deletions
diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog
index db7a2b82584..08d6ae7a653 100644
--- a/core/org.eclipse.cdt.ui/ChangeLog
+++ b/core/org.eclipse.cdt.ui/ChangeLog
@@ -1,4 +1,8 @@
2005-07-06 Alain Magloire
+ PR 102622: OpenIncludeAction improvement, patch from: Robert O'Callahan
+ * src/org/eclipse/cdt/internal/ui/OpenIncludeAction.java
+
+2005-07-06 Alain Magloire
PR 102619: Performance improvement patch from: Robert O'Callahan
* src/org/eclipse/cdt/ui/CElementContentProvider.java
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OpenIncludeAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OpenIncludeAction.java
index 8c57f8cf42f..5c5e49b3f13 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OpenIncludeAction.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OpenIncludeAction.java
@@ -6,7 +6,10 @@ package org.eclipse.cdt.internal.ui.editor;
*/
import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
@@ -74,7 +77,7 @@ public class OpenIncludeAction extends Action {
try {
IResource res = include.getUnderlyingResource();
- ArrayList filesFound= new ArrayList(4);
+ ArrayList filesFound = new ArrayList(4);
if (res != null) {
IProject proj = res.getProject();
String includeName = include.getElementName();
@@ -88,7 +91,8 @@ public class OpenIncludeAction extends Action {
}
if (info != null) {
String[] includePaths = info.getIncludePaths();
- findFile(includePaths, includeName, filesFound);
+ HashSet found = new HashSet();
+ findFile(includePaths, includeName, filesFound, found);
}
if (filesFound.size() == 0) {
// Fall back and search the project
@@ -135,13 +139,44 @@ public class OpenIncludeAction extends Action {
errorMsg.setMessage (CUIPlugin.getResourceString("OpenIncludeAction.error.description")); //$NON-NLS-1$
errorMsg.open();
}
-
- private void findFile(String[] includePaths, String name, ArrayList list) throws CoreException {
+
+ private boolean isInProject(IPath path) {
+ return ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path) != null;
+ }
+
+ // If 'path' is not a resource in the current workspace and
+ // it is a symlink to a resource that is in the current workspace,
+ // use the symlink target instead
+ private IPath resolveIncludeLink(File file, IPath path) {
+ if (isInProject(path))
+ return path;
+
+ try {
+ String canon = file.getCanonicalPath();
+ if (canon.equals(file.getAbsolutePath()))
+ return path;
+
+ IPath p = Path.fromOSString(canon);
+ if (isInProject(p))
+ return p;
+ } catch (IOException e) {
+ // Do nothing; the path is not resolved
+ }
+
+ return path;
+ }
+
+ private void findFile(String[] includePaths, String name, ArrayList list,
+ HashSet foundSet) throws CoreException {
for (int i = 0; i < includePaths.length; i++) {
IPath path = new Path(includePaths[i] + "/" + name); //$NON-NLS-1$
File file = path.toFile();
if (file.exists()) {
- list.add(path);
+ IPath p = resolveIncludeLink(file, path);
+ if (!foundSet.contains(p)) {
+ foundSet.add(p);
+ list.add(p);
+ }
}
}
}

Back to the top