CLion 2016.2 Help

Move Refactorings

On this page:

Move refactorings: basics

The Move refactorings allow you to move files, directories, class members and declarations within a project. 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

To move a file or directory to another directory, follow these steps:

  1. Select the file or directory in the Project tool window.
  2. Do one of the following:
    • On the main menu, choose Refactor, and then choose Move.
    • On the context menu of the selection, choose Refactor, and then choose 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 check box.

Moving a class member to another class, existing or new:

To move a class member to the new class, follow these steps:

  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, follow this steps:

  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:
cl_MoveDeclarationError1
As you can see, variable d3 here depends on variable d1. If you apply Move Declaration refactoring to the above class and try to select declaration of classSubCLass to be moved, and leave declaration of d1 at the initial position, CLion warns you about dependency:
cl_moveDeclarationError2
where declaration of d1 is highlighted with blue. The same rules are applicable to Move Members refactoring.

See Also

External Links:

Last modified: 22 November 2016