Refractor extract class to an already created class?

So i extracted a class from class A to B mainly int's and strings, but i noticed i forgot a few in class A, how do i move them to class B that i allready made ?

I've tried move (F6) but it does not seem to work (is not static) :(

I tried to search for extract class or extract to class, but im not sure im supposed to extract ?

and is there any live chat that people use to help with intellij or should i just post here?

1 comment

As far as I know, there is not a direct way to do what you want. But there is away it can be done in a few step.

  1. Extract the missed class members from A to to a new class B2
  2. Edit B2 so it extends B
  3. In B2, execute a "Pull Members Up" refactoring. Pull all the members in B2 up to B
  4. In B2, place your cursor on the class name and execute a "Use Interface Where Possible Refactoring". Select B in the "Change usages of B2 to:" area of the refactoring dialog. Click Refactor
    • A "Rename variables" dialog will open. Select to rename A.b2 to b where 'b' is the same name of the field of your original 'B' field from when you extracted members from A to B. Click OK.
  5. In Class A, there will be duplicate fields named 'b'. One will be a new B() declaration, and the other a new B2() declaration. Delete the B2 one.
  6. Safe delete class B2. There should not be any other uses of it and therefore it should delete safely.


As for a chat area for help/support, I am unaware of any.

0

Please sign in to leave a comment.