Search in sources :

Example 1 with XDebuggerEditorsProvider

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

the class XDebuggerEvaluateActionHandler method perform.

@Override
protected void perform(@NotNull final XDebugSession session, final DataContext dataContext) {
    final XDebuggerEditorsProvider editorsProvider = session.getDebugProcess().getEditorsProvider();
    final XStackFrame stackFrame = session.getCurrentStackFrame();
    final XDebuggerEvaluator evaluator = session.getDebugProcess().getEvaluator();
    if (evaluator == null) {
        return;
    }
    Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
    EvaluationMode mode = EvaluationMode.EXPRESSION;
    String selectedText = editor != null ? editor.getSelectionModel().getSelectedText() : null;
    if (selectedText != null) {
        selectedText = evaluator.formatTextForEvaluation(selectedText);
        mode = evaluator.getEvaluationMode(selectedText, editor.getSelectionModel().getSelectionStart(), editor.getSelectionModel().getSelectionEnd(), CommonDataKeys.PSI_FILE.getData(dataContext));
    }
    Promise<String> expressionTextPromise = Promise.resolve(selectedText);
    if (selectedText == null && editor != null) {
        expressionTextPromise = getExpressionText(evaluator, CommonDataKeys.PROJECT.getData(dataContext), editor);
    }
    final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
    EvaluationMode finalMode = mode;
    XValue value = XDebuggerTreeActionBase.getSelectedValue(dataContext);
    expressionTextPromise.done(expressionText -> {
        if (expressionText == null && value != null) {
            value.calculateEvaluationExpression().done(expression -> {
                if (expression != null) {
                    AppUIUtil.invokeOnEdt(() -> showDialog(session, file, editorsProvider, stackFrame, evaluator, expression));
                }
            });
        } else {
            XExpression expression = XExpressionImpl.fromText(StringUtil.notNullize(expressionText), finalMode);
            AppUIUtil.invokeOnEdt(() -> showDialog(session, file, editorsProvider, stackFrame, evaluator, expression));
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XDebuggerEvaluator(com.intellij.xdebugger.evaluation.XDebuggerEvaluator) EvaluationMode(com.intellij.xdebugger.evaluation.EvaluationMode) XExpression(com.intellij.xdebugger.XExpression) Editor(com.intellij.openapi.editor.Editor) XDebuggerEditorsProvider(com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider) XStackFrame(com.intellij.xdebugger.frame.XStackFrame) XValue(com.intellij.xdebugger.frame.XValue)

Example 2 with XDebuggerEditorsProvider

use of com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider in project google-cloud-intellij by GoogleCloudPlatform.

the class BreakpointConfigurationPanel method loadFrom.

@Override
public void loadFrom(@NotNull XLineBreakpoint<CloudLineBreakpointProperties> breakpoint) {
    XBreakpointBase lineBreakpointImpl = breakpoint instanceof XBreakpointBase ? (XBreakpointBase) breakpoint : null;
    Breakpoint javaBreakpoint = BreakpointManager.getJavaBreakpoint(breakpoint);
    CloudLineBreakpointType.CloudLineBreakpoint cloudBreakpoint = null;
    if (javaBreakpoint instanceof CloudLineBreakpointType.CloudLineBreakpoint) {
        cloudBreakpoint = (CloudLineBreakpointType.CloudLineBreakpoint) javaBreakpoint;
    }
    if (cloudBreakpoint == null || lineBreakpointImpl == null) {
        return;
    }
    XDebuggerEditorsProvider debuggerEditorsProvider = cloudLineBreakpointType.getEditorsProvider(breakpoint, cloudBreakpoint.getProject());
    if (debuggerEditorsProvider != null) {
        treePanel = new XDebuggerTreePanel(cloudBreakpoint.getProject(), debuggerEditorsProvider, this, breakpoint.getSourcePosition(), "GoogleCloudTools.BreakpointWatchContextMenu", null);
        List<XExpression> watches = new ArrayList<XExpression>();
        for (String watchExpression : breakpoint.getProperties().getWatchExpressions()) {
            watches.add(debuggerEditorsProvider.createExpression(((XBreakpointBase) breakpoint).getProject(), new DocumentImpl(watchExpression), getFileTypeLanguage(breakpoint), EvaluationMode.EXPRESSION));
        }
        rootNode = new WatchesRootNode(treePanel.getTree(), this, watches.toArray(new XExpression[watches.size()]));
        treePanel.getTree().setRoot(rootNode, false);
        watchPanel.removeAll();
        watchPanel.add(watchLabel, BorderLayout.NORTH);
        treePanel.getTree().getEmptyText().setText("There are no custom watches for this snapshot location.");
        final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(treePanel.getTree()).disableUpDownActions();
        decorator.setToolbarPosition(ActionToolbarPosition.RIGHT);
        decorator.setAddAction(new AnActionButtonRunnable() {

            @Override
            public void run(AnActionButton button) {
                executeAction(XDebuggerActions.XNEW_WATCH);
            }
        });
        decorator.setRemoveAction(new AnActionButtonRunnable() {

            @Override
            public void run(AnActionButton button) {
                executeAction(XDebuggerActions.XREMOVE_WATCH);
            }
        });
        CustomLineBorder border = new CustomLineBorder(CaptionPanel.CNT_ACTIVE_BORDER_COLOR, SystemInfo.isMac ? 1 : 0, 0, SystemInfo.isMac ? 0 : 1, 0);
        decorator.setToolbarBorder(border);
        watchPanel.add(decorator.createPanel(), BorderLayout.CENTER);
    }
}
Also used : XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) Breakpoint(com.intellij.debugger.ui.breakpoints.Breakpoint) AnActionButtonRunnable(com.intellij.ui.AnActionButtonRunnable) XBreakpointBase(com.intellij.xdebugger.impl.breakpoints.XBreakpointBase) XDebuggerTreePanel(com.intellij.xdebugger.impl.ui.tree.XDebuggerTreePanel) ArrayList(java.util.ArrayList) XDebuggerEditorsProvider(com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) AnActionButton(com.intellij.ui.AnActionButton) CustomLineBorder(com.intellij.ui.border.CustomLineBorder) WatchesRootNode(com.intellij.xdebugger.impl.ui.tree.nodes.WatchesRootNode) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) XExpression(com.intellij.xdebugger.XExpression) CloudLineBreakpointType(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType)

Aggregations

XExpression (com.intellij.xdebugger.XExpression)2 XDebuggerEditorsProvider (com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider)2 CloudLineBreakpointType (com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType)1 Breakpoint (com.intellij.debugger.ui.breakpoints.Breakpoint)1 Editor (com.intellij.openapi.editor.Editor)1 DocumentImpl (com.intellij.openapi.editor.impl.DocumentImpl)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 AnActionButton (com.intellij.ui.AnActionButton)1 AnActionButtonRunnable (com.intellij.ui.AnActionButtonRunnable)1 ToolbarDecorator (com.intellij.ui.ToolbarDecorator)1 CustomLineBorder (com.intellij.ui.border.CustomLineBorder)1 XLineBreakpoint (com.intellij.xdebugger.breakpoints.XLineBreakpoint)1 EvaluationMode (com.intellij.xdebugger.evaluation.EvaluationMode)1 XDebuggerEvaluator (com.intellij.xdebugger.evaluation.XDebuggerEvaluator)1 XStackFrame (com.intellij.xdebugger.frame.XStackFrame)1 XValue (com.intellij.xdebugger.frame.XValue)1 XBreakpointBase (com.intellij.xdebugger.impl.breakpoints.XBreakpointBase)1 XDebuggerTreePanel (com.intellij.xdebugger.impl.ui.tree.XDebuggerTreePanel)1 WatchesRootNode (com.intellij.xdebugger.impl.ui.tree.nodes.WatchesRootNode)1 ArrayList (java.util.ArrayList)1