Code refactorings are used to restructure your existing code without changing its external behaviour. The most popular is probably the Rename refactoring, which changes the name of a variable, method, class, etc. Refactoring is an essential technique to maintain the quality of your code, make it more readable and easier to maintain and reuse.
CLion offers you a set of code refactorings, which track down and correct the affected code references automatically. This means you can always be sure that your project will work correctly, even after large-scale changes. The list of refactorings available in CLion includes:
- Rename (
Shift+F6) renames symbols, automatically correcting all references in the code for you.
- Change Signature (
Cmd+F6on OS X) helps you add/remove/reorder function parameters, change the result type or update the name of the function, all usages will be fixed as well.
- Move (
F6) moves files or directories, as well as methods, variables or constants.
- Copy (
F5) allows you to create a copy of file or directory.
- Safe Delete (
Cmd+Delete Forwardon OS X) safely removes files and symbols from your code.
- Inline (
Alt+Cmd+Non OS X) replaces redundant variable usage/method calls with its initializer/declaration.
- Extract refactoring – CLion analyses the block of code where the refactoring was invoked, detects input and output variables, together with the usages of the selected expression to replace them with the newly created:
- Variable (
Alt+Cmd+Von OS X)
- Constant (
Alt+Cmd+Con OS X)
- Parameter (
Alt+Cmd+Pon OS X)
- Typedef (
Alt+Cmd+Kon OS X)
- Define (
Alt+Cmd+Don OS X)
- Method (
Alt+Cmd+Mon OS X)
- Variable (
- Pull Members Up safely moves class members to a superclass.
- Push Members Down safely moves class members to a subclass.
You can use Refactor This (
Ctrl+Alt+Shift+T on Windows/Linux,
Ctrl+T on OS X) to get the list of the refactorings available in the current scope.
Watch CLion’s refactorings in action:
Develop with pleasure,
The CLion Team