IntelliJ IDEA 2018.3 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 tool window.

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, IntelliJ IDEA provides a way to quickly evaluate an expression at caret or a selection in the editor.

While using the Expression Evaluation feature, mind the following:

  • A method can be invoked within the Evaluate 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 Expression Evaluation has a breakpoint inside its body, this breakpoint will be ignored.

Evaluating expressions using the dedicated dialog

To evaluate expressions or code fragments in 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 Evaluate expression on the Stepping toolbar in 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.
    ij evaluate expression

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

    ij evaluate expression impossible

To evaluate arbitrary expressions

  1. Open the Evaluate Expression dialog box in one of the following ways:
    • Choose Run | Evaluate Expression on the main menu.

    • PressAlt+F8.

    • To evaluate a specific variable, select it on the Variables pane of the Debug tool window, then choose Run | Evaluate Expression or press Alt+F8.

  2. In the Evaluate Expression dialog box, specify the expression you want to evaluate. Do one of the following:
    • In the Expression field, type the expression in question or choose one of the previously evaluated expressions from the drop-down list.

      If you have selected a specific variable on the Variables pane, this variable will be displayed in the Expression text box.

    • To evaluate a code fragment, click the Code Fragment Mode button and fill in the Code Fragment text box.

      To return to the original mode, click the Expression mode button.

  3. Click the Evaluate button. The Result read-only field shows the evaluation output. If the specified expression cannot be evaluated, the Result field explains the reason.

Evaluating expressions in the editor

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

ij evaluate selection

You can also use the Quick Evaluate expression functionality that lets you view the value of an expression using the keyboard only.

There are two ways to evaluate an expression quickly:

Show value tooltip on code selection

  1. In the Debugger | Data Views settings page, enable the Show value tooltip on code selection option.

  2. Select a code fragment with the mouse, or by pressing Ctrl+W. A tooltip with the expression value automatically appears under the selection and changes each time you change the selection.

    evaluate selection

Manually invoke the tooltip with the expression value

  1. Place the caret at the desired location, or select an expression to be evaluated.

  2. Choose Run | Quick Evaluate Expression on the main menu, or press Ctrl+Alt+F8. The tooltip with the expression value appears under the selected expression.

    ij quick evaluate expression

Last modified: 1 February 2019

See Also