From 2a54313bd69179a50387fe04f1bc9e1d4d1c05c2 Mon Sep 17 00:00:00 2001 From: Ken Ryall Date: Sat, 17 Feb 2007 14:39:49 +0000 Subject: When the source locator finds source files by absolute path attempt to create an external translation unit to display them with. Bug 159831. --- .../sourcelookup/AbsolutePathSourceContainer.java | 34 +++++++++++++++++----- .../debug/internal/ui/CDebugModelPresentation.java | 5 ++++ 2 files changed, 31 insertions(+), 8 deletions(-) (limited to 'debug') diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/AbsolutePathSourceContainer.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/AbsolutePathSourceContainer.java index 9e74fce12f9..e9a937890f5 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/AbsolutePathSourceContainer.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/AbsolutePathSourceContainer.java @@ -14,10 +14,15 @@ package org.eclipse.cdt.debug.core.sourcelookup; import java.io.File; import java.io.IOException; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.debug.core.CDebugCorePlugin; +import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; +import org.eclipse.cdt.internal.core.model.ExternalTranslationUnit; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; import org.eclipse.debug.core.sourcelookup.ISourceContainerType; import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainer; @@ -30,20 +35,33 @@ public class AbsolutePathSourceContainer extends AbstractSourceContainer { */ public static final String TYPE_ID = CDebugCorePlugin.getUniqueIdentifier() + ".containerType.absolutePath"; //$NON-NLS-1$ - private Object[] findSourceElementByFile( File file ) { - IFile[] wfiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation( new Path( file.getAbsolutePath() ) ); - if ( wfiles.length > 0 ) + private Object[] findSourceElementByFile(File file) { + IFile[] wfiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(file.getAbsolutePath())); + if (wfiles.length > 0) return wfiles; try { - // Check the canonical path as well to support case insensitive file systems like Windows. - wfiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation( new Path( file.getCanonicalPath() ) ); - if ( wfiles.length > 0 ) + // Check the canonical path as well to support case insensitive file + // systems like Windows. + wfiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(file.getCanonicalPath())); + if (wfiles.length > 0) return wfiles; - } catch (IOException e) { // ignore if getCanonicalPath throws + + // The file is not already in the workspace so try to create an external translation unit for it. + String projectName = getDirector().getLaunchConfiguration().getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); + ICProject project = CoreModel.getDefault().getCModel().getCProject(projectName); + if (project != null) + { + IPath path = Path.fromOSString(file.getCanonicalPath()); + String id = CoreModel.getRegistedContentTypeId(project.getProject(), path.lastSegment()); + return new ExternalTranslationUnit[] { new ExternalTranslationUnit(project, new Path(file.getCanonicalPath()), id) }; } + } catch (IOException e) { // ignore if getCanonicalPath throws + } catch (CoreException e) { + } - return new LocalFileStorage[] { new LocalFileStorage( file ) }; + // If we can't create an ETU then fall back on LocalFileStorage. + return new LocalFileStorage[] { new LocalFileStorage(file) }; } public boolean isValidAbsoluteFilePath( String name ) diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugModelPresentation.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugModelPresentation.java index 17cff89bae9..ce7d3ee8e34 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugModelPresentation.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugModelPresentation.java @@ -48,6 +48,7 @@ import org.eclipse.cdt.debug.core.model.IEnableDisableTarget; import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceNotFoundElement; import org.eclipse.cdt.debug.internal.ui.sourcelookup.CSourceNotFoundEditorInput; import org.eclipse.cdt.debug.ui.CDebugUIPlugin; +import org.eclipse.cdt.internal.core.model.ExternalTranslationUnit; import org.eclipse.cdt.internal.ui.util.ExternalEditorInput; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.core.resources.IFile; @@ -167,6 +168,10 @@ public class CDebugModelPresentation extends LabelProvider implements IDebugMode if ( element instanceof FileStorage || element instanceof LocalFileStorage ) { return new ExternalEditorInput( (IStorage)element ); } + if ( element instanceof ExternalTranslationUnit ) { + ExternalTranslationUnit etu = (ExternalTranslationUnit) element; + return new ExternalEditorInput( etu , new LocalFileStorage( etu.getPath().toFile() ) ); + } if (element instanceof CSourceNotFoundElement) { return new CSourceNotFoundEditorInput((CSourceNotFoundElement) element); -- cgit v1.2.3