简体   繁体   English

如何为java项目生成调用图

[英]How to generate a call graph for a java project

Is it possible to generate a global call graph of an application? 是否可以生成应用程序的全局调用图?

Basically I am trying to find the most important class of an application. 基本上我试图找到一个最重要的应用程序类。

I am looking for options for Java. 我正在寻找Java的选项。

I have tried Doxy Gen, but it only generates inheritance graphs. 我尝试过Doxy Gen,但它只生成继承图。

My current script: 我目前的剧本:

#! /bin/bash

echo "digraph G
{"
find $1 -name \*.class |
    sed s/\\.class$// |
    while read x
    do
        javap -v $x | grep " = class" | sed "s%.*// *%\"$x\" -> %" | sed "s/$1\///" | sed "s/-> \(.*\)$/-> \"\1\"/"
    done
echo "}"

javap -v and a bit of perl will get you dependencies between classes. javap -v和一些perl会让你获得类之间的依赖关系。 You can make your parser slightly more sophisticated and get dependencies between methods. 您可以使解析器稍微复杂一些,并在方法之间获得依赖关系。

Update: or if you have either a *nix or cygwin you can get a list of dependencies as 更新:或者如果您有* nix或cygwin,您可以获得依赖项列表

find com/akshor/pjt33/image -name \*.class |
  sed s/\\.class$// |
    while read x
    do
      javap -v $x | grep " = class" | sed "s%.*// *%$x -> %"
    done

Add a header and a footer and you can pass it to dot to render a graph. 添加页眉和页脚,您可以将其传递给点以呈现图形。 If you just want to know which classes are used by the most other classes, as your question implies, then 如果你只是想知道大多数其他类使用哪些类,那么就像你的问题所暗示的那样

find com/akshor/pjt33/image -name \*.class |
  sed s/\\.class$// |
    while read x
    do
      javap -v $x | grep " = class" | sed "s%.*// *%%"
    done |
      sort | uniq -c | sort -n

For advanced code analysis you might wanna have a look at http://www.moosetechnology.org/ 对于高级代码分析,您可能需要查看http://www.moosetechnology.org/

Cheers 干杯
Thomas 托马斯

( edit: moved down here by general request, See: How to generate a Java call graph ) 编辑:通过一般请求向下移动,请参阅: 如何生成Java调用图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM