How to use IntelliJ IDEA to find all unused code?

后端 未结 3 1562
南旧
南旧 2020-11-29 16:00

When I am in a .java file the unused code is usually grayed out or has a green underline saying this code will probably (probably because of some weird JNI/Reflection corner

相关标签:
3条回答
  • 2020-11-29 16:22

    Just use Analyze | Inspect Code with appropriate inspection enabled (Unused declaration under Declaration redundancy group).

    Using IntelliJ 11 CE you can now "Analyze | Run Inspection by Name ... | Unused declaration"

    0 讨论(0)
  • 2020-11-29 16:24

    After you've run the Inspect by Name, select all the locations, and make use of the Apply quick fixes to all the problems drop-down, and use either (or both) of Delete unused parameter(s) and Safe Delete.

    Don't forget to hit Do Refactor afterwards.

    Then you'll need to run another analysis, as the refactored code will no doubt reveal more unused declarations.

    0 讨论(0)
  • In latest IntelliJ versions, you should run it from Analyze->Run Inspection By Name:

    Than, pick Unused declaration:

    And finally, uncheck the Include test sources:

    0 讨论(0)
提交回复
热议问题