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:

  1. 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.

  2. In the Safe Delete dialog box, make sure that the IDE has identified the right element to be deleted and click Next.

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:

To remove references to code and continue with the deletion of the class element:

  1. 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.

  2. Double-click a node for code that references the class to be deleted.

    The referencing class opens in the Source Editor.

  3. 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.

  4. Repeat steps 2 and 3 until all references to the code that you want to delete are removed.
  5. 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.

See Also
Refactoring: Quick Reference
Finding Class, Method, and Field Usages
Renaming a Class or Interface
Undoing Refactoring Changes

Legal Notices