File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes IDEs, Version Control and other tools and the fly likes tool to identify unused methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "tool to identify unused methods" Watch "tool to identify unused methods" New topic

tool to identify unused methods

Mark Lybarger
Ranch Hand

Joined: Dec 19, 2003
Posts: 72
is there a tool which will identify unused methods for classes? we have a code base which is probably 3 years old and after much refactoring and such there's most certainly methods that got replaced but never removed.
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

There are tools to test code coverage - JBuilderX springs to mind. I think its got that sort of profiling capabilities. Nothing however beats a proper manual code review - especially when you got technologies like Reflection where methods might not be directly refered to by other classes, but are used at run time.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

There are a number of decent static analysis tools available that will do this -- no need to subject humans to that sort of bookkeeping work. IntelliJ IDEA has this built in, but there's also the open-source PMD.

[Jess in Action][AskingGoodQuestions]
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
The Code Guide IDE can do that, as far as I know. You simply tell it all the root classes (main class, classes loaded via reflection etc.), and it flags all unreachable code. Haven't tried it yet, though.

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Ernest Friedman-Hill:
there's also the open-source PMD.

From the description on the homepage it seems as if it only works for private methods, which is rather trivial (Eclipse can do that, too).

Finding unused *public* methods would be helpfull for us, too. Sadly, my feature request has been without effect until now...
I agree. Here's the link:
subject: tool to identify unused methods
jQuery in Action, 3rd edition