In older programs that have been modified many times, sometimes code creeps in that is no longer executed, and which can be removed without affecting the way the program runs. Leaving that code in place makes programs hard to understand; new developers rightly question what it’s for. But finding such code can be tricky – unless you have a tool like UCDetector, an Eclipse plugin that finds unnecessary Java code.
UCDetector can flag public classes, methods, and fields that have no references and display them in the Eclipse Problems view. A developer might run UCDetector after refactoring to clean up code, or when starting to work on someone else’s code.
German developer JÃ¶rg Spieler created the utility back in 2007 because “I like to refactor and simplify code. Removing unused code makes it easier to understand programs.” UCDetector is itself built using Eclipse for Java and plugin development, while Spieler uses Inkscape to create and edit icons, and jEdit for all other kind of files.
Spieler says UCDetector checks for dangerous cases where searching references and deleting code may cause your program to fail. For example, searching references for a method that is overridden causes no search matches, but you can’t delete the method. You can find code used only by test, and produce XML, HTML, and text reports. The utility also lets you create a custom detection by using existing classes, and you can run UCDetector without Eclipse as an Apache Ant task.
Spieler says the software is pretty feature-complete. He plans only bug fixes and feature requests from the community in upcoming versions. “I welcome interesting ideas from the community to improve
UCDetector, or other ways to find unused code, or other ideas on how to use results of searching for references in Java.”