Aqua 2024.3 Help

Rename refactorings

Use the Rename refactoring to change names of symbols, files, directories, packages, modules and all the references to them throughout code.

Renaming local variables or private methods can be done easily inline since only the limited scope is affected. Renaming classes or public methods could potentially impact a lot of files. Preview potential changes before you refactor.

Rename code in place with gutter icon

  1. In the editor start renaming a parameter, a method, or other code element. Aqua will display the Rename the usages of icon in the gutter.

  2. Click the gutter icon or press Alt+Enter and apply a suggestion.

    Rename inline

    Aqua renames the code element and updates its usages accordingly.

    Rename refactoring result

Rename code in place with inlay hint

  1. In the editor, find the code element you want to rename.

    Ij identify code element
  2. Edit the text of the code element you want to rename, Aqua will display the Rename usages inlay hint.

    Ij rename usages inlay hint
  3. Select the inlay hint. If Aqua determines that some variables might also be renamed, the Rename Variables dialog opens. To confirm the rename refactoring, select OK.

    Ij rename variables dialog

    If Aqua doesn't identify any variables that might also be renamed, Aqua immediately renames the code element and updates its usages accordingly.

    Ij code element renamed

Rename a directory or a module

  1. In the Project tool window right-click a directory or a module that you want to rename.

  2. From the context menu, select Rename (Shift+F6).

  3. In the popup that opens, select what you want to rename. If you have a module with one content root, and it has the same name as your module, you can rename them both simultaneously.

    Select refactoring popup
  4. In the Rename dialog that opens, type the new name, specify additional options and the scope of the refactoring, and click Refactor.

Rename a package

  1. In the Project tool window, click Project and select Packages from the list. Aqua lists all the packages in your project.

  2. Right-click the package you want to rename and from the context menu, select Rename (Shift+F6).

    If you have multiple directories that correspond to the package, or the package contains directories in the libraries that cannot be renamed, Aqua will display a warning. However, you can proceed with one of the offered options in the warning. Aqua opens the Rename dialog where you can enter the new package name and click Preview to see what directories and files will be affected before you decide to refactor. If you want to undo the changes you have made, press Ctrl+Z.

Rename a code element

  1. In the editor, select the element you want to rename. If you need to rename a file, select one in the Project tool window.

  2. Press Shift+F6 or right-click and select Rename from the context menu.

    When you invoke the rename Shift+F6 action, Aqua displays the Rename in comments and strings icon and the Rename in text occurrences icon next to the highlighted element.

    Rename variable

    You can press Ctrl+Alt+Shift+N to open the context menu and select the additional rename options.

    Additional Rename options

    If you want to see the Rename dialog with more options, click the More options link or press Shift+F6.

  3. Open (Shift+F6) the Rename dialog. Enter a new name of the element to enable the Preview and Refactor buttons.

    The Rename dialog

    You can specify additional options. For example, specify where to search for element occurrences, or what else to rename. You can also specify a scope for the refactoring.

  4. Click Preview to see the potential changes or click Refactor.

    When you click Preview, Aqua opens the Find tool window with the results of found usages where you can check the results and confirm the refactoring (Do Refactor).

Next time you invoke the Rename refactoring, Aqua remembers the options you have specified inside the Rename dialog.

Examples

Let's rename a class MyClass.

Before

After

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 November 2024