Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ remove all uses of a method?

IntelliJ gives useful functionality to see all usages of a method, and to check for usages before delete.

Is there a way to delete all usages of a method?

like image 834
C. Ross Avatar asked Jul 30 '14 17:07

C. Ross


People also ask

How do I hide usage in IntelliJ?

File -> Preferences -> Editor -> Inlay Hints -> Code vision and uncheck "Usages" for the Intellij folk that get directed here.

How do I see the usage of a method in IntelliJ?

In the editor, select a symbol for which you want to see the usages. From the main menu, select Edit | Find Usages | Show Usages In Code Ctrl+Alt+F7 . The usages window shows the current scope and total count of usages. If you want to quickly switch to the default scope, press Ctrl+Alt+F7 .

How do I refactor a method in IntelliJ?

Press Ctrl+Alt+M or from the main menu, select Refactor | Extract | Method. In the dialog that opens, configure a method options, such as visibility, parameters, and so on. You can also change a name of the method if you need. Click OK.

What is safe delete in IntelliJ?

Safe delete 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.


1 Answers

Yes you can, but it is not safe. If you are really sure that you want to delete all usages, then you can:

  • Empty the method body manually
  • Inline the method and let it remove all invocations Ctrl+Alt+N

You could seriously break the source code. Safe-deleting Alt+Del is the better solution, that is, iterating through the invocations and deleting them manually.

Even if you empty & inline the method, make sure you first double-check the invocations.


Example - Before inline:

Before inline


Result of inline:

After inline

like image 126
sina72 Avatar answered Nov 10 '22 04:11

sina72