What's the IDEA way to move a class into a different file?

In languages like Groovy and Scala, it's common to have multiple public classes in one file. Therefore the need arises to move a class from one file to another. Does IDEA support this? "Move class" refactoring only offers "to package" and "make inner class of".

Cheers,
Peter

7 comments
Comment actions Permalink

As you know, Java doesn't allow more than one public class per file, so what did you have in mind, if not moving a class to the package level?

0
Comment actions Permalink

What I have in mind are languages like Groovy and Scala that don't have a "one public class per file" limitation.

0
Comment actions Permalink

IOC - you're actually editing Groovy and Scala code... the penny has dropped.

Sorry, I thought you were after something like that, for Java...  

0
Comment actions Permalink

There's currently no way to do it. You can move class to the same
directory and then manually copy/paste it to the target file. I can
hardly imagine a UI for moving class into a file.

0
Comment actions Permalink

One way would be to select a target file as in "Go To File". Another way would be "move into same file as class ...".
Since moving to a different file might mean a package change, refactoring support is helpful.

0
Comment actions Permalink

In the "Move" dialog that takes place upon drag-and-drop, where it asks if you are moving to a new package or to become an inner class of the target class, add a third option (present only for Groovy or Scala classes) to move to the same file as the target class.   Same with the F6 move.  Simple.

Speaking as someone doing quite a bit of Scala and Groovy (and indeed rarely doing straight Java anymore), this is getting more necessary to me every day.   Almost to the point of coding up my own refactoring plugin.

--Dave Griffith

0

Please sign in to leave a comment.