Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of classes in a project that are no longer needed by anything in that project

Is there any way to generate a list of classes in a Java project that are no longer needed by any other classes in that project?

Here's a diagram to help illustrate the situation (I hope you enjoy my ASCII diagram since I don't have enough rep to use an image), where C and B depend on project A:

         A
        / \
       /   \
      C     B

I started refactoring by moving code from B to A, so that it could be shared by C and B. However, now that I'm getting close to finishing refactoring, I want to check to see if there are any classes that I moved to A that can now be moved back down to B (classes that are in A but aren't using by any code in A)

Is there some tool that I can use to generate a list of such classes for me?

like image 702
cshanes Avatar asked Mar 14 '11 17:03

cshanes


People also ask

How do I add a class library to an existing project?

In the Solution Explorer window, right click the project you want to use your class library from and click the 'Add Reference' menu item. Then if the class library is in the same solution file, go to the projects tab and select it; if it's not in the same tab, you can go to the Browse tab and find it that way.

How do I run a class library in Visual Studio?

Right-click on the solution in Solution Explorer and select Add > New Project. On the Add a new project page, enter library in the search box. Choose C# or Visual Basic from the Language list, and then choose All platforms from the Platform list. Choose the Class Library template, and then choose Next.

What are data classes?

A data class is a list of data set allocation attributes and their values. You cannot assign a data class to an object; however, data class may be used for allocation of a scratch tape to be used to write objects.


2 Answers

JBoss Tattletale works well for this. I have used it in the past to figure out what third-party libraries are no longer needed by our project and also to learn about potentially conflicting packages/classes that are present in multiple JAR files.

like image 61
Rob H Avatar answered Oct 06 '22 23:10

Rob H


Start your program with the -verbose:class flag to the JVM. Redirect the output to a file. Exercise your program - run your tests or whatever. Grep out the name of every class loaded. Run find over your build output directories to make a list of all your classes. Compare the results to find anything in your build output directories that's not in the list of loaded classes.

like image 41
Tom Anderson Avatar answered Oct 07 '22 01:10

Tom Anderson