Refactor to move a class to its own file

Answered

If I add a second class to a file, then the system objects so is there a tool/refactor option that lets me select the class in the IDE and then have the system create a new file with the same name as the class and move the class's code into that new file ?

Thanks

7 comments
Comment actions Permalink

Just use the Move Refactor (F6 or Refactor > Move from the menu) with your cursor on the second class name. After promoting it, you will likely want to make the class public.

0
Comment actions Permalink

Is it possible that this suggests a new file with the same name as the class I want to move?

 

When I "Move..." the "TO:" field holds the old file name, so I always have to write the new name by hand.

0
Comment actions Permalink

Hello Sebastian,

Please try "Refactor | Move Inner Class to Upper Level"

0
Comment actions Permalink

Sorry just saw this is ItelliJ Forum. I use Webstorm. The option seems to be missing there? 

0
Comment actions Permalink

@Sebastian What language do you use? Please provide more details on your case.

0
Comment actions Permalink

Oksana Chumak I use Typescript.

I wish I could go from:

class Foo {
do() {
bar.do2();
}
}


// to this


class Foo {
constructor(public bar:any){}
do() {
this.bar.do2()
}
}
0

Please sign in to leave a comment.