IntelliJ IDEA 14.0.0 Web Help

Evaluating Expressions

IntelliJ IDEA enables you to evaluate expressions and code fragments in the context of a stack frame currently selected in the Frames pane of the Debug window.

14.0+
In addition to regular expressions, you can also evaluate operator expressions, lambda expressions and anonymous classes.

The following evaluation modes are available:

  • Expression Mode for evaluating single-line expressions.
  • Code Fragment Mode for evaluating short code portions. You can evaluate declarations, assignments, loops and if/else.

Besides that, IntelliJ IDEA provides a way to quickly evaluate an expression in the editor at caret or a selection.

While using the Expression Evaluation feature, be aware of the following:

  • A method can be invoked within the Expression Evaluation dialog only if the debugger has stopped at a breakpoint, but has not been paused.
  • Expression Evaluation can only be "single-level". In other words, if IntelliJ IDEA stops at a breakpoint within a method called from the Expression Evaluation, you cannot use the Expression Evaluation feature again.
  • If a method invoked within the Expression Evaluation has a breakpoint inside its body, this breakpoint will be ignored.

To evaluate an expression or a code fragment in the context of a stack frame

  1. In the Frames pane, select the thread where you want an expression to be evaluated.
  2. Invoke the Evaluate Expression command in one of the following ways:
    • On the main menu, choose Run | Evaluate Expression
    • On the context menu of the editor, choose Evaluate Expression
    • Press Alt+F8
    • Click variables_evaluate_expr on the stepping toolbar of the Debug tool window
  3. Select an evaluation mode. If you want to evaluate a code fragment, click the Code Fragment Mode button.
  4. Depending on the selected mode, type the expression or statements to evaluate in the text field and click Evaluate.
    evaluate_expression

    If the specified expression cannot be evaluated, the possible reason will be briefly described in the Result pane of the dialog box.

    evaluate_expression_impossible

Note that during a debugger session, the value of any expression at caret is shown in the tooltip every time you hover your mouse pointer over it. If an expression contains children, clicking add expands the node and displays all children.

However, Quick evaluate expression helps you view the expression value using the keyboard only.

To quickly evaluate an expression in the editor

  • 14.0+
    By using the Show Value On Selection Change functionality:
    1. In the Debug tool window toolbar click the Settings icon projectToolWindowSettingsIcon and select the Show Value On Selection Change option from the popup menu.
    2. Select a code fragment with the mouse, or by clicking Ctrl+W. A tooltip with the expression value automatically appears under the selection and changes each time you change the selection:
      evaluate_selection
  • By manually invoking the tooltip with the expression value:
    1. Place the caret at the desired location, or select an expression to be evaluated.
    2. Press Ctrl+Alt+F8. The tooltip with the expression value appears under the selected expression.
      py_quickEvaluateExpression

See Also

Last modified: 4 December 2014
comments powered by Disqus