Refactor inner class to its own class

Answered

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?

8
7 comments

use "Move" refactoring

5

Move should suggest you to move inner class to upper level, does it? Thank you

2

Hello Michael,

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.

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?


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


10

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.

1

Hello Dmitry,

I see that you wrote this

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.

--
Dmitry Jemerov

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)
OSX 10.8.4

I've attached some screenshots showing the option doesn't exist in the refactor dialog. Thanks for taking a look!



Attachment(s):
ij4.png
ij3.png
ij2.png
ij1.png
0

Hi Josh,

i've created an issue. Feel free to vote.

Max Medvedev

0

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.

0

Please sign in to leave a comment.