From ce15475828065f06ff10f9d8593a8a78b0ee4366 Mon Sep 17 00:00:00 2001 From: Teodor Madan Date: Mon, 29 Sep 2014 11:56:18 +0300 Subject: [PATCH] Bug 445357 Fix breakpoint set on external files - In case IDeclaration has no underlining resource, get resource from editor utility support, in the same way as toggle by line Change-Id: Ic0de58e9f8c1e671911b56f131b01937d8b982fd Signed-off-by: Teodor Madan Reviewed-on: https://git.eclipse.org/r/34050 Tested-by: Hudson CI Reviewed-by: Marc Khouzam Tested-by: Marc Khouzam --- .../AbstractToggleBreakpointAdapter.java | 64 +++++++++++++------ 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/AbstractToggleBreakpointAdapter.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/AbstractToggleBreakpointAdapter.java index 6ec0228d919..3cd09acbdb9 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/AbstractToggleBreakpointAdapter.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/AbstractToggleBreakpointAdapter.java @@ -39,6 +39,7 @@ import org.eclipse.cdt.debug.internal.ui.actions.ActionMessages; import org.eclipse.cdt.debug.internal.ui.actions.breakpoints.EnableDisableBreakpointRulerAction; import org.eclipse.cdt.debug.internal.ui.breakpoints.CBreakpointContext; import org.eclipse.cdt.debug.ui.CDebugUIPlugin; +import org.eclipse.cdt.internal.ui.util.EditorUtility; import org.eclipse.cdt.internal.ui.util.ExternalEditorInput; import org.eclipse.cdt.ui.CDTUITools; import org.eclipse.core.filesystem.URIUtil; @@ -646,31 +647,37 @@ abstract public class AbstractToggleBreakpointAdapter /** * Returns the resource being edited in the given workbench part. - * @param part Workbench part to checm. + * @param part Workbench part to check. * @return Resource being edited. */ protected static IResource getResource( IWorkbenchPart part ) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); if ( part instanceof IEditorPart ) { IEditorInput editorInput = ((IEditorPart)part).getEditorInput(); - IResource resource = null; - if ( editorInput instanceof IFileEditorInput ) { - resource = ((IFileEditorInput)editorInput).getFile(); - } - else if ( editorInput instanceof ExternalEditorInput ) { - resource = ((ExternalEditorInput)editorInput).getMarkerResource(); - } - if ( resource != null ) - return resource; - /* This file is not in a project, let default case handle it */ - ILocationProvider provider = (ILocationProvider)editorInput.getAdapter( ILocationProvider.class ); - if ( provider != null ) { - IPath location = provider.getPath( editorInput ); - if ( location != null ) { - IFile[] files = root.findFilesForLocationURI( URIUtil.toURI( location ) ); - if ( files.length > 0 && files[0].isAccessible()) - return files[0]; - } + return getResource(editorInput); + } + return root; + } + + private static IResource getResource(IEditorInput editorInput) { + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IResource resource = null; + if ( editorInput instanceof IFileEditorInput ) { + resource = ((IFileEditorInput)editorInput).getFile(); + } + else if ( editorInput instanceof ExternalEditorInput ) { + resource = ((ExternalEditorInput)editorInput).getMarkerResource(); + } + if ( resource != null ) + return resource; + /* This file is not in a project, let default case handle it */ + ILocationProvider provider = (ILocationProvider)editorInput.getAdapter( ILocationProvider.class ); + if ( provider != null ) { + IPath location = provider.getPath( editorInput ); + if ( location != null ) { + IFile[] files = root.findFilesForLocationURI( URIUtil.toURI( location ) ); + if ( files.length > 0 && files[0].isAccessible()) + return files[0]; } } return root; @@ -691,8 +698,25 @@ abstract public class AbstractToggleBreakpointAdapter return ""; //$NON-NLS-1$ } + /** + * Returns the resource file containing the C model element. + * + * @param declaration model element + * @return resource for c model element. Cannot be null, will return workspace root when no resource file can be found. + */ + protected IResource getElementResource( IDeclaration declaration ) { - return declaration.getUnderlyingResource(); + IResource resource = declaration.getUnderlyingResource(); + if (resource != null) + return resource; + + try { + IEditorInput editorInput = EditorUtility.getEditorInput(declaration); + return getResource(editorInput); + } catch (CModelException e) { + DebugPlugin.log(e); + } + return ResourcesPlugin.getWorkspace().getRoot(); } private String getFunctionName( IFunction function ) {