Java Reference
In-Depth Information
and selecting
Include
or pressing the
Insert
key. If, on the other hand, your
review of the proposed change causes you to rethink your decision, click
Cancel
to abort the refactoring. To execute the refactoring, click
Do Refactor
.
Undoing your changes
So you've just done a massive refactoring, and you realize that you didn't know
the code as well as you thought you did and what you've done has made things
worse. Before you panic, rest assured that
IDEA
's compound undo mechanism
supports its refactoring features. Press
Ctrl+Z
or select
Edit | Undo
to back out
the refactoring changes and restore the code to its previous state.
9.4.2
Renaming code symbols to improve readability
At first glance, you may not think that the seemingly simple act of renaming a
code symbol would fall under the jurisdiction of refactoring, but consider the
implications. Assigning appropriate and meaningful names to your classes, vari-
ables, and constants is the first step in creating readable code. Moreover, creating
understandable code is the first step in building a maintainable system.
IDEA
allows you to rename any of your Java code's symbols, including the following:
Packages
■
Classes
■
Methods
■
Fields (instance and static class variables)
■
Local variables
■
Method parameters
■
Non-Java files
■
Renaming a code symbol through the refactoring system is easy. Start by placing
the cursor on the symbol you wish to rename. You can rename a symbol from any
reference point in any file, not just its declaration; thus, you don't have to go to a
method's declaration, or even its containing class, to rename it—you can rename
it directly from within a calling class. Either way, the operation is the same. You
can even call the
Refactor | Rename
command from within the
Project
view by
selecting the file or package you wish to rename.
Once you've selected the symbol you wish to rename, select
Refactor |
Rename
from the menu or press
Shift+F6
to activate the
Rename
dialog, as
shown in figure 9.14. Alternatively, you can right-click a symbol in the editor or in
any of
IDEA
's tool windows, including the
Project
and
Structure
views, and select