public void init() {
    XBreakpointManager manager = XDebuggerManager.getInstance(myProject).getBreakpointManager();
    manager.addBreakpointListener(
        new XBreakpointListener() {
          @Override
          public void breakpointAdded(@NotNull XBreakpoint xBreakpoint) {
            if (isJavaType(xBreakpoint)) {
              onBreakpointAdded(xBreakpoint);
            }
          }

          @Override
          public void breakpointRemoved(@NotNull XBreakpoint xBreakpoint) {
            onBreakpointRemoved(xBreakpoint);
          }

          @Override
          public void breakpointChanged(@NotNull XBreakpoint xBreakpoint) {
            Breakpoint breakpoint = myBreakpoints.get(xBreakpoint);
            if (breakpoint != null) {
              fireBreakpointChanged(breakpoint);
            }
          }
        });
  }
  private static void removeJSBreakpointsInDartFiles(final Project project) {
    final XBreakpointManager breakpointManager =
        XDebuggerManager.getInstance(project).getBreakpointManager();
    final Collection<XBreakpoint<?>> toRemove = new ArrayList<XBreakpoint<?>>();

    for (XBreakpoint<?> breakpoint : breakpointManager.getAllBreakpoints()) {
      final XSourcePosition position = breakpoint.getSourcePosition();
      if (position != null
          && position.getFile().getFileType() == DartFileType.INSTANCE
          && !(breakpoint.getType() instanceof DartLineBreakpointType)) {
        toRemove.add(breakpoint);
      }
    }

    if (!toRemove.isEmpty()) {
      ApplicationManager.getApplication()
          .runWriteAction(
              new Runnable() {
                public void run() {
                  for (XBreakpoint<?> breakpoint : toRemove) {
                    breakpointManager.removeBreakpoint(breakpoint);
                  }
                }
              });
    }
  }
 public boolean isEnabled(@NotNull final Project project, final AnActionEvent event) {
   XLineBreakpointType<?>[] breakpointTypes = XDebuggerUtil.getInstance().getLineBreakpointTypes();
   final XBreakpointManager breakpointManager =
       XDebuggerManager.getInstance(project).getBreakpointManager();
   for (XSourcePosition position :
       XDebuggerUtilImpl.getAllCaretsPositions(project, event.getDataContext())) {
     for (XLineBreakpointType<?> breakpointType : breakpointTypes) {
       final VirtualFile file = position.getFile();
       final int line = position.getLine();
       if (breakpointType.canPutAt(file, line, project)
           || breakpointManager.findBreakpointAtLine(breakpointType, file, line) != null) {
         return true;
       }
     }
   }
   return false;
 }
 private void updateGutter() {
   if (myVisible) {
     if (isValid()) {
       final XBreakpointManager breakpointManager =
           XDebuggerManager.getInstance(myProject).getBreakpointManager();
       breakpointManager.updateBreakpointPresentation(
           (XLineBreakpoint) myXBreakpoint, getIcon(), null);
     }
     // RangeHighlighter highlighter = myHighlighter;
     // if (highlighter != null && highlighter.isValid() && isValid()) {
     //  AppUIUtil.invokeLaterIfProjectAlive(myProject, new Runnable() {
     //    @Override
     //    public void run() {
     //      if (isValid()) {
     //        setupGutterRenderer(myHighlighter);
     //      }
     //    }
     //  });
     // }
     // else {
     //  DebuggerManagerEx.getInstanceEx(myProject).getBreakpointManager().removeBreakpoint(this);
     // }
   }
 }
Exemplo n.º 5
0
  public void testXDebugger() throws Exception {
    final WorkingContextManager manager = getContextManager();
    final XBreakpointManager breakpointManager =
        XDebuggerManager.getInstance(getProject()).getBreakpointManager();

    ApplicationManager.getApplication()
        .runWriteAction(
            new Runnable() {
              public void run() {
                XLineBreakpointImpl<XBreakpointProperties> breakpoint =
                    (XLineBreakpointImpl<XBreakpointProperties>)
                        breakpointManager.addLineBreakpoint(
                            new XsltBreakpointType(), "foo", 0, null);

                final String name = "foo";
                manager.saveContext(name, null);
                breakpointManager.removeBreakpoint(breakpoint);
              }
            });
    manager.loadContext("foo");
    XBreakpoint<?>[] breakpoints = breakpointManager.getAllBreakpoints();
    assertEquals(1, breakpoints.length);
    manager.clearContext();
  }
  /**
   * Toggle line breakpoint with editor support: - unfolds folded block on the line - if folded,
   * checks if line breakpoints could be toggled inside folded text
   */
  @NotNull
  public static Promise toggleLineBreakpoint(
      @NotNull Project project,
      @NotNull XSourcePosition position,
      @Nullable Editor editor,
      boolean temporary,
      boolean moveCarret) {
    int lineStart = position.getLine();
    VirtualFile file = position.getFile();
    // for folded text check each line and find out type with the biggest priority
    int linesEnd = lineStart;
    if (editor != null) {
      FoldRegion region = FoldingUtil.findFoldRegionStartingAtLine(editor, lineStart);
      if (region != null && !region.isExpanded()) {
        linesEnd = region.getDocument().getLineNumber(region.getEndOffset());
      }
    }

    final XBreakpointManager breakpointManager =
        XDebuggerManager.getInstance(project).getBreakpointManager();
    XLineBreakpointType<?>[] lineTypes = XDebuggerUtil.getInstance().getLineBreakpointTypes();
    XLineBreakpointType<?> typeWinner = null;
    int lineWinner = -1;
    for (int line = lineStart; line <= linesEnd; line++) {
      int maxPriority = 0;
      for (XLineBreakpointType<?> type : lineTypes) {
        maxPriority = Math.max(maxPriority, type.getPriority());
        final XLineBreakpoint<? extends XBreakpointProperties> breakpoint =
            breakpointManager.findBreakpointAtLine(type, file, line);
        if (breakpoint != null && temporary && !breakpoint.isTemporary()) {
          breakpoint.setTemporary(true);
        } else if (type.canPutAt(file, line, project) || breakpoint != null) {
          if (typeWinner == null || type.getPriority() > typeWinner.getPriority()) {
            typeWinner = type;
            lineWinner = line;
          }
        }
      }
      // already found max priority type - stop
      if (typeWinner != null && typeWinner.getPriority() == maxPriority) {
        break;
      }
    }

    if (typeWinner != null) {
      XSourcePosition winPosition =
          (lineStart == lineWinner) ? position : XSourcePositionImpl.create(file, lineWinner);
      if (winPosition != null) {
        Promise<XLineBreakpoint> res =
            XDebuggerUtilImpl.toggleAndReturnLineBreakpoint(
                project, typeWinner, winPosition, temporary, editor);

        if (editor != null && lineStart != lineWinner) {
          int offset = editor.getDocument().getLineStartOffset(lineWinner);
          ExpandRegionAction.expandRegionAtOffset(project, editor, offset);
          if (moveCarret) {
            editor.getCaretModel().moveToOffset(offset);
          }
        }
        return res;
      }
    }

    return PromiseKt.rejectedPromise();
  }