Safely Deleting Java Code
See Also
You can use the Safely Delete command to have the IDE check for references to a code
element before you delete that code element. You can use the Safely Delete command on
classes, methods, and fields.
When you choose the Safely Delete command on a code element, the Safe Delete
dialog box opens and helps walk you through the process.
To initiate the Safely Delete operation:
- Select the code element that you want to delete and choose Refactor > Safely Delete.
You can select the code element by clicking the element's node in the Projects window
or by placing the insertion point in an identifier for the code element in the Source Editor.
- In the Safe Delete dialog box, make sure that the IDE has identified the right element to
be deleted and click Next.
- If the code element is not referenced by other code, the Safe Delete dialog box closes
and the code element is deleted.
- If the code element to be deleted is referenced by other code, a warning and a
Show Usages button appear in the Safely Delete dialog box. See the
section below for information on completing or canceling the operation.
Handling Deletions When The Code Element is Referenced
When the message beginning with References to selected elements were found
appears in the Safely Delete window, you can proceed in one of the following ways:
- Remove the references to the code to be deleted and then continue
the Safely Delete operation.
- Click Cancel to cancel the command.
- If you mistakenly delete a code element that is still referenced by
other code, you can reverse the deletion with the Refactor > Undo command.
To remove references to code and continue with the deletion of the class element:
- In the Safely Delete dialog box, click Show Usages.
The Usages window opens with a list of the references
to the code that you want to delete.
- Double-click a node for code that references the class to be deleted.
The referencing class opens in the Source Editor.
- Remove the reference to the code that you want to delete.
You can use the Safely Delete command to remove this reference. If there are references
to that code as well, you can click Show Usages to open a new tab in the Usages
window.
- Repeat steps 2 and 3 until all references to the code that you want to delete
are removed.
- In the Usages window, click Rerun Safe Delete.
The Safely Delete command will be run again.
If there are any references that you have not removed, a warning will appear and
you can click Show Usages to resume the process of resolving the references.
- If you click Preview in the Safe Delete window, the
Refactoring window appears after you click Next. Click Do Refactoring to proceed with the
deletion.
- See Also
- Refactoring: Quick Reference
- Finding Class, Method, and Field Usages
- Renaming a Class or Interface
- Undoing Refactoring Changes
Legal Notices