コード例 #1
0
ファイル: DebuggerUtilsEx.java プロジェクト: jared2501/test
 @NotNull
 @Override
 public Navigatable createNavigatable(@NotNull Project project) {
   if (ALTERNATIVE_SOURCE_KEY.get(myFile) != null) {
     return new OpenFileDescriptor(project, getFile(), getLine(), 0);
   }
   return XSourcePositionImpl.doCreateOpenFileDescriptor(project, this);
 }
コード例 #2
0
  /**
   * 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();
  }