This would be nice: Quick Refactor

I'm often in a situation that I want to do simple refactorings but unable to find the right one quickly while browsing through the menu. I think this can be done in a much easier way. Let me give an example. Say I have a some code that looks like

if (time + interval < 60000)

I want to refactor the 60000 into a constant value in the class.

My ideal refactoring tool would work like this:

I select the 60000 and then hit Control-R. A popup appears and it shows ONLY those refactorings relevant for the current selection. In this case that would be:

  • Extract Method

  • Introduce variable

  • Introduce field

  • Introduce constant

  • Introduct parameter


I probably miss a few, but the key here is that only those refactorings are shown that you most likely want to use in the current context of the selection or caret position.

This is simple and elegant and very helpful to the user since you don't have to remember a lot of shortcuts for the above refactorings or move through a menu with a lot of options that are not relevant.



S.

10 comments
Comment actions Permalink

+1, I like the IDEA.

0
Comment actions Permalink

+1

"Stefan Arentz" <no_reply@jetbrains.com> wrote in message
news:32279178.1169717292094.JavaMail.itn@is.intellij.net...

I'm often in a situation that I want to do simple refactorings but unable
to find the right one quickly while browsing through the menu. I think
this can be done in a much easier way. Let me give an example. Say I have
a some code that looks like

>

if (time + interval < 60000)

>

I want to refactor the 60000 into a constant value in the class.

>

My ideal refactoring tool would work like this:

>

I select the 60000 and then hit Control-R. A popup appears and it shows
ONLY those refactorings relevant for the current selection. In this case
that would be:

>

  • Extract Method

  • Introduce variable

  • Introduce field

  • Introduce constant

  • Introduct parameter

>

I probably miss a few, but the key here is that only those refactorings
are shown that you most likely want to use in the current context of the
selection or caret position.

>

This is simple and elegant and very helpful to the user since you don't
have to remember a lot of shortcuts for the above refactorings or move
through a menu with a lot of options that are not relevant.

>
>
>

S.



0
Comment actions Permalink

+1

This should be an intention.

0
Comment actions Permalink

the key here is that only those refactorings are shown that you most likely want to use in the current context of the selection or caret position.

+1

Ahmed.

0
Comment actions Permalink

I remember submitting a very similar feature request in the old tracker,
alas it appears to have been lost in the mists of time.

Anyway +1 from me for something like this.

N.

Norris Shelton wrote:

+1

This should be an intention.

0
Comment actions Permalink

Hi Stefan,

my plugiin NaviActionPad ( http://naviactionpad.beeger.net/ ) goes into that direction, although it's not there yet. It works only for structure elements like fields, methods and classes, but from the beginning one of the driving ideas was to filter the list of refactorings and other actions like "Find Usages" to a list of applicable actions.

I don't know if it is possible with the current OpenAPI, but I'll look into this. That looks like a worthwhile addition.

Cheers,
Robert

0
Comment actions Permalink

I had proposed almost the exact same thing a couple years ago. And somebody else had proposed the same thing 2 years before that. I have included the my original post below. Click the link to see the previous discussion.

-Alex

-



Dec 16, 2004 10:04 PM
idea to improve useability of refactoring features
http://www.intellij.net/forums/thread.jspa?messageID=3431911&#3431911

Not sure if anyone suggested this before, but here goes...

I use the rename refactoring all the time; So much so that I have it bound
to ALT-R. I also use about 50% of the other refactorings, but for those I
always have to access the Refactor menu in the menubar of the right-click
popup menu. The problem with that Refactor menu is that it is starting to
become overwhelming with the number of options. What is confusing is that
the Refactor menu is not contextual -- All the refactor choices are
available even when they don't make sense. If you select a wrong item, it
does display an error message.

I would like the Refactor menu to dynamically disable items which
are not valid for the current context. I suppose there may be a
performance problem to doing this for the Refactor menu in the menubar but
the right-click popup menu should be able to do this.

What I really want is a new feature similar to the inline intention
popups; This inline popup would display all the refactor commands which
are valid for the current context: local variable, field, method, static
method, class, expression, blocks of code, etc.

For example, if you invoke it on a local variable in a method.



(if that is possible)



If you invoke it on a method


(if not static)
(if static)
(if static)



This feature would make it much easier to understand which Refactorings
are applicable in each context. Also, I would bind this inline popup
command to a keybinding so that with two keybindings I have access to the
Rename Refactoring (80%+ of my refactoring work) and then all the other
refactorings through the inline Refactor Popup Menu.

0

Please sign in to leave a comment.