Refactor inner class to its own class Follow
This seems like an oversight but there doesn't appear to be any way to refactor an inner class to be its own class. There is a "Extract Class..." option in the refactor menu which sounded promising but it appears to be aimed at extracting a handul of methods/members to be their own class. You can select the inner class to be extracted but it won't let you choose the same name for the extracted class as the inner class. Which is wrong because it won't share a name with the inner class after it is extracted.
Is there a refactor option somewhere that lets you extract an inner class to be its own class?
Please sign in to leave a comment.
use "Move" refactoring
Move should suggest you to move inner class to upper level, does it? Thank you
Press F6 when the caret is on the inner class. The name of the refactoring
is "Move inner to upper level", and it has always existed in the product.
"Develop with Pleasure!"
Thanks for the information. It seemed intuitive to use "Extract class" for this so was trying to get that to do what I wanted. Didn't think about trying move.
I see that you wrote this
a few years ago. However, it appears to no longer be valid, at least not for Groovy source! I would like to accomplish this refactoring, but I don't get an "Move inner to upper level" option in the move dialog. I have a good number of classes (~10, possibly more once I'm finished with the code sketch) to move out of a class, and this refactoring would save me a good deal of repetative and boring work. Creating a class, cutting the innerclass and pasting it into the new file, possibly updating imports...yawn.
Here are my versions:
IntelliJ 12.1.4 build #IU-129.713
Oracle JDK 1.6.0_39 (64)
I've attached some screenshots showing the option doesn't exist in the refactor dialog. Thanks for taking a look!
i've created an issue. Feel free to vote.
For anyone still looking for this, I think the refactor is called "Move to Outer Scope" in the current version. It shows in the F6 dialog as well as under Refactor > Refactor This (^T) > Move to Outer Scope.