extract common members from two classes

Hi,

What is the easiest way to extract common members from two classes into new superclass?

For example, I wont turn:

class A {
   pirvate String fieldName;
   private String someOtherA;
   //getters/setters here
}


class B {
  private String fieldName;
  private String someOtherB;
   //getters/setters here
}


into:

class Basic {
     private String fieldName;
        //getters/setters here
}

class A extends  Basic {
  private String someOtherA;
      //getters/setters here
}


class B extends  Basic {
  private String someOtherB;
  //getters/setters here
}


?

I tried to select both A and B in project tree and then Refactor->Generify, Generify Obejcts, but it doesn't see any common fields.

Best regards, Eugene.

2 comments
Comment actions Permalink

I don't think Generify Obejects does what you want it to do.  If you look here,  You'll see that Generify Objects refers to converting things away from Java.lang.Object into more specific classes.  I feel like this commonality is something you might have to do manually, though if someone does know a way to do it I'd love to learn it :)

Cheers,
Frank

0
Comment actions Permalink

I just came across the same use case, which is quite common in legacy code and should be really supported imho.

I think I'll open an issue if it's not already in YouTrack...

0

Please sign in to leave a comment.