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

0
7 comments
Avatar
Permanently deleted user

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.

2

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.

2
Avatar
Yaroslav Bedrov

Hello Sebastian,

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

0

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

0

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

0

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.