View | Details | Raw Unified | Return to bug 165867 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/cdt/internal/ui/editor/OpenIncludeAction.java (-28 / +34 lines)
Lines 12-27 Link Here
12
package org.eclipse.cdt.internal.ui.editor;
12
package org.eclipse.cdt.internal.ui.editor;
13
13
14
import java.io.File;
14
import java.io.File;
15
import java.io.IOException;
16
import java.util.ArrayList;
15
import java.util.ArrayList;
17
import java.util.HashSet;
16
import java.util.HashSet;
18
import java.util.List;
17
import java.util.List;
19
18
20
import org.eclipse.core.resources.IContainer;
19
import org.eclipse.core.resources.IContainer;
20
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.resources.IProject;
21
import org.eclipse.core.resources.IProject;
22
import org.eclipse.core.resources.IResource;
22
import org.eclipse.core.resources.IResource;
23
import org.eclipse.core.resources.IResourceProxy;
23
import org.eclipse.core.resources.IResourceProxy;
24
import org.eclipse.core.resources.IResourceProxyVisitor;
24
import org.eclipse.core.resources.IResourceProxyVisitor;
25
import org.eclipse.core.resources.IWorkspaceRoot;
25
import org.eclipse.core.resources.ResourcesPlugin;
26
import org.eclipse.core.resources.ResourcesPlugin;
26
import org.eclipse.core.runtime.CoreException;
27
import org.eclipse.core.runtime.CoreException;
27
import org.eclipse.core.runtime.IPath;
28
import org.eclipse.core.runtime.IPath;
Lines 94-101 Link Here
94
					}
95
					}
95
					if (info != null) {
96
					if (info != null) {
96
						String[] includePaths = info.getIncludePaths();
97
						String[] includePaths = info.getIncludePaths();
97
						HashSet found = new HashSet();
98
						findFile(includePaths, includeName, filesFound);
98
						findFile(includePaths, includeName, filesFound, found);
99
					}
99
					}
100
					if (filesFound.size() == 0) {
100
					if (filesFound.size() == 0) {
101
						// Fall back and search the project
101
						// Fall back and search the project
Lines 135-175 Link Here
135
	}
135
	}
136
	
136
	
137
	private boolean isInProject(IPath path) {
137
	private boolean isInProject(IPath path) {
138
		return ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path) != null;		
138
		return getWorkspaceRoot().getFileForLocation(path) != null;		
139
	}
139
	}
140
	
140
	
141
	// If 'path' is not a resource in the current workspace and
141
	/**
142
	// it is a symlink to a resource that is in the current workspace,
142
	 * Returns the path as is, if it points to a workspace resource. If the path
143
	// use the symlink target instead
143
	 * does not point to a workspace resource, but there are linked workspace
144
	private IPath resolveIncludeLink(File file, IPath path) {
144
	 * resources pointing to it, returns the paths of these resources.
145
		if (isInProject(path))
145
	 * Othervise, returns the path as is. 
146
			return path;
146
	 */
147
		
147
	private IPath[] resolveIncludeLink(IPath path) {
148
		try {
148
		if (!isInProject(path)) {
149
			String canon = file.getCanonicalPath();
149
			IFile[] files = getWorkspaceRoot().findFilesForLocation(path);
150
			if (canon.equals(file.getAbsolutePath()))
150
			if (files.length > 0) {
151
				return path;
151
				IPath[] paths = new IPath[files.length];
152
			
152
				for (int i = 0; i < files.length; i++) {
153
			IPath p = Path.fromOSString(canon);
153
					paths[i] = files[i].getFullPath(); 
154
			if (isInProject(p))
154
				}
155
			    return p;
155
				return paths;
156
		} catch (IOException e) {
156
			}
157
			// Do nothing; the path is not resolved
158
		}
157
		}
159
		
158
		
160
		return path;
159
		return new IPath[] { path };
160
	}
161
162
	private IWorkspaceRoot getWorkspaceRoot() {
163
		return ResourcesPlugin.getWorkspace().getRoot();
161
	}
164
	}
162
	
165
	
163
	private void findFile(String[] includePaths,  String name, ArrayList list,
166
	private void findFile(String[] includePaths, String name, ArrayList list)
164
			HashSet foundSet)  throws CoreException {
167
			throws CoreException {
168
		HashSet foundSet = new HashSet();
165
		for (int i = 0; i < includePaths.length; i++) {
169
		for (int i = 0; i < includePaths.length; i++) {
166
			IPath path = new Path(includePaths[i] + "/" + name); //$NON-NLS-1$
170
			IPath path = new Path(includePaths[i] + "/" + name); //$NON-NLS-1$
167
			File file = path.toFile();
171
			File file = path.toFile();
168
			if (file.exists()) {
172
			if (file.exists()) {
169
				IPath p = resolveIncludeLink(file, path);
173
				IPath[] paths = resolveIncludeLink(path);
170
				if (!foundSet.contains(p)) {
174
				for (int j = 0; j < paths.length; j++) {
171
					foundSet.add(p);
175
					IPath p = paths[j];
172
					list.add(p);
176
					if (foundSet.add(p)) {
177
						list.add(p);
178
					}
173
				}
179
				}
174
			} 
180
			} 
175
		}
181
		}

Return to bug 165867