Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch rename of methods using IntelliJ IDEA

I have a class with many (approximately 40) methods with names in SCREAMING_CASE_LIKE_THIS.

Is there a quick way, perhaps via the code analysis/inspections, to rename all of these to more idiomatic names in camelCaseLikeThis?

like image 389
Drew Noakes Avatar asked Jan 07 '13 23:01

Drew Noakes


People also ask

How do I rename a method in IntelliJ?

Press Shift+F6 or from the main menu, select Refactor | Rename. next to the highlighted element. You can press Tab to open the context menu and select the additional rename options. If you want to see the Rename dialog with more options, click the More options link or press Shift+F6 .

How do I change multiple variables in IntelliJ?

Try to set cursor on variable and use shortcut Shift-F6 - after that there are dialog frame for change name of variable and it changes all occurences of variable to setted name.

What does refactor do in IntelliJ?

The most popular refactorings supported in IntelliJ IDEAMakes sure that you do not delete files that are referenced in your source code. Copies/Moves an element. These refactoring actions help you reduce the code duplication. Renames an element.


1 Answers

It's not quite a batch, but if you position the cursor above the first of the methods, start a macro recording then do: control-alt-down shift-f6 down-arrow down-arrow carriage-return

then stop the macro, you now have a macro that goes to the next method and renames it as you desired (camel case, without underscores). You can then assign that macro to a shortcut and repeat the appropriate number of times. I tried adding the last step to the macro as being a key combination which was not bound, then assigning that combination to the macro itself (so it was self calling) but I could not get that to work. Also tried creating another macro which invoked the first x times, but that would also not work for some reason.

like image 138
user467257 Avatar answered Oct 26 '22 05:10

user467257