1

Lets say, I am on a class A. I want to be able to see all classes that it calls/refers/uses down to to the bottom..

 class A {
    B b;
    D d;
 }

 class B {
     C c;
 }

So I want something like:

 A
  --> B
       --> C
            --> xx
  --> D
      --> Yyy

Any tool if not eclipse?

Kevin Rave
  • 13,876
  • 35
  • 109
  • 173
  • F4 on the class will show u the type hierarchy – anfy2002us May 30 '13 at 15:23
  • @anfy2002us F4 key gives you the hierarchy of the class (superclasses, sub classses), not for fields of classes. – Luiggi Mendoza May 30 '13 at 15:23
  • Why do you want to know these details? – SimonC May 30 '13 at 15:24
  • click 'Show All Inherited Members' in the Type Hierarchy view – anfy2002us May 30 '13 at 15:25
  • @anfy2002us **is not about inheritance**. – Luiggi Mendoza May 30 '13 at 15:25
  • 1
    Folks, OP is asking for a dependency tree, not class hierarchy or implementations. Meaning if a class *uses* another class, it should show up somewhere/how. – Dave Newton May 30 '13 at 15:25
  • oh crap i have to read the question to the end... Try to see the 'Call Hierarcy' of the constructors of the super class – anfy2002us May 30 '13 at 15:27
  • @DaveNewton You are right. – Kevin Rave May 30 '13 at 15:38
  • `class A { B b; } class B { A a; }` - could be a problem. I don't know of a tool, but note that because Java makes reflection so easy, it shouldn't be to difficult to write this yourself. As a very rough estimate, I would say less than 20 lines. Getting rid of the circular dependencies, like above - a little more effort, but still not much. Figuring out how to make it into a Eclipse plug-in (or really anything that you don't need to run as part of your project), probably quite a bit more effort, if even possible. – Bernhard Barker May 30 '13 at 15:41
  • Doing this "for reals" is actually reasonably straight-forward by walking the bytecode, pulling out references, and drawing stuff up. I implemented a simplistic version using ASM (IIRC) and Graphviz. It falls over severely in "real life" code where dependencies might be injected outside of code, classes are instantiated via `forName` etc. It's difficult to get a complete dependency graph without also knowing how your codebase works. You might also consider a commercial tool like Structure 101 (no relation other than I use it sometimes). – Dave Newton May 30 '13 at 15:47

2 Answers2

0

You can use Maven + m2eclipse plug-in within Eclipse to get a dependency tree. There is a dependency tree tab within m2eclipse with a very graphical view of the dependencies. However I know Maven has a learning curve. But maybe that's OK. Only you can decide if you will get enough of a return on learning it to make it worthwhile. Other than that, I don't know of any plug-ins off the top of my head that will generate something similar.

Scott Shipp
  • 2,241
  • 1
  • 13
  • 20
  • I have m2eclipse installed, can you point me exact menu option to get to it? – Kevin Rave May 30 '13 at 15:44
  • That's different: that reports dependencies at the jar level (which may be adequate) but does not report (directly) what's actually *used*. – Dave Newton May 30 '13 at 15:45
  • @Scott the dependency tree plugin only shows the classpath artifacts that are used and its hierarchy. It doesnt show anything at the class level. – Adarsh May 30 '13 at 16:04
0

nWire does close to what I need. But not exactly same.

Thanks!

Kevin Rave
  • 13,876
  • 35
  • 109
  • 173