Search in sources :

Example 1 with ErlangLineBreakpoint

use of org.erlide.backend.debug.ErlangLineBreakpoint in project erlide_eclipse by erlang.

the class ErlangProcess method getBreakpoints.

@Override
public IBreakpoint[] getBreakpoints() {
    IStackFrame top = null;
    try {
        top = getTopStackFrame();
    } catch (final DebugException e1) {
    // can never happen
    }
    if (top instanceof ErlangStackFrame) {
        final ErlangStackFrame topFrame = (ErlangStackFrame) top;
        final IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
        final IBreakpoint[] breakpoints = breakpointManager.getBreakpoints();
        for (final IBreakpoint breakpoint : breakpoints) {
            if (breakpoint instanceof ErlangLineBreakpoint) {
                final ErlangLineBreakpoint lineBreakpoint = (ErlangLineBreakpoint) breakpoint;
                try {
                    if (lineBreakpoint.getModule().equals(topFrame.getModule()) && lineBreakpoint.getLineNumber() == topFrame.getLineNumber()) {
                        return new IBreakpoint[] { lineBreakpoint };
                    }
                } catch (final DebugException e) {
                    ErlLogger.warn(e);
                } catch (final CoreException e) {
                    ErlLogger.warn(e);
                }
            }
        }
    }
    return new IBreakpoint[0];
}
Also used : ErlangLineBreakpoint(org.erlide.backend.debug.ErlangLineBreakpoint) IStackFrame(org.eclipse.debug.core.model.IStackFrame) CoreException(org.eclipse.core.runtime.CoreException) IBreakpointManager(org.eclipse.debug.core.IBreakpointManager) DebugException(org.eclipse.debug.core.DebugException) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint)

Example 2 with ErlangLineBreakpoint

use of org.erlide.backend.debug.ErlangLineBreakpoint in project erlide_eclipse by erlang.

the class ErlLineBreakpointAdapter method toggleLineBreakpoints.

@Override
public void toggleLineBreakpoints(final IWorkbenchPart part, final ISelection selection) throws CoreException {
    final ITextEditor textEditor = getEditor(part);
    if (textEditor != null) {
        final IResource resource = textEditor.getEditorInput().getAdapter(IResource.class);
        if (resource == null) {
            return;
        }
        final ITextSelection textSelection = (ITextSelection) selection;
        final int lineNumber = textSelection.getStartLine();
        final IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(ErlDebugConstants.ID_ERLANG_DEBUG_MODEL);
        for (final IBreakpoint breakpoint : breakpoints) {
            if (resource.equals(breakpoint.getMarker().getResource())) {
                if (breakpoint instanceof ILineBreakpoint) {
                    final ILineBreakpoint lineBr = (ILineBreakpoint) breakpoint;
                    if (lineBr.getLineNumber() == lineNumber + 1) {
                        breakpoint.delete();
                        return;
                    }
                }
            }
        }
        // create line breakpoint (doc line numbers start at 0)
        final ErlangLineBreakpoint lineBreakpoint = new ErlangLineBreakpoint();
        lineBreakpoint.createMarker(resource, lineNumber + 1);
        DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(lineBreakpoint);
    }
}
Also used : ErlangLineBreakpoint(org.erlide.backend.debug.ErlangLineBreakpoint) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) ILineBreakpoint(org.eclipse.debug.core.model.ILineBreakpoint) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) IResource(org.eclipse.core.resources.IResource) ITextSelection(org.eclipse.jface.text.ITextSelection) ILineBreakpoint(org.eclipse.debug.core.model.ILineBreakpoint) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) ErlangLineBreakpoint(org.erlide.backend.debug.ErlangLineBreakpoint)

Example 3 with ErlangLineBreakpoint

use of org.erlide.backend.debug.ErlangLineBreakpoint in project erlide_eclipse by erlang.

the class BreakpointMarkerUpdater method updateMarker.

@Override
public boolean updateMarker(final IMarker marker, final IDocument document, final Position position) {
    if (position.isDeleted()) {
        return false;
    }
    try {
        final int line = MarkerUtilities.getLineNumber(marker);
        final int newLine = document.getLineOfOffset(position.getOffset()) + 1;
        if (line == newLine) {
            return true;
        }
        final IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager();
        final IBreakpoint breakpoint = manager.getBreakpoint(marker);
        if (breakpoint == null) {
            return false;
        }
        if (breakpoint instanceof ErlangLineBreakpoint) {
            final ErlangLineBreakpoint erlangLineBreakpoint = (ErlangLineBreakpoint) breakpoint;
            final ErlangDebugTarget target = erlangLineBreakpoint.getTarget();
            erlangLineBreakpoint.remove(target);
            MarkerUtilities.setLineNumber(marker, newLine);
            erlangLineBreakpoint.install(target);
            return true;
        }
        // if there exists a breakpoint on the line remove this one
        if (BreakpointMarkerUpdater.isLineBreakpointMarker(marker)) {
            ensureRanges(document, marker, line);
            return lineBreakpointExists(marker.getResource(), line, marker) == null;
        }
        // a line breakpoint must be removed
        if (BreakpointMarkerUpdater.isLineBreakpointMarker(marker) && line == -1) {
            return false;
        }
        MarkerUtilities.setLineNumber(marker, line);
        if (BreakpointMarkerUpdater.isLineBreakpointMarker(marker)) {
            ensureRanges(document, marker, line);
        }
        return true;
    } catch (final BadLocationException e) {
        ErlLogger.error(e);
    } catch (final CoreException e) {
        ErlLogger.error(e);
    }
    return false;
}
Also used : ErlangLineBreakpoint(org.erlide.backend.debug.ErlangLineBreakpoint) ErlangDebugTarget(org.erlide.backend.debug.model.ErlangDebugTarget) CoreException(org.eclipse.core.runtime.CoreException) IBreakpointManager(org.eclipse.debug.core.IBreakpointManager) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) IErlangBreakpoint(org.erlide.backend.debug.IErlangBreakpoint) ErlangLineBreakpoint(org.erlide.backend.debug.ErlangLineBreakpoint) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 4 with ErlangLineBreakpoint

use of org.erlide.backend.debug.ErlangLineBreakpoint in project erlide_eclipse by erlang.

the class BreakpointMarkerUpdater method lineBreakpointExists.

/**
 * Searches for an existing line breakpoint on the specified line in the
 * current type that does not match the id of the specified marker
 *
 * @param resource
 *            the resource to care about
 * @param typeName
 *            the name of the type the breakpoint is in
 * @param lineNumber
 *            the number of the line the breakpoint is on
 * @param currentmarker
 *            the current marker we are comparing to see if it will be moved
 *            onto an existing one
 * @return an existing line breakpoint on the current line of the given
 *         resource and type if there is one
 * @throws CoreException
 *
 * @since 3.4
 */
private IErlangBreakpoint lineBreakpointExists(final IResource resource, final int lineNumber, final IMarker currentmarker) throws CoreException {
    final IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager();
    final IBreakpoint[] breakpoints = manager.getBreakpoints(ErlDebugConstants.ID_ERLANG_DEBUG_MODEL);
    final String markerType = currentmarker.getType();
    for (IBreakpoint breakpoint1 : breakpoints) {
        if (!(breakpoint1 instanceof IErlangBreakpoint)) {
            continue;
        }
        final IErlangBreakpoint breakpoint = (IErlangBreakpoint) breakpoint1;
        final IMarker marker = breakpoint.getMarker();
        if (marker != null && marker.exists() && marker.getType().equals(markerType) && currentmarker.getId() != marker.getId()) {
            if (marker instanceof ErlangLineBreakpoint) {
                final ErlangLineBreakpoint erlangLineBreakpoint = (ErlangLineBreakpoint) marker;
                if (erlangLineBreakpoint.getLineNumber() == lineNumber) {
                    return erlangLineBreakpoint;
                }
            }
        }
    }
    return null;
}
Also used : ErlangLineBreakpoint(org.erlide.backend.debug.ErlangLineBreakpoint) IErlangBreakpoint(org.erlide.backend.debug.IErlangBreakpoint) IBreakpointManager(org.eclipse.debug.core.IBreakpointManager) IMarker(org.eclipse.core.resources.IMarker) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint)

Example 5 with ErlangLineBreakpoint

use of org.erlide.backend.debug.ErlangLineBreakpoint in project erlide_eclipse by erlang.

the class ErlangDebugTarget method breakpointAdded.

@Override
public void breakpointAdded(final IBreakpoint breakpoint) {
    if (supportsBreakpoint(breakpoint)) {
        try {
            if (breakpoint.isEnabled() && DebugPlugin.getDefault().getBreakpointManager().isEnabled() || !breakpoint.isRegistered()) {
                final ErlangLineBreakpoint erlangLineBreakpoint = (ErlangLineBreakpoint) breakpoint;
                erlangLineBreakpoint.install(this);
            }
        } catch (final CoreException e) {
            ErlLogger.error(e);
        }
    }
}
Also used : ErlangLineBreakpoint(org.erlide.backend.debug.ErlangLineBreakpoint) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

ErlangLineBreakpoint (org.erlide.backend.debug.ErlangLineBreakpoint)6 CoreException (org.eclipse.core.runtime.CoreException)4 IBreakpoint (org.eclipse.debug.core.model.IBreakpoint)4 IBreakpointManager (org.eclipse.debug.core.IBreakpointManager)3 IErlangBreakpoint (org.erlide.backend.debug.IErlangBreakpoint)2 IMarker (org.eclipse.core.resources.IMarker)1 IResource (org.eclipse.core.resources.IResource)1 DebugException (org.eclipse.debug.core.DebugException)1 ILineBreakpoint (org.eclipse.debug.core.model.ILineBreakpoint)1 IStackFrame (org.eclipse.debug.core.model.IStackFrame)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 ITextSelection (org.eclipse.jface.text.ITextSelection)1 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)1 ErlangDebugTarget (org.erlide.backend.debug.model.ErlangDebugTarget)1