I have a class which has 1600 public static members. I must found and delete the unused ones. Is there a way to do it in Eclipse.
-
1you can delete it. if it generates an error undelete it. how can you detect if something is in use though? deprecation might be a better idea. – Logan Murphy May 16 '14 at 12:18
-
doesn't code expection solve your issue? – Dmitry Ginzburg May 16 '14 at 12:30
-
what is code expection? – rdonuk May 16 '14 at 12:43
2 Answers
There exists a Eclipse plugin Unused Code Detector (http://www.ucdetector.org/). It can process a specific file or the entire project, searching for unused members/methods.

- 310
- 2
- 8
-
**UCDetector** does not detect the calls to methods from `.xml` files (in case of spring web-flow). So, it shows that the method is not being called from anywhere in the project, but ideally it is being called from web-flow. Is there any way where I can check the calls from web-flow as well apart from other `.java` files? – Nisarg Patil Feb 20 '18 at 14:28
-
2@NisargPatil Spring uses reflection to call these methods, there's no way a tool can detect that. Same applies to Struts. – Lluis Martinez Jun 19 '19 at 20:23
Ucdetector: You can install a plugin from this link. It works pretty well we have been using it in all our projects. It generates a html report as well it can mark warnings in eclipse. It helps you find unused classes, methods and variables. Only thing it dosen't do well is finding if a class is used via reflection only or where instance is created via spring. In these cases it still shows that class is unused.
http://ucdetector.sourceforge.net/update
Another thing you can do to clean up other types of unsed code is GoTo Window>Preferences>Java>Compiler>Error/Warnings
Now look for uncessary code section and tweak the settings as you desire to cleanup further.
I hope it helps :)

- 1,839
- 14
- 15