In IntelliJ Editor, If there is any unused code such as imports, methods or classes, or variables, It shows greyed code that code is not used anywhere. Developers manually remove it in a single file.

If you want to remove multiple files in a larger project, it is a very tedious task to check each file and remove unused code manually.

IntelliJ provides the following things

  • Inspect Code
  • Code Cleanup
  • Analyze Code

IntelliJ unused classes or code

  • Go to Code Menu
  • Select Analyze Code
  • Run Inspection by Name or Use Ctrl + Alt + Shift + I on Windows or Use Command + Option + Shift + I
  • type Unused Declaration
  • It shows Popup
  • Select Inspect options
  • Check or Uncheck classes, Inner classes, Fields, Methods, and Local Variables

Another way to use

Find Actions -> Ctrl + Shift + A Type Unused Declaration and select On to enable it