public void toggleLineBreakpoints(final IWorkbenchPart part, ISelection selection) throws CoreException { final QvtEditor qvtEditor = getEditor(part); if (qvtEditor == null) { return; } IFile unitFile = (IFile) qvtEditor.getEditorInput().getAdapter(IResource.class); ITextSelection textSelection = (ITextSelection) selection; int lineNumber = textSelection.getStartLine() + 1; List<ILineBreakpoint> breakpoints = QVTODebugCore.getQVTOBreakpoints(ILineBreakpoint.class); for (ILineBreakpoint next : breakpoints) { if (!unitFile.equals(next.getMarker().getResource())) { continue; } if (next.getLineNumber() == lineNumber) { try { // a breakpoint already exists at this line =>toggle again means remove DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint(next, true); } catch (CoreException e) { QVTODebugUIPlugin.log(e.getStatus()); } next.delete(); return; } } URI sourceURI = URIUtils.getResourceURI(unitFile); final QVTOBreakpoint lineBreakpoint = new QVTOBreakpoint(sourceURI, lineNumber); lineBreakpoint.register(true); Job job = new Job(DebugUIMessages.QVTOToggleBreakpointAdapter_VerifyBreakpointJob) { @Override protected IStatus run(IProgressMonitor monitor) { return new BreakpointLocationVerifier( qvtEditor, lineBreakpoint, DebugUIMessages.QVTOToggleBreakpointAdapter_CannotSetBreakpoint) .run(); } @Override public boolean belongsTo(Object family) { return QVTOBreakpoint.QVTO_BREAKPOINT_JOBFAMILY == family; } }; job.setPriority(Job.INTERACTIVE); job.setSystem(true); job.schedule(); }
protected StringBuilder appendLineNumber(ILineBreakpoint breakpoint, StringBuilder label) throws CoreException { int lineNumber = breakpoint.getLineNumber(); if (lineNumber > 0) { label.append(" ["); // $NON-NLS-1$ label.append("line:"); label.append(' '); label.append(lineNumber); label.append(']'); } return label; }
protected StringBuilder appendFileName(ILineBreakpoint breakpoint, StringBuilder label) throws CoreException { label.append(breakpoint.getMarker().getResource().getName()); return label; }
private Position createPositionFromBreakpoint(IBreakpoint breakpoint) throws CoreException { IBreakpointLocationProvider locationProvider = breakpoint.getAdapter(IBreakpointLocationProvider.class); /* if there is a location provider, than use the provider to retrieve the location */ if (locationProvider != null) { /* if there is source info, than create a source line position */ String sourceFile = locationProvider.getSourceFile(breakpoint, fDebugContext); if (sourceFile != null) { int lineNumber = locationProvider.getLineNumber(breakpoint, fDebugContext) - 1; return createPositionFromSourceLine(sourceFile, lineNumber); } else { /* if there is label info, than create a label position */ IAddress labelAddress = locationProvider.getLabelAddress(breakpoint, fDebugContext); if (labelAddress != null) { return createPositionFromLabel(labelAddress.getValue()); /* Otherwise, create an address position */ } else { // See bug 300053 comment 5: // Since there can only be one annotation per marker and in order to support multiple // annotations per breakpoint, we need a specialized annotation type. // // So for now, we only create an annotation for the first valid address. We can add // support for multiple annotations per breakpoint when it's needed. IAddress[] addresses = locationProvider.getAddresses(breakpoint, fDebugContext); for (int i = 0; addresses != null && i < addresses.length; ++i) { BigInteger address = addresses[i].getValue(); Position position = createPositionFromAddress(address); if (position != null) return position; } } } /* otherwise, use legacy ICBreakpoint location info */ } else { if (breakpoint instanceof ICAddressBreakpoint) { ICAddressBreakpoint addressBreakpoint = (ICAddressBreakpoint) breakpoint; return createPositionFromAddress(decodeAddress(addressBreakpoint.getAddress())); } else if (breakpoint instanceof ILineBreakpoint) { ILineBreakpoint lineBreakpoint = (ILineBreakpoint) breakpoint; Position position = null; final int lineNumber = lineBreakpoint.getLineNumber() - 1; final IMarker marker = breakpoint.getMarker(); if (marker.getResource().getType() == IResource.FILE) { position = createPositionFromSourceLine((IFile) marker.getResource(), lineNumber); if (position != null) { return position; } } String fileName = marker.getAttribute(ICLineBreakpoint.SOURCE_HANDLE, null); position = createPositionFromSourceLine(fileName, lineNumber); if (position == null && breakpoint instanceof ICLineBreakpoint) { ICLineBreakpoint cBreakpoint = (ICLineBreakpoint) breakpoint; if (breakpoint instanceof ICFunctionBreakpoint) { position = createPositionFromLabel(cBreakpoint.getFunction()); } else { position = createPositionFromAddress(decodeAddress(cBreakpoint.getAddress())); } } return position; } } return null; }