L-Zephyr / Drafter

在iOS项目中自动生成类图和方法调用图 - Generate call graph in iOS project
MIT License
1.02k stars 128 forks source link

Drafter

English Version

Drafter是什么

安装

执行以下指令,会自动安装到/usr/local/bin目录中:

curl "https://raw.githubusercontent.com/L-Zephyr/Drafter/master/install.sh" | /bin/sh

或者直接下载并编译源码

基本使用

指定一个文件或文件夹,Drafter会自动解析所有的OC和Swift代码文件,解析各个类型中方法的调用流程以及类型之间的继承关系,并以图表的形式展现出来。

导出HTML在浏览器中查看

以AFNetworking的源码为例,在命令行中执行如下命令,在参数-f后输入文件或目录:

drafter -f ./AFNetworking

解析结果会输出到当前路径下的DrafterStage文件夹中,用浏览器打开./DrafterStage/index.html文件即可浏览,建议使用chrome浏览器:

call graph

界面主要分为三个部分:

  1. 左边可以切换方法调用图(Call Graph)和类图(Class Diagram)模式,查看方法调用图时,列表中显示工程中的所有类型,选择可以直接切换。开启Intrinsic Method Only选项仅显示类型内部的方法调用(为防止调用过多默认打开);开启Show Access Level选项则会在方法节点的左上角显示该方法的访问等级;

  2. 中间是主要的展示区域,类型中的方法和方法之间的调用关系会以流程图的形式展示出来,选中一个方法会将该方法及其所调用的方法一起高亮出来;Pick按钮可以选择仅展示指定的方法;在类图模式中这里会显示工程中的类型继承关系,虚线表示实现协议,实线表示继承父类(UML): class diagram

  3. 右侧为详细信息面板,选中节点后自动弹出,展示该节点的所有信息,包括所有参数的名称以及类型等,Invokes字段列出了它所调用的方法,点击可以快速定位;

在浏览器中交互式的查看可以帮助你快速找到一个类型的关键逻辑,强烈建议通过这种方式来使用Drafter。前端部分的代码开源在DrafterStage,在Chrome环境下经过测试。

导出为PNG

这部分为第一个版本的旧接口,不建议使用

参数

实现原理

实现细节请看https://juejin.im/post/5a3088e95188253ee45b6cbe

english-version

What is Drafter

Install

Run the following command, drafter will automatically install into the /usr/local/bin directory.

curl "https://raw.githubusercontent.com/L-Zephyr/Drafter/master/install.sh" | /bin/sh

Or you can download and compile the source directly.

Basic Use

Export to HTML

Run the following command. Enter the file or directory path after the -f argument :

drafter -f ./AFNetworking

Analysis result will be generated to the path ./DrafterStage. Then just open the file ./DrafterStage/index.html in browser (Recommended Chrome) :

call graph

In the browser you can interactively browse the Call Graph and the Class Dragram, it is strongly recommended to use drafter in this way.

Export to PNG

Deprecated !

Parameter