IntelliJ IDEA 2018.2 Help

Rename Refactorings

The Rename refactoring lets you change names of symbols, files and all the references to them throughout code.

Renaming local variables or private methods can be done easily in-line since only the limited scope is affected. Renaming classes or public methods could potentially impact a lot of files. In this case we suggest that you preview potential changes before you refactor.

  1. In the editor, select an element you want to rename. If you need to rename a file or a directory, select one in the Project tool window.
  2. Press Shift+F6 or from the main menu, select Refactor | Rename.
  3. You can perform a rename refactoring in-place or press Shift+F6 again to open the Rename dialog if you need to specify additional options. For example, specify where to search for element occurrences, or what else to rename.
    rename dialog
  4. Click Preview to see the potential changes and click Refactor.

Examples

Let's rename a class MyClass.

BeforeAfter
public class MyClass { // some code here } ... public void myMethod() { MyClass myClass = new MyClass(); }
public class YourClass { // some code here } ... public void myMethod() { YourClass yourClass = new YourClass(); }
Last modified: 14 June 2018

See Also