Instant Rename and Rename Refactoring

During the last weeks I have got  a few questions about rename refactoring and some users also complain to me that the refactoring in NetBeans 6.x was much faster. So I would like to explain the situation.

For some people, who don't know, Instant Rename action and Rename Refactoring  can look like one action. But it's not true, even if  both actions use the same shortcut (CTRL + R). NetBeans 6.x contained only Instant Rename action (speaking about PHP support), which we can mark as very simple rename refactoring through one file.

From NetBeans 7.0 the Instant Rename action works only in "non public" context. It means that this action is used for fast renaming variables that has local context like inside a method, or for renaming private methods and fields that can not be used outside of the scope, where they are declared.

From user point of view these two action can be simply recognized. When is after CTRL+R called Instant Rename action, then the identifier is surrounded with rectangle and you can rename it directly in the file. It's fast and simple, also the usages of this identifier are renamed in the same time as you write.

The picture below shows Instant Rename action for $message identifier, that is visible only in the print_test method and due this after CTRL+R is called Instant Rename.

In NetBeans 7.0, there was added Rename Refactoring that is called for public identifiers. It means for identifiers that could be used in other files. If you press CTRL+R shortcut when the caret is inside $hello identifier from the picture above, NetBeans recognizes that $hello is declared / used in a global context and calls the Rename Refactoring that brings a dialog to change the name of the identifier. From this dialog you have to preview suggested changes, through pressing Preview button and then execute the refactoring through Do Refactoring button.

Yes, it's more complicated from user point of view than Instant Rename, but in Rename Refactoring NetBeans can change more files at once. It should be  the developer responsibility to decide whether the suggested changes are right and the refactoring can be executed or in some files original name should be kept.

Someone can argue that he doesn't use $hello variable in any other file so Instant Rename could be used in such case. Yes it's true, but in such case NetBeans has to know all usages of all identifiers and keep this informations up to date during editing a file. I'm sure that this is not possible due to the performance problems, mainly for big projects. So the usages are computed after pressing the Preview button.

And why is the Refactor button always disabled in the Rename dialog and user has to always go through the preview phase? NetBeans has API and SPI for implementing refactoring actions and this dialog is a part of this infrastructure. If you rename an identifier for example in Java, the Refactor buttons is enabled, but Java is strongly type language and you can be almost in 99% sure that the IDE will suggest the right results. In PHP as a dynamic language, we can not be sure, what NetBeans finds is only a "guess". This is why NetBeans pushes developers to preview the changes for PHP rename.

I hope that I have explain it clearly. I'm open to any discussion. What I have described above is situation in NetBeans 7.0, 7.0.1 and probably it will be also in NetBeans 7.1, because there is no plan to change it. Please write your opinion here.

Comments:

Most of the time I don't need refactoring over the entire project. Please introduce a shortcut for the Instant Rename, because I really miss this feature and have downgraded back to 6.9.

Posted by kvz on June 27, 2011 at 10:53 AM CEST #

I really miss the old functionality of 6.9. I also want back the Instant Rename back, I used it a lot.

Posted by Jaime Suez on June 27, 2011 at 12:49 PM CEST #

I think that the old functionality is used more often than the new one.

I also really mis the old functionality, please keep the possibility of using Instant Rename.

Posted by Jaime Suez Musalem on June 27, 2011 at 12:51 PM CEST #

I don't expect NB to know when a variable is only used in one file, but when I know it I would like the ability to choose an instant rename--i.e. using a different hotkey or something.

I very rarely set a variable in one file then use it another--so refactoring a variable name is a very rare occurrence. The only time I would need, and want, to do refactoring is when I change a the name of a class/method/function.

So instant rename is something I would use far more frequently than refactoring, and whilst I don't refactor often, when I do it's a great feature to have.

Posted by guest on June 28, 2011 at 02:48 AM CEST #

I might be wrong, but isn't Ctrl+R assigned to "rename refactoring" by default? I think I had to change the shortcut from "Refactor -> Rename" to "Other -> Rename" to get the old functionality back.

Guest, as for using variables in files where they are not defined (i.e., defining variable in one file and using in another) - don't you use OOP with class extending? If you do, then public/protected class members are often defined in one file and accessed in another. For private/local functions and variables "Instant rename" worked fine for me.

Posted by binaryLV on June 28, 2011 at 06:55 AM CEST #

Instant rename was much faster than refactoring. Pleas add shortcut for instant rename.

Posted by guest on June 28, 2011 at 08:29 AM CEST #

I'm happy with the new "global" refactorings even so i don't care for it for variables (I don't use global scope variables in multiples files).

My only real grief with the refactoring is that it seems to ignore the "Test Files" folder for renaming.

Posted by edo on June 30, 2011 at 02:46 AM CEST #

@edo: Regarding the refactoring of occurrences in tests, I created new issue: http://netbeans.org/bugzilla/post_bug.cgi . Thanks.

Posted by Petr Pisl on June 30, 2011 at 04:44 AM CEST #

=== I really miss the old functionality of 6.9. I also want back the Instant Rename back, I used it a lot.

=== instant rename is something I would use far more frequently than refactoring, and whilst I don't refactor often, when I do it's a great feature to have.

Me too, and probably many other "little developers"

Posted by guest on July 07, 2011 at 12:39 PM CEST #

I miss the instant rename as well. The rename refactoring is used quite sparsely so a shortcut to explicitly call the instant rename would be much appreciated.

Thanks

Posted by Ziad on August 09, 2011 at 04:46 AM CEST #

I like the new rename feature but I also need and use the Instant Rename. Instant Rename doesn't scan all my project files, just the current one, so there is no need to have a cache or whatever about the variables used. Just current file. I would love to have a Ctrl-Shift-R for Instant Rename on the file I have right now: if it's a View, i want it to be applied to all the file! If its a Method in a class, only on the method scope, on the file I have open. For me, this makes sense.

Posted by luislobo on September 01, 2011 at 02:43 PM CEST #

I also would love to have a shortcut like Ctrl+Shift+R for the Instant Rename. I'm stuck with a very very old project... no OOP in there...

Posted by guest on November 28, 2011 at 04:31 PM CET #

Please return Intant Rename feature. I used this a lot, and think lack of swift keyboard navigation in Rename Refactoring is cumbersome.

Posted by guest on March 27, 2012 at 12:02 PM CEST #

there is instant rename in other, you just have to attach key shortcut and you can use it in "old style"

Posted by guest on June 13, 2012 at 08:40 PM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

This blogs is written by NetBeans developers who contribute to the PHP support mainly.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today