1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Bug 341607 - Empty editor content for unavailable file resources when debugger steps into those source files

This commit is contained in:
Teodor Madan 2011-04-04 14:33:40 +00:00
parent 49c57fad93
commit dfeae8915c
4 changed files with 51 additions and 25 deletions

View file

@ -112,9 +112,9 @@ public class CompilationDirectorySourceContainer extends CompositeSourceContaine
if (!file.isAbsolute()) { if (!file.isAbsolute()) {
file = new File(fDirectory, name); file = new File(fDirectory, name);
} }
List<Object> sources; List<Object> sources = new ArrayList<Object>();
if (file.exists() && file.isFile()) { if (file.exists() && file.isFile()) {
sources = Arrays.asList(SourceUtils.findSourceElements(file, getDirector())); sources.addAll(Arrays.asList(SourceUtils.findSourceElements(file, getDirector())));
} else { } else {
sources = new ArrayList<Object>(); sources = new ArrayList<Object>();
} }

View file

@ -28,6 +28,7 @@ import javax.xml.transform.TransformerException;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.CDebugUtils; import org.eclipse.cdt.debug.core.CDebugUtils;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
@ -37,8 +38,8 @@ import org.eclipse.cdt.debug.core.sourcelookup.IDirectorySourceLocation;
import org.eclipse.cdt.debug.core.sourcelookup.IMappingSourceContainer; import org.eclipse.cdt.debug.core.sourcelookup.IMappingSourceContainer;
import org.eclipse.cdt.debug.core.sourcelookup.IProjectSourceLocation; import org.eclipse.cdt.debug.core.sourcelookup.IProjectSourceLocation;
import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer; import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer;
import org.eclipse.cdt.internal.core.model.ExternalTranslationUnit;
import org.eclipse.cdt.internal.core.resources.ResourceLookup; import org.eclipse.cdt.internal.core.resources.ResourceLookup;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
@ -145,7 +146,7 @@ public class SourceUtils {
clazz = CDebugCorePlugin.getDefault().getBundle().loadClass(className); clazz = CDebugCorePlugin.getDefault().getBundle().loadClass(className);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
CDebugCorePlugin.log(MessageFormat.format("Unable to restore source location - class not found {0}", //$NON-NLS-1$ CDebugCorePlugin.log(MessageFormat.format("Unable to restore source location - class not found {0}", //$NON-NLS-1$
new String[] { className })); (Object[]) new String[] { className }));
continue; continue;
} }
ICSourceLocation location = null; ICSourceLocation location = null;
@ -256,14 +257,15 @@ public class SourceUtils {
* @param file A source or header file. * @param file A source or header file.
* @param director A source lookup director. * @param director A source lookup director.
* @return An array of source elements sorted in relevance order. The elements of the array can * @return An array of source elements sorted in relevance order. The elements of the array can
* be either instances of IFile or LocalFileStorage. The returned array can be empty if * be either instances of IFile, ITranslationUnit or LocalFileStorage. The returned array can be empty if
* no source elements match the given file. * no source elements match the given file.
*/ */
public static Object[] findSourceElements(File file, ISourceLookupDirector director) { public static Object[] findSourceElements(File file, ISourceLookupDirector director) {
IFile[] wfiles = ResourceLookup.findFilesForLocation(new Path(file.getAbsolutePath())); IFile[] wfiles = ResourceLookup.findFilesForLocation(new Path(file.getAbsolutePath()));
IProject launchConfigurationProject = getLaunchConfigurationProject(director);
if (wfiles.length > 0) { if (wfiles.length > 0) {
ResourceLookup.sortFilesByRelevance(wfiles, getLaunchConfigurationProject(director)); ResourceLookup.sortFilesByRelevance(wfiles, launchConfigurationProject);
return wfiles; return updateUnavailableResources(wfiles, launchConfigurationProject);
} }
try { try {
@ -271,8 +273,8 @@ public class SourceUtils {
// systems like Windows. // systems like Windows.
wfiles = ResourceLookup.findFilesForLocation(new Path(file.getCanonicalPath())); wfiles = ResourceLookup.findFilesForLocation(new Path(file.getCanonicalPath()));
if (wfiles.length > 0) { if (wfiles.length > 0) {
ResourceLookup.sortFilesByRelevance(wfiles, getLaunchConfigurationProject(director)); ResourceLookup.sortFilesByRelevance(wfiles, launchConfigurationProject);
return wfiles; return updateUnavailableResources(wfiles, launchConfigurationProject);
} }
// The file is not already in the workspace so try to create an external translation unit for it. // The file is not already in the workspace so try to create an external translation unit for it.
@ -281,9 +283,7 @@ public class SourceUtils {
if (projectName != null) { if (projectName != null) {
ICProject project = CoreModel.getDefault().getCModel().getCProject(projectName); ICProject project = CoreModel.getDefault().getCModel().getCProject(projectName);
if (project != null) { if (project != null) {
IPath path = Path.fromOSString(file.getCanonicalPath()); return new ITranslationUnit[] { CoreModel.getDefault().createTranslationUnitFrom(project, URIUtil.toURI(file.getCanonicalPath(), true)) };
String id = CoreModel.getRegistedContentTypeId(project.getProject(), path.lastSegment());
return new ExternalTranslationUnit[] { new ExternalTranslationUnit(project, path, id) };
} }
} }
} }
@ -293,4 +293,30 @@ public class SourceUtils {
// If we can't create an ETU then fall back on LocalFileStorage. // If we can't create an ETU then fall back on LocalFileStorage.
return new LocalFileStorage[] { new LocalFileStorage(file) }; return new LocalFileStorage[] { new LocalFileStorage(file) };
} }
/**
* Check for IFile to be available in workspace ( see {@link IFile#isAccessible()} ).
* Unavailable resources are replaced with {@link ITranslationUnit}
* @param wfiles
* @param project
* @return
*/
private static Object[] updateUnavailableResources(IFile[] wfiles, IProject project){
// with no projects context we will not be able to create ITranslationUnits
if (project == null) {
return wfiles;
}
ICProject cProject = CoreModel.getDefault().create(project);
Object[] result = new Object[wfiles.length];
for (int i=0; i< wfiles.length; ++i) {
IFile wkspFile = wfiles[i];
if (wkspFile.isAccessible()) {
result[i] = wkspFile;
} else {
result[i] = CoreModel.getDefault().createTranslationUnitFrom(cProject, wkspFile.getLocationURI());
}
}
return result;
}
} }

View file

@ -166,7 +166,7 @@ public class CDebugModelPresentation extends LabelProvider implements IDebugMode
IProject project = b.getMarker().getResource().getProject(); IProject project = b.getMarker().getResource().getProject();
// Select the most 'relevant' IFile for an external location // Select the most 'relevant' IFile for an external location
file = ResourceLookup.selectFileForLocation(path, project); file = ResourceLookup.selectFileForLocation(path, project);
if (file == null) { if (file == null || !file.isAccessible()) {
// Try resolving the path to a real io.File // Try resolving the path to a real io.File
File fsfile = new File( handle ); File fsfile = new File( handle );
if ( fsfile.isFile() && fsfile.exists() ) { if ( fsfile.isFile() && fsfile.exists() ) {
@ -470,7 +470,7 @@ public class CDebugModelPresentation extends LabelProvider implements IDebugMode
} }
} }
catch( DebugException e ) { catch( DebugException e ) {
return MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.2" ), new String[] { e.getMessage() } ); //$NON-NLS-1$ return MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.2" ), e.getMessage() ); //$NON-NLS-1$
} }
catch( CoreException e ) { catch( CoreException e ) {
CDebugUIPlugin.log( e ); CDebugUIPlugin.log( e );
@ -682,15 +682,15 @@ public class CDebugModelPresentation extends LabelProvider implements IDebugMode
String reason = ""; //$NON-NLS-1$ String reason = ""; //$NON-NLS-1$
if ( info != null && info instanceof ICDISignalExitInfo ) { if ( info != null && info instanceof ICDISignalExitInfo ) {
ICDISignalExitInfo sigInfo = (ICDISignalExitInfo)info; ICDISignalExitInfo sigInfo = (ICDISignalExitInfo)info;
reason = ' ' + MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.5" ), new String[]{ sigInfo.getName(), sigInfo.getDescription() } ); //$NON-NLS-1$ reason = ' ' + MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.5" ), sigInfo.getName(), sigInfo.getDescription() ); //$NON-NLS-1$
} }
else if ( info != null && info instanceof ICDIExitInfo ) { else if ( info != null && info instanceof ICDIExitInfo ) {
reason = ' ' + MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.6" ), new Integer[] { Integer.valueOf( ((ICDIExitInfo)info).getCode() ) } ); //$NON-NLS-1$ reason = ' ' + MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.6" ), Integer.valueOf( ((ICDIExitInfo)info).getCode() ) ); //$NON-NLS-1$
} }
return MessageFormat.format( label, new String[] { target.getName(), reason } ); return MessageFormat.format( label, target.getName(), reason );
} }
else if ( state.equals( CDebugElementState.SUSPENDED ) ) { else if ( state.equals( CDebugElementState.SUSPENDED ) ) {
return MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.7" ), new String[] { target.getName() } ); //$NON-NLS-1$ return MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.7" ), target.getName() ); //$NON-NLS-1$
} }
} }
} }
@ -718,10 +718,10 @@ public class CDebugModelPresentation extends LabelProvider implements IDebugMode
Object info = element.getCurrentStateInfo(); Object info = element.getCurrentStateInfo();
if ( info instanceof ICDISignalReceived ) { if ( info instanceof ICDISignalReceived ) {
ICDISignal signal = ((ICDISignalReceived)info).getSignal(); ICDISignal signal = ((ICDISignalReceived)info).getSignal();
reason = MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.13" ), new String[]{ signal.getName(), signal.getDescription() } ); //$NON-NLS-1$ reason = MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.13" ), signal.getName(), signal.getDescription() ); //$NON-NLS-1$
} }
else if ( info instanceof ICDIWatchpointTrigger ) { else if ( info instanceof ICDIWatchpointTrigger ) {
reason = MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.14" ), new String[]{ ((ICDIWatchpointTrigger)info).getOldValue(), ((ICDIWatchpointTrigger)info).getNewValue() } ); //$NON-NLS-1$ reason = MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.14" ), ((ICDIWatchpointTrigger)info).getOldValue(), ((ICDIWatchpointTrigger)info).getNewValue() ); //$NON-NLS-1$
} }
else if ( info instanceof ICDIWatchpointScope ) { else if ( info instanceof ICDIWatchpointScope ) {
reason = CDebugUIMessages.getString( "CDTDebugModelPresentation.15" ); //$NON-NLS-1$ reason = CDebugUIMessages.getString( "CDTDebugModelPresentation.15" ); //$NON-NLS-1$
@ -733,12 +733,12 @@ public class CDebugModelPresentation extends LabelProvider implements IDebugMode
reason = CDebugUIMessages.getString( "CDTDebugModelPresentation.17" ); //$NON-NLS-1$ reason = CDebugUIMessages.getString( "CDTDebugModelPresentation.17" ); //$NON-NLS-1$
} }
else if ( info instanceof ICDIEventBreakpointHit ) { else if ( info instanceof ICDIEventBreakpointHit ) {
reason = MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.20" ), new String[]{ ((ICDIEventBreakpointHit)info).getEventBreakpointType() } ); //$NON-NLS-1$ reason = MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.20" ), ((ICDIEventBreakpointHit)info).getEventBreakpointType() ); //$NON-NLS-1$
} }
} }
return MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.18" ), new String[] { thread.getName(), reason } ); //$NON-NLS-1$ return MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.18" ), thread.getName(), reason ); //$NON-NLS-1$
} }
return MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.19" ), new String[] { thread.getName() } ); //$NON-NLS-1$ return MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.19" ), thread.getName() ); //$NON-NLS-1$
} }
protected String getStackFrameText( IStackFrame f, boolean qualified ) throws DebugException { protected String getStackFrameText( IStackFrame f, boolean qualified ) throws DebugException {
@ -790,7 +790,7 @@ public class CDebugModelPresentation extends LabelProvider implements IDebugMode
} }
public static String getFormattedString( String string, String[] args ) { public static String getFormattedString( String string, String[] args ) {
return MessageFormat.format( string, args ); return MessageFormat.format( string, (Object[]) args );
} }
} }

View file

@ -267,7 +267,7 @@ abstract public class AbstractToggleBreakpointAdapter implements IToggleBreakpoi
IPath location = provider.getPath( editorInput ); IPath location = provider.getPath( editorInput );
if ( location != null ) { if ( location != null ) {
IFile[] files = root.findFilesForLocationURI( URIUtil.toURI( location ) ); IFile[] files = root.findFilesForLocationURI( URIUtil.toURI( location ) );
if ( files.length > 0 ) if ( files.length > 0 && files[0].isAccessible())
return files[0]; return files[0];
} }
} }