开发者

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

开发者 https://www.devze.com 2023-02-16 14:51 出处:网络
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?

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 proj开发者_如何学JAVAect 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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号