smstromb
smstromb

Reputation: 596

How do I find all execution paths that use a certain method in a Java class?

Given a certain java method, I need to determine all the execution paths from the entry class to the target method.

Example:

target method: MyClass.myMethod()

execution paths:

EntryClass --calls--> Class1.method1() --calls--> Class2.method1() --calls--> Class2.method2() --calls--> MyClass.myMethod()

EntryClass --calls--> Class1.method1() --calls--> Class3.method1() --calls--> Class2.method2() --calls--> MyClass.myMethod()

EntryClass --calls--> Class3.method1() --calls--> MyClass.myMethod()

etc.

Is there any tool available that can run static analysis on my codebase to determine all of these code execution paths?

Upvotes: 5

Views: 2848

Answers (2)

j.jerrod.taylor
j.jerrod.taylor

Reputation: 1140

FindBugs is a written by the University of Maryland. It is

a program which uses static analysis to look for bugs in Java code

Cobetura is a

free Java tool that calculates the percentage of code accessed by tests. It can be used to identify which parts of your Java program are lacking test coverage.

I hadn't ever heard of them until one of the senior devs where I work did a code review. You can install them as maven plugins. Run the command

mvn site

to run your code coverage reports. I can't tell you any more about actually configuring it, because I didn't do that. They documentation is supposed to be pretty good though.

Upvotes: 0

meriton
meriton

Reputation: 70584

Does eclipse's call hierarchy fit the bill? It displays a tree of all callers of a method, or all callees of a method (it only shows callers or callees the source code is available for, and doesn't show calls made by reflection).

To open it, simply click on the method name, and press CtrlAltH

Upvotes: 3

Related Questions