views:

338

answers:

3

Any code-analysis or "reverse-engineering" tool that can do either of these?:

  • Calculate which classes are sub-classes of which classes
  • Calculate which classes instantiate which classes -- (like VS Class Designer)
  • Calculate which functions call which functions -- (much like a Call Stack)
+1  A: 

Doxygen + GraphViz (for pictures, Doxygen requires GraphViz)

That has the largest languages support (since you did not specify a language) and the viewer is a browser, so once generated, anyone should be able to view it.

Configure doxygen to generate even non documented members, and to include the source code. This way the source code will include links to function declarations for easy navigation.

There are also tools that specialize in a language, such as Understand for C++.

earlNameless
A: 

Understand 2.0

...shows the dependence between parts of the code written in different languages. CLA make it easy to follow the calls. ~ Combined Language Analysis

Specifically this Function Call tree image.

Jenko
A: 

The NDepend can produce some cool methods or class call graph like for example (image full size here)

alt text

Find more explanations about NDepend call graph here.

NDepend also comes with Code Query Language (CQL) that is designed to ask queries about your code and get instant results in Visual Studio:

SELECT METHODS WHERE IsDirectlyUsedBy "NUnit.Core"

SELECT METHODS WHERE 
DepthOfCreateA "NUnit.Core.Builders.DatapointProvider" == 1

SELECT TYPES WHERE 
DepthOfDeriveFrom "NUnit.Util.ServerBase" >= 0 
ORDER BY DepthOfDeriveFrom

CQL is also designed to write code quality rules that can be verified live in Visual Studio, or that can be verified during build process and reported in a HTML report. Here are a few samples of CQL rules (designed to be highly customizable):

Code refactored recently should be 100% covered by test:

WARN IF Count > 0 IN SELECT METHODS WHERE CodeWasChanged AND PercentageCoverage < 100

Complex methods should be commented:

WARN IF Count > 0 IN SELECT METHODS WHERE CyclomaticComplexity > 15 AND PercentageComment < 10

I don’t want that my User Interface layer to depend directly on the DataBase layer:

WARN IF Count > 0 IN SELECT NAMESPACES WHERE IsDirectlyUsing "DataLayer" AND NameIs "UILayer"

Static fields should not be named m_XXX (Custom naming conventions):

WARN IF Count > 0 IN SELECT FIELDS WHERE NameLike "^m_" AND IsStatic

Methods out of MyAssembly and MyAssembly2 should not have more than 30 lines of code:

WARN IF Count > 0 IN SELECT METHODS OUT OF ASSEMBLIES "MyAssembly1", "MyAssembly2" WHERE NbLinesOfCode > 30

Public methods should not be removed to avoid API breaking changes:

WARN IF Count > 0 IN SELECT METHODS WHERE IsPublic AND IsInOlderBuild AND WasRemoved

Types tagged with the attribute MyNamespace.FullCoveredAttribute must be thoroughly covered by tests:

WARN IF Count > 0 IN SELECT TYPES WHERE HasAttribute "MyNamespace.FullCoveredAttribute" AND PercentageCoverage < 100

Patrick Smacchia - NDepend dev