### Eclipse Workspace Patch 1.0 #P org.eclipse.cdt.ui Index: src/org/eclipse/cdt/internal/ui/editor/OpenIncludeAction.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OpenIncludeAction.java,v retrieving revision 1.19 diff -u -r1.19 OpenIncludeAction.java --- src/org/eclipse/cdt/internal/ui/editor/OpenIncludeAction.java 24 Nov 2006 14:07:15 -0000 1.19 +++ src/org/eclipse/cdt/internal/ui/editor/OpenIncludeAction.java 11 Dec 2006 08:10:22 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 2006 IBM Corporation 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 @@ -8,20 +8,22 @@ * Contributors: * IBM Corporation - initial API and implementation * QNX Software System + * Sergey Prigogin, Google - https://bugs.eclipse.org/bugs/show_bug.cgi?id=13221 *******************************************************************************/ 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.List; import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceProxy; import org.eclipse.core.resources.IResourceProxyVisitor; +import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; @@ -35,9 +37,6 @@ import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.MessageBox; -import org.eclipse.ui.IEditorDescriptor; -import org.eclipse.ui.IEditorRegistry; -import org.eclipse.ui.PlatformUI; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.model.CModelException; @@ -94,8 +93,7 @@ } if (info != null) { String[] includePaths = info.getIncludePaths(); - HashSet found = new HashSet(); - findFile(includePaths, includeName, filesFound, found); + findFile(includePaths, includeName, filesFound); } if (filesFound.size() == 0) { // Fall back and search the project @@ -135,41 +133,47 @@ } private boolean isInProject(IPath path) { - return ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path) != null; + return getWorkspaceRoot().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 + /** + * Returns the path as is, if it points to a workspace resource. If the path + * does not point to a workspace resource, but there are linked workspace + * resources pointing to it, returns the paths of these resources. + * Othervise, returns the path as is. + */ + private IPath[] resolveIncludeLink(IPath path) { + if (!isInProject(path)) { + IFile[] files = getWorkspaceRoot().findFilesForLocation(path); + if (files.length > 0) { + IPath[] paths = new IPath[files.length]; + for (int i = 0; i < files.length; i++) { + paths[i] = files[i].getFullPath(); + } + return paths; + } } - return path; + return new IPath[] { path }; + } + + private IWorkspaceRoot getWorkspaceRoot() { + return ResourcesPlugin.getWorkspace().getRoot(); } - private void findFile(String[] includePaths, String name, ArrayList list, - HashSet foundSet) throws CoreException { + private void findFile(String[] includePaths, String name, ArrayList list) + throws CoreException { + HashSet foundSet = new HashSet(); 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()) { - IPath p = resolveIncludeLink(file, path); - if (!foundSet.contains(p)) { - foundSet.add(p); - list.add(p); + IPath[] paths = resolveIncludeLink(path); + for (int j = 0; j < paths.length; j++) { + IPath p = paths[j]; + if (foundSet.add(p)) { + list.add(p); + } } } } @@ -248,16 +252,4 @@ return false; } - - public static String getEditorID(String name) { - IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry(); - if (registry != null) { - IEditorDescriptor descriptor = registry.getDefaultEditor(name); - if (descriptor != null) { - return descriptor.getId(); - } - return IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID; - } - return null; - } }