Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我在 .java 文件中时,未使用的代码通常显示为灰色或带有绿色下划线,表示此代码可能(可能是因为一些奇怪的 JNI/Reflection 极端情况)未被使用。但是我有这个包含数千个 Java 文件的项目,我想找到这些可能未使用的代码的所有实例。我怎样才能在 IntelliJ IDEA 中做到这一点?
只需在Analyze | Inspect Code启用适当检查的情况下使用(声明冗余组下的未使用声明)。
Analyze | Inspect Code
使用 IntelliJ 11 CE,您现在可以“分析 | 按名称运行检查 ... | 未使用的声明”
在最新的 IntelliJ 版本中,您应该从Analyze->Run Inspection By Name运行它:
然后,选择未使用的声明:
最后,取消选中Include test sources:
运行 Inspect by Name 后,选择所有位置,并使用Apply quick fix to all the questions下拉菜单,并使用Delete used parameter(s)和Safe Delete中的一个(或两个) 。
之后不要忘记点击Do Refactor。
然后你需要运行另一个分析,因为重构的代码无疑会揭示更多未使用的声明。