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?
350
votes
The answer given is right, but it's just a pity that there is no way to get all unused /dead code inside a project + a button to remove it all. That would be helpful !
– Snicolas
@Snicolas right-click on the inspection result (Declaration redundancy->Unused declaration) and choose "Safe delete".
– OrangeDog
Or if you want button, there's the light-bulb in the left toolbar.
– OrangeDog
You may check my answer on stackoverflow.com/questions/22522013/…. There you can find how to filter the results to see only those, which you really wanted.
– BlondCode
3 Answers
532
votes
84
votes
2
votes
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.