3

给定某个 java 方法,我需要确定从入口类到目标方法的所有执行路径。

例子:

目标方法:MyClass.myMethod()

执行路径

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()

等等

是否有任何工具可以在我的代码库上运行静态分析以确定所有这些代码执行路径?

4

2 回答 2

2

eclipse 的调用层次结构是否符合要求?它显示一个方法的所有调用者或方法的所有被调用者的树(它只显示源代码可用的调用者或被调用者,不显示反射进行的调用)。

要打开它,只需单击方法名称,然后按CtrlAltH

于 2013-02-12T20:50:34.663 回答
0

FindBugs 是由马里兰大学编写的。这是

使用静态分析来查找 Java 代码中的错误的程序

Cobetura是一个

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.

于 2013-02-12T21:09:27.970 回答