« Return to Thread: Why are there no tools to find unused CLASSES?

Re: Why are there no tools to find unused CLASSES?

by Thomas Wolf-4 :: Rate this Message:

Reply to Author | View in Thread


If a public class has a public method, it IS possible to know whether any other class in the project is calling that method directly.  Otherwise, the project wouldn't even compile.  That's what I termed (perhaps incorrectly) *static analysis*.  There are obviously cases where classes/methods can be created/called by just specifying some string at runtime.  Those, I expect, would not be found by any tool.

To be clear, I'm not looking for a tool that will automatically remove unused classes for me.  I'm looking for a tool that will give me a list of candidate classes.

A brute force way of achieving what I want is to simply create a list of all the Java source files in the project.  Then try to build without one of these files.  If the build succeeds, it's a candidate.  Put that file back and repeat with the next file in the list.
With 3800 files in my project, this would take 3800 builds - horribly inefficient.  But it illustrates that it is a very straight-forward problem.  I just don't have the IDE/ant skills to implement it more efficiently myself.  And I was thinking that something like this belongs in the IDE (or into a plugin like PDM as someone else pointed out).

thnx,
tom

Jose Noheda wrote:
If a public class has a public method there is no way to decide if it's used or not. You just can't remove it that easily

On Thu, May 8, 2008 at 11:27 PM, Thomas Wolf <twolf@...> wrote:

Every now and then I work on larger projects where alot of cruft, in the form of unused Java files, has accumulated.  Each time, I unsuccessfully look through NB and its plugins for a tool that can find potentially unused java classes in a project.  I asked my Eclipse-toting colleagues and it, too, doesn't seem to have any such tool :-(  I always check the web for static analysis tools that might do the job - either my keyword searches are insufficient or there are just none to be found.

Does anyone know of such a tool?

I  am not looking for a perfect solution - I know that no tool would know whether statically unreferenced classes are dynamically referenced from somewhere.  I'm just looking for one that can check for static references.

Many thanks for any suggestions/pointers.
Tom

P.S. Eclipse and Netbeans both have "Find Usages" capabilities.  But with 3800 src files, I don't want to go through that exercise.


 « Return to Thread: Why are there no tools to find unused CLASSES?