Java 如何使用 IntelliJ IDEA 查找所有未使用的代码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6587729/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use IntelliJ IDEA to find all unused code?
提问by pathikrit
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?
当我在 .java 文件中时,未使用的代码通常变灰或带有绿色下划线,表示此代码可能(可能是因为一些奇怪的 JNI/反射极端情况)未被使用。但是我有这个包含数千个 Java 文件的项目,我想找到这种可能未使用的代码的所有实例。我怎样才能在 IntelliJ IDEA 中做到这一点?
采纳答案by CrazyCoder
Just use Analyze | Inspect Code
with appropriate inspection enabled (Unused declarationunder Declaration redundancygroup).
只需Analyze | Inspect Code
启用适当的检查即可使用(声明冗余组下的未使用声明)。
Using IntelliJ 11 CE you can now "Analyze | Run Inspection by Name ... | Unused declaration"
使用 IntelliJ 11 CE,您现在可以“分析 | 按名称运行检查 ... | 未使用的声明”