Search in sources :

Example 6 with XSourcePosition

use of com.intellij.xdebugger.XSourcePosition in project intellij-community by JetBrains.

the class XBreakpointUtil method toggleLineBreakpoint.

/**
   * 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<XLineBreakpoint> toggleLineBreakpoint(@NotNull Project project, @NotNull XSourcePosition position, @Nullable Editor editor, boolean temporary, boolean moveCaret, boolean canRemove) {
    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());
            XLineBreakpoint<? extends XBreakpointProperties> breakpoint = breakpointManager.findBreakpointAtLine(type, file, line);
            if ((type.canPutAt(file, line, project) || breakpoint != null) && (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, canRemove);
            if (editor != null && lineStart != lineWinner) {
                int offset = editor.getDocument().getLineStartOffset(lineWinner);
                ExpandRegionAction.expandRegionAtOffset(project, editor, offset);
                if (moveCaret) {
                    editor.getCaretModel().moveToOffset(offset);
                }
            }
            return res;
        }
    }
    return rejectedPromise();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FoldRegion(com.intellij.openapi.editor.FoldRegion) XSourcePosition(com.intellij.xdebugger.XSourcePosition) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with XSourcePosition

use of com.intellij.xdebugger.XSourcePosition in project intellij-community by JetBrains.

the class XBreakpointItem method doUpdateDetailView.

@Override
public void doUpdateDetailView(DetailView panel, boolean editorOnly) {
    XBreakpointBase breakpoint = (XBreakpointBase) myBreakpoint;
    Project project = breakpoint.getProject();
    //saveState();
    if (myPropertiesPanel != null) {
        myPropertiesPanel.dispose();
        myPropertiesPanel = null;
    }
    if (!editorOnly) {
        myPropertiesPanel = new XLightBreakpointPropertiesPanel(project, getManager(), breakpoint, true);
        panel.setPropertiesPanel(myPropertiesPanel.getMainPanel());
    }
    XSourcePosition sourcePosition = myBreakpoint.getSourcePosition();
    if (sourcePosition != null && sourcePosition.getFile().isValid()) {
        showInEditor(panel, sourcePosition.getFile(), sourcePosition.getLine());
    } else {
        panel.clearEditor();
    }
    if (myPropertiesPanel != null) {
        myPropertiesPanel.setDetailView(panel);
        myPropertiesPanel.loadProperties();
        myPropertiesPanel.getMainPanel().revalidate();
    }
}
Also used : Project(com.intellij.openapi.project.Project) XLightBreakpointPropertiesPanel(com.intellij.xdebugger.impl.breakpoints.ui.XLightBreakpointPropertiesPanel) XSourcePosition(com.intellij.xdebugger.XSourcePosition)

Example 8 with XSourcePosition

use of com.intellij.xdebugger.XSourcePosition in project intellij-community by JetBrains.

the class XBreakpointFileGroupingRule method getGroup.

public XBreakpointFileGroup getGroup(@NotNull final B breakpoint, @NotNull final Collection<XBreakpointFileGroup> groups) {
    if (!(breakpoint instanceof XLineBreakpoint)) {
        return null;
    }
    XSourcePosition position = ((XLineBreakpoint) breakpoint).getSourcePosition();
    if (position == null)
        return null;
    VirtualFile file = position.getFile();
    for (XBreakpointFileGroup group : groups) {
        if (group.getFile().equals(file)) {
            return group;
        }
    }
    return new XBreakpointFileGroup(file);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XSourcePosition(com.intellij.xdebugger.XSourcePosition) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint)

Example 9 with XSourcePosition

use of com.intellij.xdebugger.XSourcePosition in project intellij-community by JetBrains.

the class XDebuggerEvaluateActionHandler method showDialog.

private static void showDialog(@NotNull XDebugSession session, VirtualFile file, XDebuggerEditorsProvider editorsProvider, XStackFrame stackFrame, XDebuggerEvaluator evaluator, @NotNull XExpression expression) {
    if (expression.getLanguage() == null) {
        Language language = null;
        if (stackFrame != null) {
            XSourcePosition position = stackFrame.getSourcePosition();
            if (position != null) {
                language = LanguageUtil.getFileLanguage(position.getFile());
            }
        }
        if (language == null && file != null) {
            language = LanguageUtil.getFileTypeLanguage(file.getFileType());
        }
        expression = new XExpressionImpl(expression.getExpression(), language, expression.getCustomInfo(), expression.getMode());
    }
    new XDebuggerEvaluationDialog(session, editorsProvider, evaluator, expression, stackFrame == null ? null : stackFrame.getSourcePosition()).show();
}
Also used : Language(com.intellij.lang.Language) XExpressionImpl(com.intellij.xdebugger.impl.breakpoints.XExpressionImpl) XSourcePosition(com.intellij.xdebugger.XSourcePosition) XDebuggerEvaluationDialog(com.intellij.xdebugger.impl.evaluate.XDebuggerEvaluationDialog)

Example 10 with XSourcePosition

use of com.intellij.xdebugger.XSourcePosition in project intellij-community by JetBrains.

the class XToggleLineBreakpointActionHandler method isEnabled.

@Override
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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XBreakpointManager(com.intellij.xdebugger.breakpoints.XBreakpointManager) XLineBreakpointType(com.intellij.xdebugger.breakpoints.XLineBreakpointType) XSourcePosition(com.intellij.xdebugger.XSourcePosition)

Aggregations

XSourcePosition (com.intellij.xdebugger.XSourcePosition)40 VirtualFile (com.intellij.openapi.vfs.VirtualFile)20 Project (com.intellij.openapi.project.Project)9 Nullable (org.jetbrains.annotations.Nullable)8 XLineBreakpoint (com.intellij.xdebugger.breakpoints.XLineBreakpoint)6 PsiFile (com.intellij.psi.PsiFile)5 NotNull (org.jetbrains.annotations.NotNull)5 Document (com.intellij.openapi.editor.Document)4 XDebugSession (com.intellij.xdebugger.XDebugSession)4 PsiElement (com.intellij.psi.PsiElement)3 XStackFrame (com.intellij.xdebugger.frame.XStackFrame)3 Editor (com.intellij.openapi.editor.Editor)2 FileEditor (com.intellij.openapi.fileEditor.FileEditor)2 FileEditorManagerImpl (com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl)2 Ref (com.intellij.openapi.util.Ref)2 TextRange (com.intellij.openapi.util.TextRange)2 XBreakpoint (com.intellij.xdebugger.breakpoints.XBreakpoint)2 XDebuggerEvaluator (com.intellij.xdebugger.evaluation.XDebuggerEvaluator)2 XValue (com.intellij.xdebugger.frame.XValue)2 VMPausedException (org.intellij.plugins.xsltDebugger.VMPausedException)2