3 ms·
This looks rather promising. Doesn't work in my version of IDEA (Build #IC-223.8214.52, built on December 20, 2022, Community Edition), due to the following err
by thangalin 4y ago
This looks rather promising. Doesn't work in my version of IDEA (Build #IC-223.8214.52, built on December 20, 2022, Community Edition), due to the following errors when running the script:
> Argument for @NotNull parameter 'module' of org/jetbrains/.../...GroovyRunner must not be null.
The project doesn't have any references to the NotNull annotation, and there are a number of what appear to be compile errors:
https://i.ibb.co/dfxbV4p/rename-script.png https://i.ibb.co/dfxbV4p/rename-script.png
Running with Ctrl+Enter produces:
> @file:Suppress("NAME_SHADOWING")
MultipleCompilationErrorsException: startup failed:
Script1.groovy: 1: Unexpected input: '@file:' @ line 1, column 6.
@file:Suppress("NAME_SHADOWING")
^
1 error
I removed the line and re-ran, which resulted in:
> import com.intellij.notification.Notification
[22 ms]=> null
Then I selected the entire text and pressed Ctrl+Enter again, which returned:
MultipleCompilationErrorsException: startup failed:
Script4.groovy: 20: Unexpected input: '<*' @ line 20, column 25.
val b = bindings as Map<*, *>
^
1 error
After changing the asterisks to question marks, the script failed to run, indicating:
MultipleCompilationErrorsException: startup failed:
Script5.groovy: 25: Unexpected input: 'registerAction(\n name: String,\n keyBind: String? =' @ line 25, column 22.
keyBind: String? = null,
^
1 error
I appreciate the effort, though!
- counttheforks 4y agoMake sure you pick Kotlin for the scripting language, not Groovy. Then run the script like this: 1. In IDEA: Tools -> IDE Scripting Console -> Kotlin 2. Paste in the script 3. Ctrl+A, Ctrl+Enter to load the script. This should show a green "Loaded!" notification 4. Select a folder containing the classes in the Project window 5. Press Ctrl+Shift+A to open action menu 6. Search for Bulk refactor and select it Also please note the first version of the script had a bug that would open confirmation dialogues for some refactorings, so see the edited script.
- thangalin 4y ago> 1. In IDEA: Tools -> IDE Scripting Console -> Kotlin No such sub-menu of Tools exists, but that's fine because I've mapped Ctrl+Shift+A to bring up the menu. I installed the Kotlin plugin and tried again. There was a missing import. After fixing the missing import: [732 ms]=> null I switched "Rename" to "Kt", of course, and re-ran the script. > 4. Select a folder containing the classes in the Project window > 5. Press Ctrl+Shift+A to open action menu > 6. Search for Bulk refactor and select it Opening the menu with Ctrl+Shift+A doesn't show the bulk refactor script, but that could be because I remapped Ctrl+Shift+A and am using the NetBeans keyboard mappings, rather than the IntelliJ map. https://i.ibb.co/5LTsffj/bulk-refactor.png https://i.ibb.co/5LTsffj/bulk-refactor.png
- counttheforks 4y ago> There was a missing import Oops :) When pressing Ctrl+Enter, did you see the green "Loaded!" notification in the bottom right? If so, then I guess installing the Kotlin plugin worked. > Opening the menu with Ctrl+Shift+A doesn't show the bulk refactor script The Ctrl+Shift+A menu from the default keymap that I'm talking about is the "Actions" dialog. You can also get there via "Navigate -> Search Everywhere" and then selecting the "Actions" tab (or just searching in All). Also you only have to select a single folder/package and it will be processed recursively. I did not test what happens when you select multiple folders. Might be fine, might explode. edit: Just realized the script I pasted here does not emit the "Loaded!" log message on load. So disregard those comments. If you want to verify it loads correctly, add this as the last line: log("Loaded!") edit: HN rate limited my account again, so I'm not allowed to post any new comments for the next few hours. Good luck! If you do wind up using this script and want to modify it, it is helpful to read https://plugins.jetbrains.com/docs/intellij/psi.html https://plugins.jetbrains.com/docs/intellij/psi.html & to install the PsiViewer plugin from the marketplace.
- thangalin 4y agoThere are some minor clean-up issues, but overall, it did the trick. https://i.ibb.co/MP2JNRM/classes-renamed.png https://i.ibb.co/MP2JNRM/classes-renamed.png Thank you!