Java Reference
In-Depth Information
doesn't make any sense to copy a method or variable.) To initiate a copy opera-
tion, use the
Refactor | Copy
command (
F5
) on the file/class or directory/pack-
age you want to copy. If you're editing a file and select this operation from the
Refactor
or context menu in the editor, the class file you're editing is copied.
When you copy a file or directory containing something other than Java code,
a copy is just that—a simple copy operation, during which you're prompted to
select a name for the copy. When you copy a class or package, however, something
much more interesting happens. When you select the name for the new class or
package,
IDEA
automatically makes the necessary adjustments to the source files,
including changing the class and package declarations and changing the
import
statements as required.
You're even free to copy classes across package boundaries. If you do, and the
original class uses other classes from its package, they're imported into the new
class appropriately.
IDEA
watches for situations that would make the copy opera-
tion illegal. For example, if the source class accesses package local methods, these
aren't accessible to the new class, and
IDEA
isn't shy about telling you so.
You can use the
Cut
,
Copy
, and
Paste
clipboard operations as shortcuts
to the copy and move refactoring operations. Select the class or package
to refactor in the
Project
window, and then use the appropriate clip-
board command on it. A
Copy
and
Paste
works like the
Copy
refactor-
ing, and a
Cut
and
Paste
works like the
Move
refactoring.
TIP
Moving classes between packages
Moving classes, files, packages, and directories works just like the
Copy
and
Delete
operations. It's the logical equivalent of performing a copy of an item and
then deleting the original. To move something, select the item (or items) to
move, and then execute the
Refactor | Move
command either from the main
menu or through the context menu (or press
F6
). When prompted, provide the
new name and destination package. The
Move
command is available from the
context menus of the
Project
,
Commander
, and
Structure
windows, like the
Copy
and
Delete
commands. Once you enter the destination and accept the
move operation,
IDEA
handles making all the necessary changes to the affected
source files.
You can move or delete multiple files in one operation, but you can only
copy files one at a time!
TIP