Java Reference
In-Depth Information
With this in mind, you can make a call to the method you wish you had, and let the
intention actions stub it out for you. It's amazing how much repetitive work like
defining variables, casting objects from collections, and importing packages can
be eliminated by relying on the intention features of
IDEA
to do the grunt work.
Counting on intention actions quickly becomes a natural and efficient way to
program. Instead of trying to understand all the methods, instance variables,
and other elements up front, you can let intention actions define them as you
need them.
3.8.5
Choosing an intention action to execute
When you see the intention action alert, your next step is
to select which, if any, intention action you want to per-
form.
IDEA
never tries to fix the code for you without
your approval. To review
IDEA
's suggestions and accept
an intention action, click the light bulb icon or press
Alt+
Enter
to view the suggestion list.
IDEA
will present a list of
possible intention actions via a drop-down menu sourced
from the light bulb icon. Only intention actions that will
result in valid code are shown in the list. In figure 3.28,
we're trying to assign a value to an undeclared field.
In this example, there are four possible intention
actions from which to select. Use the mouse or keyboard
to select one of them, and
IDEA
will automatically implement the changes.
Although most conditions are applicable to only one or two intention actions, this
situation has four possible solutions. Briefly, the four options in our example will
perform the following actions:
Figure 3.28 When you
select an option from the
intention action drop-
down, IDEA will modify
your code to implement
the suggested fix.
Create Field
—Creates a new boolean field called
status
■
Create Local Variable
—Creates a new boolean local variable called
status
■
Create Parameter
—Adds a new boolean parameter called
status
to the
method
■
Rename Reference
—Changes the assignment to another, existing boolean
reference in scope
■
Select the option that matches your intended purpose for the code. If none is
appropriate, you can press
Escape
to close the intention action list and leave the
code unchanged, or you can make your own changes.