Search in sources :

Example 1 with XLineBreakpointManager

use of com.intellij.xdebugger.impl.breakpoints.XLineBreakpointManager in project intellij-community by JetBrains.

the class ToggleBreakpointEnabledAction method findLineBreakpoints.

@NotNull
private static Set<XLineBreakpoint> findLineBreakpoints(AnActionEvent e) {
    Project project = e.getProject();
    Editor editor = e.getData(CommonDataKeys.EDITOR);
    if (project == null || editor == null)
        return Collections.emptySet();
    XBreakpointManagerImpl breakpointManager = (XBreakpointManagerImpl) XDebuggerManager.getInstance(project).getBreakpointManager();
    XLineBreakpointManager lineBreakpointManager = breakpointManager.getLineBreakpointManager();
    Document document = editor.getDocument();
    Collection<Range<Integer>> lineRanges = new ArrayList<>();
    for (Caret caret : editor.getCaretModel().getAllCarets()) {
        lineRanges.add(new Range<>(document.getLineNumber(caret.getSelectionStart()), document.getLineNumber(caret.getSelectionEnd())));
    }
    Collection<XLineBreakpointImpl> breakpoints = lineBreakpointManager.getDocumentBreakpoints(document);
    HashSet<XLineBreakpoint> res = new HashSet<>();
    for (XLineBreakpointImpl breakpoint : breakpoints) {
        int line = breakpoint.getLine();
        for (Range<Integer> range : lineRanges) {
            if (range.isWithin(line)) {
                res.add(breakpoint);
            }
        }
    }
    return res;
}
Also used : XLineBreakpointImpl(com.intellij.xdebugger.impl.breakpoints.XLineBreakpointImpl) XLineBreakpointManager(com.intellij.xdebugger.impl.breakpoints.XLineBreakpointManager) Document(com.intellij.openapi.editor.Document) Range(com.intellij.util.Range) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) XBreakpointManagerImpl(com.intellij.xdebugger.impl.breakpoints.XBreakpointManagerImpl) Project(com.intellij.openapi.project.Project) Editor(com.intellij.openapi.editor.Editor) Caret(com.intellij.openapi.editor.Caret) HashSet(com.intellij.util.containers.HashSet) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Caret (com.intellij.openapi.editor.Caret)1 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 Project (com.intellij.openapi.project.Project)1 Range (com.intellij.util.Range)1 HashSet (com.intellij.util.containers.HashSet)1 XLineBreakpoint (com.intellij.xdebugger.breakpoints.XLineBreakpoint)1 XBreakpointManagerImpl (com.intellij.xdebugger.impl.breakpoints.XBreakpointManagerImpl)1 XLineBreakpointImpl (com.intellij.xdebugger.impl.breakpoints.XLineBreakpointImpl)1 XLineBreakpointManager (com.intellij.xdebugger.impl.breakpoints.XLineBreakpointManager)1 NotNull (org.jetbrains.annotations.NotNull)1