1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix for Bug 165867 - Open include ignores linked resources (patch by Sergey Prigogin)

This commit is contained in:
Anton Leherbauer 2006-12-12 07:29:52 +00:00
parent 8bc761d4c6
commit 6155014aab

View file

@ -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 * 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
@ -8,20 +8,22 @@
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* QNX Software System * QNX Software System
* Sergey Prigogin, Google - https://bugs.eclipse.org/bugs/show_bug.cgi?id=13221
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.editor; package org.eclipse.cdt.internal.ui.editor;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceProxy; import org.eclipse.core.resources.IResourceProxy;
import org.eclipse.core.resources.IResourceProxyVisitor; import org.eclipse.core.resources.IResourceProxyVisitor;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
@ -35,9 +37,6 @@ import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.window.Window; import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox; 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.CCorePlugin;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
@ -94,8 +93,7 @@ public class OpenIncludeAction extends Action {
} }
if (info != null) { if (info != null) {
String[] includePaths = info.getIncludePaths(); String[] includePaths = info.getIncludePaths();
HashSet found = new HashSet(); findFile(includePaths, includeName, filesFound);
findFile(includePaths, includeName, filesFound, found);
} }
if (filesFound.size() == 0) { if (filesFound.size() == 0) {
// Fall back and search the project // Fall back and search the project
@ -135,41 +133,53 @@ public class OpenIncludeAction extends Action {
} }
private boolean isInProject(IPath path) { 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, * Returns the path as is, if it points to a workspace resource. If the path
// use the symlink target instead * does not point to a workspace resource, but there are linked workspace
private IPath resolveIncludeLink(File file, IPath path) { * resources pointing to it, returns the paths of these resources.
if (isInProject(path)) * Othervise, returns the path as is.
return path; */
private IPath[] resolveIncludeLink(IPath path) {
try { if (!isInProject(path)) {
String canon = file.getCanonicalPath(); IFile[] files = getWorkspaceRoot().findFilesForLocation(path);
if (canon.equals(file.getAbsolutePath())) if (files.length > 0) {
return path; IPath[] paths = new IPath[files.length];
for (int i = 0; i < files.length; i++) {
IPath p = Path.fromOSString(canon); paths[i] = files[i].getFullPath();
if (isInProject(p)) }
return p; return paths;
} catch (IOException e) { }
// Do nothing; the path is not resolved
} }
return path; return new IPath[] { path };
}
private IWorkspaceRoot getWorkspaceRoot() {
return ResourcesPlugin.getWorkspace().getRoot();
} }
private void findFile(String[] includePaths, String name, ArrayList list, private void findFile(String[] includePaths, String name, ArrayList list)
HashSet foundSet) throws CoreException { throws CoreException {
// in case it is an absolute path
IPath includeFile= new Path(name);
if (includeFile.isAbsolute() && includeFile.toFile().exists()) {
list.add(includeFile);
return;
}
HashSet foundSet = new HashSet();
for (int i = 0; i < includePaths.length; i++) { for (int i = 0; i < includePaths.length; i++) {
IPath path = new Path(includePaths[i] + "/" + name); //$NON-NLS-1$ IPath path = new Path(includePaths[i]).append(includeFile);
File file = path.toFile(); File file = path.toFile();
if (file.exists()) { if (file.exists()) {
IPath p = resolveIncludeLink(file, path); IPath[] paths = resolveIncludeLink(path);
if (!foundSet.contains(p)) { for (int j = 0; j < paths.length; j++) {
foundSet.add(p); IPath p = paths[j];
list.add(p); if (foundSet.add(p)) {
list.add(p);
}
} }
} }
} }
@ -248,16 +258,4 @@ public class OpenIncludeAction extends Action {
return false; 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;
}
} }