コード例 #1
0
 public void dispose() {
   final KeyStroke[] treeStrokes = getRegisteredKeyStrokes();
   for (KeyStroke stroke : treeStrokes) {
     unregisterKeyboardAction(stroke);
   }
   myBreakpointManager.removeBreakpointManagerListener(myNodeUpdateListener);
 }
コード例 #2
0
 public boolean canMoveTo(@Nullable final SourcePosition position) {
   if (position == null || !position.getFile().isValid()) {
     return false;
   }
   final PsiFile psiFile = position.getFile();
   final Document document = PsiDocumentManager.getInstance(getProject()).getDocument(psiFile);
   if (document == null) {
     return false;
   }
   final int spOffset = position.getOffset();
   if (spOffset < 0) {
     return false;
   }
   final BreakpointManager breakpointManager =
       DebuggerManagerEx.getInstanceEx(getProject()).getBreakpointManager();
   return breakpointManager.findBreakpoint(document, spOffset, getCategory()) == null;
 }
コード例 #3
0
  @Override
  protected void onNodeStateChanged(final CheckedTreeNode node) {
    final Object descriptor = node.getUserObject();
    final Breakpoint breakpoint;
    if (descriptor instanceof BreakpointDescriptor) {
      breakpoint = ((BreakpointDescriptor) descriptor).getBreakpoint();
      if (myBreakpointManager.findMasterBreakpoint(breakpoint) != null) {
        return;
      }
    } else {
      breakpoint = null;
    }

    if (breakpoint != null) {
      myBreakpointManager.setBreakpointEnabled(breakpoint, node.isChecked());
    }
  }
コード例 #4
0
 @Override
 public void reload() {
   ApplicationManager.getApplication().assertReadAccessAllowed();
   final XSourcePosition position = myXBreakpoint.getSourcePosition();
   try {
     final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(position.getFile());
     mySourcePosition = SourcePosition.createFromOffset(psiFile, position.getOffset());
   } catch (Exception e) {
     mySourcePosition = null;
   }
   reload(BreakpointManager.getPsiFile(myXBreakpoint, myProject));
 }
コード例 #5
0
 public BreakpointTree(final Project project) {
   super(new BreakpointTreeCellRenderer(), new CheckedTreeNode(new RootDescriptor()));
   myRootNode = (CheckedTreeNode) getModel().getRoot();
   myDescriptorToNodeMap.put((TreeDescriptor) myRootNode.getUserObject(), myRootNode);
   myBreakpointManager = DebuggerManagerEx.getInstanceEx(project).getBreakpointManager();
   myNodeUpdateListener =
       new BreakpointManagerListener() {
         public void breakpointsChanged() {
           repaint();
         }
       };
   myBreakpointManager.addBreakpointManagerListener(myNodeUpdateListener);
   getEmptyText().setText(XDebuggerBundle.message("debugger.no.breakpoints"));
 }
コード例 #6
0
  public static boolean canAddLineBreakpoint(
      Project project, final Document document, final int lineIndex) {
    if (lineIndex < 0 || lineIndex >= document.getLineCount()) {
      return false;
    }
    final BreakpointManager breakpointManager =
        DebuggerManagerEx.getInstanceEx(project).getBreakpointManager();
    final LineBreakpoint breakpointAtLine =
        breakpointManager.findBreakpoint(
            document, document.getLineStartOffset(lineIndex), CATEGORY);
    if (breakpointAtLine != null) {
      // there already exists a line breakpoint at this line
      return false;
    }
    PsiDocumentManager.getInstance(project).commitDocument(document);

    final boolean[] canAdd = new boolean[] {false};
    XDebuggerUtil.getInstance()
        .iterateLine(
            project,
            document,
            lineIndex,
            new Processor<PsiElement>() {
              @Override
              public boolean process(PsiElement element) {
                if ((element instanceof PsiWhiteSpace)
                    || (PsiTreeUtil.getParentOfType(element, PsiComment.class, false) != null)) {
                  return true;
                }
                PsiElement child = element;
                while (element != null) {

                  final int offset = element.getTextOffset();
                  if (offset >= 0) {
                    if (document.getLineNumber(offset) != lineIndex) {
                      break;
                    }
                  }
                  child = element;
                  element = element.getParent();
                }

                if (child instanceof PsiMethod
                    && child.getTextRange().getEndOffset()
                        >= document.getLineEndOffset(lineIndex)) {
                  PsiCodeBlock body = ((PsiMethod) child).getBody();
                  if (body == null) {
                    canAdd[0] = false;
                  } else {
                    PsiStatement[] statements = body.getStatements();
                    canAdd[0] =
                        statements.length > 0
                            && document.getLineNumber(statements[0].getTextOffset()) == lineIndex;
                  }
                } else {
                  canAdd[0] = true;
                }
                return false;
              }
            });

    return canAdd[0];
  }