CLion 2018.2 Help

Move and Copy refactorings

Move refactorings allow you to move packages and classes between the source roots of a project, class members to other classes and inner classes to upper hierarchy levels. The move refactorings automatically correct all references to the moved packages, classes and members in the source code.

The following move refactorings are available:

  • Move Class refactoring enables you to:
    • Move a class to a package under the specified source root.

    • Make a class an inner class.

  • Move Static Members moves a static field, method or inner class to another class.

  • Move Inner to Upper Level:
    • In Java, this refactoring moves an inner class to a higher level.

    • In ActionScript, this refactoring moves out-of-package classes, functions, variables, constants and namespaces into a package. (In this case the word inner is used to refer to entities (classes, functions, etc.) that are declared outside of packages. The upper level means a package.)

  • Move Instance Method refactoring moves an instance method to another class.

  • Move File refactoring moves a file to another directory.

The Move refactorings allow you to move files, directories, class members and declarations within a project. So doing, CLion tracks these movements and automatically corrects all references to the moved symbols in the source code.

The following Move refactorings are available:

  • The Move File refactoring moves a file to another directory.

  • The Move Directory refactoring moves a directory to another directory.

  • The Move Member refactoring moves the selected class member to a new or an existing class.

  • The Move Declaration refactoring moves the top level type declaration to a new or an existing file.

Moving a file or a directory to another directory

  1. Select the file or directory in the Project tool window.

  2. Do one of the following:
    • On the main menu, choose Refactor | Move.

    • On the context menu of the selection, choose Refactor | Move

    • Press F6.

    The dialog that opens depends on the type of the selected symbol.

  3. In the To directory field, specify the folder to move the selected file or folder to. Choose an existing folder from the drop-down list or type the full path to the parent folder to be created.

  4. To have the references to the selected file or folder updated according to the refactoring result, select the Search for references checkbox.

Moving a class member to another class, existing or new

To move a class member to the new class:

  1. In the Editor or Structure view, select the class member to be moved

  2. Do one of the following:
    • On the main menu, choose Refactor | Move.

    • On the context menu of the selection, choose Refactor | Move

    • Press F6.

    • The dialog that opens depends on the type of the selected symbol.

  3. Type the destination class name or click the browseButton button to choose.

  4. Select the class members to be moved to the specified class.

    cl moveMembersDialog

Moving a declaration

To move a top level declaration to another file:

  1. In the editor or Structure view, select the declaration to be moved to another file.

  2. Do one of the following:
    • On the main menu, choose Refactor | Move.

    • On the context menu of the selection, choose Refactor | Move

    • Press F6

    • The dialog that opens depends on the type of the selected symbol.

  3. Type the destination file name or click the browseButton button to choose.

  4. Select the declaration to be moved to another file.

    cl moveDeclarationDialog

Moving a declaration or member that influence the others

Let's consider the following sample of code:
int d1; class ExClass { static const int d2 = 1; int d3 = d2 * d1; };
As you can see, variable d3 here depends on variable d1. If you apply Move Declaration refactoring to the above class, the declaration of d1 will be highlighted with blue:
cl move dependancy
If you select the declaration of d1 to be moved, you will get a warning message:
cl move warning
The same is applicable to Move Declaration refactoring.

Copy refactoring

The Copy refactoring lets you create a copy of a class, file or directory in a different or the same directory.

To perform the Copy refactoring:

  1. Select the item of interest in a tool window (e.g. the Project tool window). Alternatively, open the necessary class or file in the editor.

  2. Do one of the following:
    • Choose Refactor | Copy on the main menu or the context menu.

    • Press F5.

    • In the Project tool window, press and hold the Ctrl key, and drag the item to the target location.

  3. In the Copy dialog that opens, specify the name and location for the copy that you are creating, and click OK.

Last modified: 27 November 2018

See Also

External Links: