CLion 2016.3 Help

Extract Define

Basics

The Extract Define refactoring method defines the selected set of tokens as macro using #define directive and replaces the set of tokens with macro call in the code; macro definition can be located in the current file or moved to the related header file.

Example

BeforeAfter
/help/img/idea/cl_extractDefineBefore.png
/help/img/idea/cl_extractDefineAfter.png

Extract define in-place

To perform Extract define in-place:

  1. In the editor, select the expression to be replaced with a macro call. You can do that yourself or use the smart expression selection feature to let CLion help you. So, do one of the following:
    • Highlight the expression. Then choose Refactor | Extract | Extract Define from the main or context menu.Alternatively, press Ctrl+Alt+D.
    • Place the cursor before or within the expression, choose Refactor | Extract | Extract Define from the main or context menu, or press Ctrl+Alt+D. In the Expression pop-up menu, select the expression by clicking the required expression. Alternatively, use the Up and Down arrow keys to navigate to the expression of interest, and then press Enter to select it.
  2. If more than one occurrence of the selected expression is found, select Replace this occurrence only or Replace all occurrences in the Multiple occurrences found pop-up menu.
    /help/img/idea/cl_extractDefineMultiple.png
    To select the required option, just click it. Alternatively, use the Up and Down arrow keys to navigate to the option of interest, and press Enter to select it.
  3. Select Put to header check box if you want to move macros definition to the header file.
  4. Specify the name of the macro. Do one of the following:
    • Select one of the suggested names from the pop-up list. To do that, double-click the suitable name. Alternatively, use the Up and Down arrow keys to navigate to the name of interest, and Enter to select it.
    • Edit the name by typing. The name is shown in the box with red borders and changes as you type. When finished, press Enter.
      /help/img/idea/cl_extractDefineMacroName.png

See Also

External Links:

Last modified: 22 November 2016