Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming a variable can affect many other files

Just something I'm curious about. Here's what I do:

  1. I have a class with a member(type) who I want to rename to alertType, for example.

  2. I right click the member, Refactor->Rename.. and enter the new name.

  3. I'm prompted if I want to rename getters and setter too, I say yes.
  4. IntelliJ scans my whole project and gives me the list of changes
  5. The default refactoring is so broad, it renames any variable called type, or many html tags.
  6. I know I can exclude/remove these refactorings, but if I forget to do that, it breaks my codebase and I have to revert, which is a bit tedious.

enter image description here

My question is, is there a way to change the default rename behaviour to only include the Field to be renamed and References in code to parameter, method refactorings? I don't think I would ever want the dynamic and comment/string replacements- I'm just trying to quickly rename a single variable.

like image 473
Karl Reid Avatar asked Nov 24 '17 14:11

Karl Reid


1 Answers

On the field you want rename, press ShiftF6 and the inline rename refactoring will start. Now press ShiftF6 again, and the rename refactoring dialog will appear. Here you have 2 checkbox settings: search in comments and strings and search for text occurrences, disable those and it should fix your problem.

like image 141
Bas Leijdekkers Avatar answered Sep 17 '22 03:09

Bas Leijdekkers