An Oracle blog about NetBeans for PHP

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.

Join the discussion

Comments ( 14 )
  • kvz Monday, June 27, 2011

    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.

  • Jaime Suez Monday, June 27, 2011

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

  • Jaime Suez Musalem Monday, June 27, 2011

    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.

  • guest Tuesday, June 28, 2011

    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.

  • binaryLV Tuesday, June 28, 2011

    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.

  • guest Tuesday, June 28, 2011

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

  • edo Thursday, June 30, 2011

    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.

  • Petr Pisl Thursday, June 30, 2011

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

  • guest Thursday, July 7, 2011

    === 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"

  • Ziad Tuesday, August 9, 2011

    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.


  • luislobo Thursday, September 1, 2011

    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.

  • guest Monday, November 28, 2011

    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...

  • guest Tuesday, March 27, 2012

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

  • guest Wednesday, June 13, 2012

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

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.