The Safe Delete refactoring allows you to safely remove the following symbols from the code:
IntelliJ IDEA checks for the remaining usages of the deleted symbol. The refactoring allows you to make the necessary corrections of the code before the symbol is actually deleted. The procedure of removing a symbol slightly differs depending on the type of the symbol to be deleted.
This refactoring is also available from UML Class diagram.
- Select the symbol to be deleted.
You can also press or , or , or , or in the Project tool window. Then you can either perform a Safe Delete or simply delete the symbol.
on the main menu or in the context menu of the selection.
Alternatively, press .
Safe Delete dialog box that opens,
specify additional settings for the refactoring:
- To have the changes applied to comments and strings, select the Search in comments and strings check box.
- To have the changes applied to text files (such as documentation, HTML, JSP and other files included in your project), select the Search for text occurrences check box.
- Click OK to continue. If no usages of the symbol are found, the refactoring removes the symbol. If IntelliJ IDEA finds any occurrences of the symbol in the code, the Usages Detected dialog box appears.
In the Usages Detected dialog box, do one of the following:
- To proceed with refactoring and delete the symbol, click the Ignore button, leaving all the usages of the symbol intact. In this case, to make your code compilable, you have to manually inspect the code and make the necessary corrections.
- To view the list of direct usages of the symbol, click the View usages button. IntelliJ IDEA stops the refactoring procedure and the displays a list of direct usages of the selected symbol in the Find tool window. Navigate to each usage location and manually correct the code. When ready, click the Rerun Safe Delete button to invoke the refactoring again.