Extracting Variables

The refactoring feature can create a local variable to replace a given expression.

 

 

Instructions on how to complete a procedure

To create a new variable from an expression:

  1. Place your cursor on the expression which you would like to replace with a variable.

  2. Right-click and select Refactor | Extract Variable
    -Or- press Alt+Shift+L.
    The Extract Local Variable dialog is launched.

  1. Ensure the name of the variable which you would like to create is entered in the Variable name field.

  2. Mark the checkbox so that all occurrences of the selected expression will be replaced by references to the local variable.

  3. Click OK to apply your changes or click Preview if you want to see a preview of the changes that this refactoring will create.

  4. 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.

  1. The changes will be listed according to the context within which they appear. You can therefore expand the nodes to see all changes within particular files, classes or functions.

  2. 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.

  3. Click OK to apply the changes.

The variable will be extracted and the relevant changes made to the code.

 

 

Related Links

Related Links:
Refactoring

Using Refactoring

Renaming Files

Renaming Elements

Moving Files

Organizing Includes