Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dependency map for Java classes and methods

I have a Java project that I've been working on for a while. The design started out pretty good but slowly degraded as changes were made. I'm looking for some sort of tool that will analyze the project. It'd be really nice to have a map of the dependencies of different classes/methods. I feel like certain methods are only in there to fulfill a very specific goal. I'd like to eliminate unnecessary code and make my design better.

Any suggestions would be great! Thanks!

like image 857
Ryan Avatar asked Mar 02 '10 21:03

Ryan


2 Answers

You may want to check out JDepend. It was specifically developed to solve the problem you are facing.

Working as a consultant it is very common for me to be thrown in to a huge legacy code base. Typically the first thing I do is run JDepend on it to try to get my bearing on the code base and all of the dependencies.

Good luck.

like image 137
Steven Levine Avatar answered Sep 24 '22 17:09

Steven Levine


Many tools are available for this, depending on the size of your system. The grandaddy of them all is Structure101, a commercial product.

http://structure101.com

I've used this on some big projects - it's complex but easily the most comprehensive of all the tools I know. It can graph a huge architecture, and lets you untangle some complex stuff. It has a sister product called reStructure101 where you can do what-if scenarios.

A nice competitor is Stan4j. It's nowhere near as complete, but does some stuff better, particularly showing the dependency context at the class level.

http://www.stan4j.com

(I own both products, but have no commercial affiliation with either)

Another way of viewing complex dependencies, particularly at the project level, is a Dependency Structure Matrix (DSM). Although S101 can do a DSM, Lattix has more support - it can handle Spring and Hibernate dependencies:

http://lattix.com/

(I've not used lattix - they make it too hard to evaluate it, which is bizarre because I work on some very big systems)

If your software is fairly small, and you are more interested in the simple class level, then something like Architexa may help you understand the structure better:

http://www.architexa.com/

Finally, if you want to roll your own, you can easily do this with ASM. It even includes a dependency matrix tool which tracks at the package level:

http://asm.ow2.org/doc/tutorial-asm-2.0.html (see down the page for the nify dependency matrix)

Here's the source for it - it's very simple, but clever. It works off bytecodes. http://cvs.forge.objectweb.org/cgi-bin/viewcvs.cgi/asm/asm/examples/dependencies/src/org/objectweb/asm/depend/

like image 37
Andrew McVeigh Avatar answered Sep 25 '22 17:09

Andrew McVeigh