IntelliJ IDEA 2018.2 Help

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

  1. Select an identifier that you want to refactor (for example, a class in the editor or a file in the Project tool window).

  2. Select Refactor | Copy (F5)

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

  1. Select an identifier that you want to refactor.

  2. Select Refactor | Move (or press F6).

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

  4. Specify a path to the target directory, a file name, and a package name.

goland move function

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.

goland move private identifiers
Last modified: 25 October 2018

See Also