Extract Variable refactoring

The Extract Variable refactoring wraps a selected expression into a variable. It adds a new variable declaration and uses the expression as an initializer. Select an expression and press &shortcut:IntroduceVariable; (Refactor | Extract/Introduce | Variable).

Extract variable

This will result in the following:

Extract variable