Move and Copy refactorings
The Copy refactoring lets you create a copy of a class in a different package. It also lets you create a copy of a file, directory or package in a different directory or package.
Perform copy refactoring
- Select an identifier that you want to refactor (for example, a class in the editor or a file in the Project tool window).
- Select (F5)
- In the Copy window, specify the name and location for your copy, and click OK.
The Move refactoring lets you move packages and classes between the source roots of a project, class members to other classes and inner classes to upper hierarchy levels.
For example, you can perform the move refactoring on method or field if it is used more in another class than in its own class.
Perform move refactoring
- Select an identifier that you want to refactor.
- Select (or press F6).
- In the dialog that opens depending on the item you have selected for your refactoring, specify the appropriate options and click Refactor (OK for a package). You can also click Preview, if available, to preview the potential changes.
- Specify a path to the target directory, a file name, and a package name.
Move private identifiers
Sometimes when you move an identifier that is not exported (a private identifier), the identifier becomes inaccessible for the source package (from which we perform the move).
IntelliJ IDEA displays a notification when the identifier is private and is not exported during the move operation. Before you apply code changes, consider reviewing them by using the Preview button.