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
Please sign in to leave a comment.
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.
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.
Hello Sebastian,
Please try "Refactor | Move Inner Class to Upper Level"
Sorry just saw this is ItelliJ Forum. I use Webstorm. The option seems to be missing there?
@Sebastian What language do you use? Please provide more details on your case.
Oksana Chumak I use Typescript.
I wish I could go from:
@Sebastian Obentheuer As we discussed in https://intellij-support.jetbrains.com/hc/en-us/community/posts/360009307519-How-can-I-refactor-a-field-into-the-constructor-, there is no such Typescript refactoring; if you miss it, please feel free to file a feature request to https://youtrack.jetbrains.com/issues/WEB