views:

393

answers:

7

I have a large codebase, and I'd like to refactor the package structure so that classes which interact heavily go in the same package.

It seems that it should be possible to create a tool that could look at the interactions between classes, and then group together those classes that interact heavily. These groupings might then suggest a good hierarchy for packages.

Does such a tool exist? (open source is preferred).

A: 

Try some Pasta (see http://freshmeat.net/projects/pastatool/)

JeffFoster
The link on the Freshmeat page appears to be broken :-/
sanity
It hasn't been updated in like 5 years, which I guess would mean no java 5 support.
SCdF
A: 

IntelliJ has some code matrix tools in this direction.

sblundy
Thanks, I tried that but its rather hard to interpret this report in a way that suggests how the package hierarchy should be restructured.
sanity
A: 

Just a comment (not really an answer since I am not aware of a specific tool but I can't comment yet)

Have you looked at formal concept analysis?

Generally it's a way of grouping together entities that share the same properties. For example, Siff and Reps (google for the paper) did automatic modularization by looking at the relation between functions and global variables. In my own research, I used the relations of class methods that access the same fields. Siff and Reps (google for paper) did automatic modularization.

FCA may not be the best approach here since you are trying to group classes against themselves, but I think that they can still be applied.

Uri
A: 

Something that can at least tell you if you're on the right track design-wise is JDepend. It encourages dependency on highly abstract packages (that presumably will change less than packages with code that is less abstract) and will warn you when your packages have circular dependencies. I find it to be a good reality check.

There are numerous ways to use it, including as an Eclipse plugin.

LeedsSideStreets
+1  A: 

You could try Lattix, which uses the Dependency Structure Matrix to show you dependencies and hidden structure within your code at both class and package level. I've found it helpful for this kind of stuff in the past.

http://www.lattix.com/

Alex Miller
+3  A: 

Structure101 is another product that can analyze the structure of your code and do dependency and what-if analysis.

http://www.headwaysoftware.com/products/structure101/index.php

Alex Miller
+1  A: 

Structure Analysis for Java is an Eclipse plugin that does some dependency analysis:

http://stan4j.com/

Alex Miller