10

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.

rdonuk
  • 3,921
  • 21
  • 39

2 Answers2

11

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.

VincentDS
  • 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
8

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

enter image description here Now look for uncessary code section and tweak the settings as you desire to cleanup further.

I hope it helps :)

vkg
  • 1,839
  • 14
  • 15