New refactorings
CLion Nova adds the following new refactorings to the CLion refactoring set:
Introduce Field
This refactoring creates a new field based on the selected expression, initializes it with the expression or from the constructor, and replaces the occurrences of the expression with references to the newly introduced field.
To invoke this refactoring, press Ctrl+Alt+F.
In the example below, we use this refactoring to replace two occurrences of the same string with a new private field and initialize it from the existing constructor:
Introduce Namespace Alias
This refactoring helps you create a namespace alias for a namespace usage and replace the currently selected usage or all usages in the current file with the alias. Depending on the selected usages, the namespace alias is declared in the closest possible scope to the usages.
Invoke Introduce Namespace Alias
Place the caret at a namespace usage, press Ctrl+Alt+Shift+T, and then select Introduce namespace alias in the Refactor This popup.
If there are multiple occurrences of the namespace usage in the document, you will be able to choose whether to replace the current usage or all usages.
In the example below, we use this refactoring to add a namespace alias for the SpaceOne::SpaceTwo
namespace.
Introduce Using Enum
The C++20 using enum
syntax allows you to add all the enumerators from the target enumeration. As a result, you can omit repetitions of the enumeration name when using its member enumerators.
Invoke Introduce Using Enum
Place the caret at a namespace usage, press Ctrl+Alt+Shift+T, and then select Introduce Using Enum in the Refactor This popup.
CLion Nova also detects the code pieces where
using enum
is applicable and suggests the refactoring in the Alt+Enter menu:If there are multiple occurrences of the enumeration usage in the document, choose whether to replace the current usage or all usages:
CLion Nova will perform the refactoring in-place:
Convert to Scoped Enum
The Convert to Scoped Enum refactoring helps you convert a C-style enumeration declaration into a C++11 scoped enumeration.
To invoke it, place the caret at an enumerator, press Ctrl+Alt+Shift+T and select Convert to Scoped Enum.