How to use IntelliJ IDEA to find all unused code?

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?


Just use Analyze | Inspect Code 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"


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 :

链接地址: http://www.djcxy.com/p/67722.html

上一篇: 如何使用春季数据jpa代理一个接口?

下一篇: 如何使用IntelliJ IDEA查找所有未使用的代码?