Move Refactorings
In this section:
- Basics
- Moving a file or a directory to another directory
- Moving a class member to another class, existing or new:
- Moving a declaration
- Moving a declaration or member that influence the others
Basics
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
- Select the file or directory in the Project tool window.
- Do one of the following:
- On the main menu or the context menu of the selection, choose , and then choose .
- Press F6.
The dialog that opens depends on the type of the selected symbol.
- 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.
- 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:
- In the Editor or Structure view, select the class member to be moved
- Do one of the following:
- On the main menu, choose .
- On the context menu of the selection, choose
- Press F6.
- The dialog that opens depends on the type of the selected symbol.
- Type the destination class name or click the button to choose.
- Select the class members to be moved to the specified class.
Moving a declaration
To move a top level declaration to another file, follow this steps:
- In the editor or Structure view, select the declaration to be moved to another file.
- Do one of the following:
- On the main menu, choose .
- On the context menu of the selection, choose
- Press F6
- The dialog that opens depends on the type of the selected symbol.
- Type the destination file name or click the button to choose.
- Select the declaration to be moved to another file.
Moving a declaration or member that influence the others
Let's consider the following sample of code: As you can see, variabled3
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: where declaration of d1
is highlighted with blue. The same rules are applicable to Move Members refactoring. Last modified: 15 December 2017