To create a new variable from an
expression:
-
Place your cursor on the
expression which you would like to replace with a variable.
-
Right-click and select Refactor | Extract Variable -Or- press Alt+Shift+L. The Extract Local Variable dialog is launched.
Extract
Local Variable dialog
-
Enter the name
of the new variable in the Variable name field.
-
Mark the checkbox
so that all occurrences of the selected expression will be
replaced by references to the local variable.
-
Click OK
to apply your changes or click Preview
if you want to see a preview of the changes that this refactoring
will create.
-
If you clicked
preview a preview window will open with a changes tree showing
all the changes which will be made to reflect the extracting
of the variable.
Extract
Local Variable Preview dialog
-
The changes will
be listed according to the context within which they appear.
You can expand the nodes to see all changes within particular
files, classes or functions.
-
Use the Next /
Previous Change arrows to scroll
through all possible changes. Unmarking the checkboxes next to the changes will cause those
changes not to take effect.
-
Click OK
to apply the changes.
|