Search in sources :

Example 1 with EvaluationMode

use of com.intellij.xdebugger.evaluation.EvaluationMode 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)

Aggregations

Editor (com.intellij.openapi.editor.Editor)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 XExpression (com.intellij.xdebugger.XExpression)1 EvaluationMode (com.intellij.xdebugger.evaluation.EvaluationMode)1 XDebuggerEditorsProvider (com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider)1 XDebuggerEvaluator (com.intellij.xdebugger.evaluation.XDebuggerEvaluator)1 XStackFrame (com.intellij.xdebugger.frame.XStackFrame)1 XValue (com.intellij.xdebugger.frame.XValue)1