Batch rename of methods using IntelliJ IDEA
Asked Answered
L

1

6

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?

Latvina answered 7/1, 2013 at 23:25 Comment(6)
I'm not very sure about this so I'm not going to post it as an answer. But, there is a feature called structural search and replace in Intellij. It might be able to do what you're talking about. But, I could never figure out how to use it.Malkamalkah
@DanielKaplan, thanks for the suggestion. It doesn't look like SSR will do what I want in this case. I've been a bigger user of ReSharper for C# than IDEA over the last few years and there they have a way of specifying and enforcing naming conventions. I'm hoping to use the same for Java as well.Latvina
Maybe this can be helpful: blogs.jetbrains.com/idea/2007/01/… I don't know if there's a way to change the names in bulk though.Malkamalkah
@DanielKaplan, with that enabled you can, from the popup, select Fix all *** problems which takes you through each one in turn with a dialog. You can select a conformant name from the drop down. Definitely easier, but not as easy as it could be.Latvina
Hi Drew, did you use SSR for renaming your method? I'd like to rename my fieldnames but I'm having trouble. Can you provide an example?Karlene
@Goot, sorry, this was a while back and I don't recall.Latvina
T
1

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.

Tadtada answered 9/6, 2015 at 11:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.