How to use IntelliJ IDEA to find all unused code?

别来无恙 提交于 2019-12-17 08:03:17

问题


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 cases) be unused. But I have this project with thousands of Java files and I want to find ALL INSTANCES of such probable-unused codes. How can I do that in IntelliJ IDEA?


回答1:


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"




回答2:


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:



来源:https://stackoverflow.com/questions/6587729/how-to-use-intellij-idea-to-find-all-unused-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!