1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 09:25:31 +02:00

When the source locator finds source files by absolute path attempt to create an external translation unit to display them with. Bug 159831.

This commit is contained in:
Ken Ryall 2007-02-17 14:39:49 +00:00
parent ac5bca2e7b
commit 2a54313bd6
2 changed files with 31 additions and 8 deletions

View file

@ -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 )

View file

@ -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);