IntelliJ IDEA lets you use the Safe Delete refactoring to remove files and symbols from the source code safely. Before IntelliJ IDEA deletes a file or a symbol, it searches for usages and if they are found, IntelliJ IDEA lets you check them to make necessary adjustments.
Select an item you want to delete.
Selectfrom the main or context menu or press Alt+Delete.
In the dialog that opens, select necessary options and click OK.
If IntelliJ IDEA encountered potential problems, it displays the Usages Detected dialog. Proceed with the appropriate action.
Safe delete a parameter
Safe delete a parameter for a call hierarchy (here performed on the parameter
If a parameter is passed only through a call hierarchy, the Safe Delete action will delete the parameter through the whole hierarchy. IntelliJ IDEA displays the appropriate dialog where you can select the caller methods in which the parameter should be deleted.
Safe delete a method
Safe delete a method in a call hierarchy (here performed on the
foo(int i) method).
IntelliJ IDEA analyzes the corresponding call hierarchy and displays the appropriate dialog, suggesting you delete all unused methods in that call hierarchy.
Safe delete the unused class field
Safe delete the unused class field (here performed on
When you remove an unused class field that is injected via constructor, IntelliJ IDEA removes the associated constructor parameter as well. IntelliJ IDEA opens the appropriate dialog where you can check and confirm your code deletion.