[ANN] Type Refactoring

Hi,

I'm prowd to announce the first public beta version of the Type
Refactoring plug-in.

What it does
-


It lets you change the type of a (local) variable without breaking the code.
Example:

Select the local variable 'items', invoke "Refactor|Change Variable
Type" and you should be able to change the type to List.


Thanks for all, who contributed hints for the implementation.

--
Cheers,
Tom

18 comments
Comment actions Permalink


Oooh, I do believe this is the first plugin to add onto IDEA's refactoring menu. Even I'm not that gutsy (yet). How do you get any coding done if you need both hands just to carry around your testicles.

Seriously though, a few questions:

1)It looks as though you are limiting the types shown based on usages (cool). Since you're limiting yourself to locals, I figure that you're doing so by traversing the containing PsiMethod, and doing an expected type calculation for each actual usage. If you instead used the PsiSearchHelper to find usages, you could find all usages globally. That way you could do fields, and even method returns.

2) It looks odd to have the current type of the variable in the type list, particularly if you can't select it.

3) I'd go for a drop-down menu rather than a scrolling list for displaying possible types. If you do that, ignore the previous point.

Very cool.

--Dave Griffith



0
Comment actions Permalink

Oooh, I do believe this is the first plugin to add onto IDEA's
refactoring menu. Even I'm not that gutsy (yet). How do you get any
coding done if you need both hands just to carry around your
testicles.


Haha, you did not just say that...

Tobin

0
Comment actions Permalink

1)It looks as though you are limiting the types shown based on usages (cool). Since you're limiting yourself to locals, I figure that you're doing so by traversing the containing PsiMethod, and doing an expected type calculation for each actual usage. If you instead used the PsiSearchHelper to find usages, you could find all usages globally. That way you could do fields, and even method returns.


Well, it requires a PsiVariable (excl. PsiParameter to avoid method
changes). But you pointed me to an important issue: return values; these are
not handled yet.

2) It looks odd to have the current type of the variable in the type list, particularly if you can't select it.


You are right.

3) I'd go for a drop-down menu rather than a scrolling list for displaying possible types. If you do that, ignore the previous point.


Could you please give me hint, how to display such a pop-up (like the one in
the live-templates)? Thanks in advance.

Tom

0
Comment actions Permalink

I've uploaded a new version, which supports return statements and fields.
Also, it defines Ctrl-Shift T as the default short-cut.

Tom

0
Comment actions Permalink

Tom

Also, it defines Ctrl-Shift T as the default short-cut.

>

Why not make it an intention?

Alain

0
Comment actions Permalink

Good question. Why not make, e.g. Rename or Change Method signature
intentions, too?

Tom

0
Comment actions Permalink

I've uploaded a new version, which should work in much more situations.

Tom

0
Comment actions Permalink

Thomas Singer (MoTJ) wrote:

> Good question. Why not make, e.g. Rename or Change Method signature
intentions, too?


The only "cons" of your suggestion/question is that the intention would
show up in too many places. That's relative, and could be customized.


A long long time ago, prior to the tracker, I suggested another solution:

  • As soon as the user start editing the name of a renamable item

, the rename refactoring is triggered, and the dialog pops up.

  • If 'Esc' is pressed, the current behaviour is implemented,

and the user can keep editing the name.


Alain

0
Comment actions Permalink

In article <csdj5l$jn1$1@is.intellij.net>,
Alain Ravet <alain.ravet@biz.tiscali.be> wrote:

Thomas Singer (MoTJ) wrote:

> Good question. Why not make, e.g. Rename or Change Method signature
intentions, too?


The only "cons" of your suggestion/question is that the intention would
show up in too many places. That's relative, and could be customized.


A long long time ago, prior to the tracker, I suggested another solution:

  • As soon as the user start editing the name of a renamable item

, the rename refactoring is triggered, and the dialog pops up.


noooo... please enough popup dialogs, you want to show the yellow bulb
ok, but don't pop anything up.

R

0
Comment actions Permalink


Robert

>>A long long time ago, prior to the tracker, I suggested another
solution:
>> * As soon as the user start editing the name of a renamable item
>> , the rename refactoring is triggered, and the dialog pops up.
>
>noooo... please enough popup dialogs, you want to show the yellow bulb
>ok, but don't pop anything up.


1: this should be optional.
2: there is no way to rename anything without a dialog, so my suggestion
doesn't add anything that's not there. It just changes the way to
trigger it.

3: actually, my suggestion could be implemented in a way that avoids the
current dialog, and makes the whole process smoother :

Example: you want to rename 'foo' into 'fooBar':

 = 12 ;
      ...
]]>


Currently, you have to
- press
- move the caret to the right position (**1)
- type "Bar"
- press

My way:
- type "Bar"
- press

Visually, as soon as you've typed the first char - 'B' -, a thin
rectangle, and a different background colour could appear around the
item you are renaming, showing you that IDEA is in control, but with a
minimal bothering.

Alain

0
Comment actions Permalink

My dog ate the footnote; here it is:

- press
- move the caret to the right position (**1)




**1: another forgotten 2+years old request:
"F6/Rename : preserve caret position"
http://www.intellij.net/tracker/idea/viewSCR?publicId=4497

It's really as easy to implement as it is useful: see the StringEditorPlugin

Alain

0
Comment actions Permalink

Hello Alain,

**1: another forgotten 2+years old request:
"F6/Rename : preserve caret position"
http://www.intellij.net/tracker/idea/viewSCR?publicId=4497


I agree, this is an enhancement I've wished for a number of times!

It's really as easy to implement as it is useful: see the
StringEditorPlugin


Speaking of which, does the StringEditor intention have a shortcut key?
If not, is it possible to configure one? I couldn't find anything from a
quick look in the keyboard configuration.

Thanks,

-tt


0
Comment actions Permalink

Taras

Speaking of which, does the StringEditor intention have a shortcut key?



It's an intention, so you can either:
- click the bulb,
or
- press Alt-Enter


Alain

0
Comment actions Permalink

Hello Alain,

>> Speaking of which, does the StringEditor intention have a shortcut
>> key?
>>

It's an intention, so you can either:
- click the bulb,
or
- press Alt-Enter


The inconvenience is that the "String editor" intention is second in the
pop-up intention list.
The first entry on my Irida installation is "Replace + with .append()", which
I rarely use.

This is a small inconvenience, to be sure, but I wanted to check I wasn't
missing a keyboard shortcut.

Thanks again for the StringEditor plugin.
I might try an alternative version when I get some time to read up on the
Swing EditorKit.

-tt

0
Comment actions Permalink

Taras

>
>> - press Alt-Enter
>
>

The inconvenience is that the "String editor" intention is second in
the pop-up intention list.
The first entry on my Irida installation is "Replace + with
.append()", which I rarely use.

>

This is a small inconvenience, to be sure, but I wanted to check I
wasn't missing a keyboard shortcut.

>


I would also like to change the order, but I don't know if it can be
done through the openAPI.

On the other hand,
"Alt-Enter" + "Down"
is easy enough, and free keys shortcuts are too precious to be wasted
on this.


Alain

0
Comment actions Permalink

Great stuff Tom! Very useful.
One thing though, I keep wanting to change the type from the type of the declaration, not the variable.
e.g.:
Arr]]>ayList list = new ArrayList();

Can you enable it there too?

Cheers,
Bas


0
Comment actions Permalink

Should work now in build 0.2.2.

Tom

0
Comment actions Permalink

Great! Thanks.

Bas

0

Please sign in to leave a comment.