CLion 2016.3 Help

Extract Superclass

Basics

The Extract Superclass refactoring enables extracting certain members of a class into a superclass.

Example

BeforeAfter
/help/img/idea/cl_extractSuperclassBefore.png
/help/img/idea/cl_extractSuperclassAfter.png

To extract a superclass

  1. Select the desired class in one of the views, or just open it in the editor.
  2. On the on the main menu or on the context menu, choose Refactor | Extract | Superclass.
  3. In the Extract Superclass dialog box that appears, specify the following information:
    • Name of the new superclass.
    • Members to be included in the superclass
      /help/img/idea/cl_extractSuperclassDialog.png
  4. Proceed with the refactoring.

Extracting the class dependent members

Let's consider the following sample of code:
/help/img/idea/cl_extractSuperclassError1.png
As you can see, there is a dependency between array a and variable exRes. If you apply Extract Superclass refactoring to the above class and try to select exRes to be moved, and leave a in the base class, CLion highlights the problem member in Extract Superclass dialog, as following:
/help/img/idea/cl_extractSuperclassError2.png

Trying to proceed with extract, you will get the following warning message:

/help/img/idea/cl_extractSuperclassError3.png

Choose Continue to ignore the problem and proceed with refactoring, or Cancel to return back and resolve it. Also you can observe the conflict in Find Tool Window.

See Also

Last modified: 22 November 2016