CLion 2023.3 Help

Pull members up, push members down

The Pull Members Up refactoring allows you to move class members to a base class.

The Push Members Down refactoring helps you clean up the class hierarchy by moving class members to a subclass. The members are then relocated into the direct subclasses only.

Pull members up

  1. Select the members to be moved to a superclass.

  2. From the main or context menu, call Refactor | Pull Members Up.

    Pull members up
  3. In the Pull members up dialog, specify the following:

    • Select the superclass.

    • In the Member section, select the members to be moved.

      CLion will highlight the dependent members:

      Dependent class members
  4. Click Preview to check the changes before proceeding. CLion will notify you in case of problems:

    Problems detected during Pull Members Up
  5. Click Pull when ready.

Examples

Before

After

class BaseClass { int d1 = 0; static const int d2 = 1; }; class ChildClass: public BaseClass { char SomeChar = 'a'; long d22; void exFunc(int); //This method will be pulled up }; void ChildClass::exFunc(int) {};
class BaseClass { int d1 = 0; static const int d2 = 1; void exFunc(int); }; class ChildClass: public BaseClass { char SomeChar = 'a'; long d22; }; void BaseClass::exFunc(int) {};

Before

After

@interface SampleClass:NSObject /* This method will be pulled up */ - (int)IntSum:(int)num1 andNum2:(int)num2; @end @implementation SampleClass - (int)IntSum:(int)num1 andNum2:(int)num2 { int result = num1 = num2; return result; } @end
@interface BaseClass : NSObject - (int)IntSum:(int)num1 andNum2:(int)num2; @end @interface SampleClass : BaseClass @end @implementation BaseClass - (int)IntSum:(int)num1 andNum2:(int)num2 { int result = num1 = num2; return result; } @end

Before

After

class SuperClass: def super_method(self): pass class SubClassOne(SuperClass): # This function will be pulled up def my_method(self): pass
class SuperClass: def super_method(self): pass def my_method(self): pass class SubClassOne(SuperClass): pass

Push members down

  1. Select the members to be moved to a subclass.

  2. From the main or context menu, call Refactor | Push Members Down.

    Push members down
  3. In the Push Members Down dialog, specify the following:

    • In the Inheritor section, select the subclass.

    • In the Member section, select the members to be moved.

  4. Click Preview to check the changes before proceeding.

  5. Click Push when ready.

Examples

Before

After

class BaseClass { int d1 = 0; static const int d2 = 1; void exFunc(int); //This method will be pushed down }; class ChildClass: public BaseClass { char SomeChar = 'a'; long d22; }; void BaseClass::exFunc(int) {};
class BaseClass { int d1 = 0; }; class ChildClass: public BaseClass { char SomeChar = 'a'; long d22; static const int d2 = 1; void exFunc(int); }; void ChildClass::exFunc(int) {};

Before

After

@interface Superclass : NSObject { int v; int w; //This variable will be pushed down } - (void)initV; @end @implementation Superclass - (void)initV { v = 20; } @end @interface Subclass : Superclass
@interface Superclass : NSObject { int v; } - (void)initV; @end @implementation Superclass - (void)initV { v = 20; } @end @interface Subclass : Superclass { int w; }

Before

After

class SuperClass: # This function will be pushed down def super_method(self): pass class SubClassOne(SuperClass): def my_method(self): pass class SubClassTwo(SuperClass): def my_method(self): pass
class SuperClass: pass class SubClassOne(SuperClass): def my_method(self): pass def super_method(self): pass class SubClassTwo(SuperClass): def my_method(self): pass def super_method(self): pass
Last modified: 15 March 2024