18

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.

Community
  • 1
  • 1
Mikhail Batcer
  • 1,938
  • 7
  • 37
  • 57
  • +1. You can submit a feature request to their bug trucker, but since it sounds low priority to me, if that bothers you so much you can fork IntelliJ on Github and create a pull request with a fix / possibility to skip the unused imports removal. – Vic Aug 26 '15 at 12:51
  • You can also check if you have accidentally ticked the "optimise imports" box on the git commit interface. See this question: http://stackoverflow.com/questions/12585253/how-to-remove-unused-imports-in-intellij-idea-on-commit?rq=1 – phil_20686 Aug 27 '15 at 11:23
  • @phil_20686 I've checked and it's not ticked. Besides, imports are removed exactly during rename (notification about it appears for a second or two). Nonetheless, thank you. – Mikhail Batcer Aug 27 '15 at 11:30

1 Answers1

1

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.

eis
  • 51,991
  • 13
  • 150
  • 199