views:

430

answers:

4

Let's say I have a MyClass class, with various methods, and let's say that method MyClass.A() calls methods MyClass.B() which calls MyClass.C(). Method MyClass.A() also calls MyClass.D() which also calls MyClass.C() and so on :)
Is there any tool to visualize this as a diagram?

UPD. I see NDepend can do what I need but it costs too much when I just need to build methods dependency graph and trial limitations are too big (I can't zoom the graph and I can't see anything on a small resulted graph without being able to zoom). So, I'm still looking for alternatives - it should be free or not expensive tool.

+3  A: 

The NDepend tool is one of the best known tools. It can do some deep analysis of assemblies (or sets of them) as well as create visual displays of the data.

Here's an image showing method dependencies in an application: Dependencies View

And from Patrick's comment: In the VisualNDepend class browser you can right click on any class and choose the menu: Show internal dependencies (on dependency Graph or on dependency Matrix). This will show you the dependencies between methods of the same class.

Eilon
Can it show dependencies between methods of the same class?
nightcoder
Yes, I believe that it can. See the online demo for "Understand code structure".
Eilon
I've watched the "Understand code structure" demo, but there is nothing about class methods dependency...
nightcoder
Slide #98 in the demo shows a sample of how to query for method dependencies. I added an image link to my original answer that shows a graph of method dependencies.
Eilon
In the VisualNDepend class browser, right click any class and choose the menu: Show internal dependencies (on dependency Graph or on dependency Matrix)and you'll get instantly: dependencies between methods of the same class
Patrick Smacchia - NDepend dev
I've updated the answer with Patrick's comment.
Eilon
@Patrick Smacchia: Yes, I know, but as I wrote in my question - trial version doesn't support zooming and without zooming this graph is unreadable and useless.
nightcoder
A: 

You should check out nWire (available for Java and PHP). nWire is an Eclipse plugin which analyzes your code and provides several power tools for exploring the code associations.

zvikico
@nightcoder has tagged his question with "visual-studio"
ProfK
Missed that... my mistake (IMHO, that should be clearly stated in the question, but... whatever).
zvikico
+2  A: 

If you have .NET code, you might want to try the RC release of Visual Studio 2010 Ultimate to generate sequence diagrams and dependency graphs:

How to: Explore Code with Sequence Diagrams: http://msdn.microsoft.com/en-us/library/ee317485%28VS.100%29.aspx

...you can generate a sequence diagram to help you visualize and understand how your code implements a particular method. A sequence diagram describes an interaction between objects as a series of lifelines and messages. Lifelines represent instances of objects, and messages represent method calls between those objects. You can generate sequence diagrams from Visual C# .NET or Visual Basic .NET code. A generated sequence diagram shows elements similar to those on a UML sequence diagram.

UML Sequence Diagrams: Reference: http://msdn.microsoft.com/en-us/library/dd409377%28VS.100%29.aspx UML Sequence Diagram

How to: Generate Graph Documents from Code: http://msdn.microsoft.com/en-us/library/dd409453%28VS.100%29.aspx#SeeSpecificSource

You can use Visual Studio Ultimate to explore the relationships and organization in existing code by generating directed graph documents. These graphs represent code elements and their relationships as a set of nodes that are connected by links, or edges. You can use these graphs to help you visualize, explore, and analyze code.

How to: Find Code Using Architecture Explorer: http://msdn.microsoft.com/en-us/library/dd409431%28VS.100%29.aspx

You can select vertical sections or "slices" of code that you want to visualize by using Architecture Explorer. You can explore source code in a Visual Studio solution or compiled managed code in .dll files or .exe files. You can use Architecture Explorer to browse other domains by installing additional providers. When you find the code that you want to visualize, you can generate graphs to explore the relationships in that code.

Esther Fan - MSFT
A: 

See http://www.reversejava.com for a dynamic reverse engineering application which generates UML Sequence diagram and view of Participating Class diagram from any Java Application at runtime All you have to do is just run your application and sit back. Reverse Java runs in background tracing all the activities happening inside your application and creates UML diagram for you.

You also have options for, excluding packages,editing the Sequence diagram and exporting the diagrams as PDF or Image.

And its not expensive !

Rajesh Jadhav