In Intellij IDEA, when I rename a method using Rename refactoring tool (which essentially replaces occurences of method's old name for its new one), IDEA also removes unused imports from files, where method name is replaced.
This is not what I want to do. And even if I want to remove this redundant imports, I would like to do it in the whole project in a separate action, so it could be a separate commit.
How can I disable this behavior?
The version I use is 14.1.3 Ultimate.
There is already similar question How to prevent IntelliJ IDEA from deleting unused packages?, but the option mentioned there (Optimize imports on the fly
) has nothing to do with my problem. Actually I have it unchecked.
Update: It seems for me now that the only solution is to delete all unused imports before applying other refactoring tools.
Choose the project/module you want to remove unused import from in Project view. Then from Code menu choose Optimize imports and confirm with Run. The imports will be cleaned in whole project/module. Save this answer.
In the Project tool window, click Project and select Packages from the list. IntelliJ IDEA lists all the packages in your project. Right-click the package you want to rename and from the context menu, select Refactor | Rename ( Shift+F6 ).
Disable wildcard importsIn the Settings/Preferences dialog ( Ctrl+Alt+S ), select Editor | Code Style | Java | Imports. Make sure that the Use single class import option is enabled.
To automatically remove unused imports, we will need to add the eslint-plugin-unused-imports plugin. Now, when you run ESLint, you should see error lines saying error '<imported-var>' is defined but never used unused-imports/no-unused-imports for the files where you have unused imports.
I've asked this from IntelliJ support, and the response referred me to this issue in their issue tracking.
Basically, it's been a bug/feature since 2005. There has been discussion back and forth about if the behaviour should be changed, but as it stands, there hasn't been any changes and there is nothing you as a user can do about it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With