IDEA插件ASM Bytecode Outline

对于有Java基础的人学习kotlin的高效方式就是看反编译的代码.那么对于其各种语法糖可以很好的了解背后的原理.那么就需要一款反编译插件ASM Bytecode Outline.
https://github.com/melix/asm-bytecode-intellij,原版插件只支持翻译为字节码指令对于开发人员来说不是很友好,比如下面代码.

1
2
3
data class TableModel(val tableName: String,
val columns: List<ColumnModel>) {
}

这反编译的bytecode形式看起来不是很友好.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public final class com/itoolshub/pojo/model/table/TableModel {

// compiled from: TableModel.kt
// access flags 0x12
private final Ljava/lang/String; tableName
@Lorg/jetbrains/annotations/NotNull;() // invisible

// access flags 0x12
// signature Ljava/util/List<Lcom/itoolshub/pojo/model/table/ColumnModel;>;
// declaration: java.util.List<com.itoolshub.pojo.model.table.ColumnModel>
private final Ljava/util/List; columns
@Lorg/jetbrains/annotations/NotNull;() // invisible

// access flags 0x11
public final getTableName()Ljava/lang/String;
@Lorg/jetbrains/annotations/NotNull;() // invisible
L0
LINENUMBER 8 L0
ALOAD 0
GETFIELD com/itoolshub/pojo/model/table/TableModel.tableName : Ljava/lang/String;
ARETURN
L1
LOCALVARIABLE this Lcom/itoolshub/pojo/model/table/TableModel; L0 L1 0
MAXSTACK = 1
MAXLOCALS = 1

// access flags 0x11
// signature ()Ljava/util/List<Lcom/itoolshub/pojo/model/table/ColumnModel;>;
// declaration: java.util.List<com.itoolshub.pojo.model.table.ColumnModel> getColumns()
public final getColumns()Ljava/util/List;
............等等

集成的Cfr decompile后的结果如下,看起来清晰了许多.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public final class TableModel {
@NotNull
private final String tableName;
@NotNull
private final List<ColumnModel> columns;

@NotNull
public final String getTableName() {
return this.tableName;
}
@NotNull
public final List<ColumnModel> getColumns() {
return this.columns;
}
public TableModel(@NotNull String tableName, @NotNull List<ColumnModel> columns) {
Intrinsics.checkParameterIsNotNull((Object)tableName, (String)"tableName");
Intrinsics.checkParameterIsNotNull(columns, (String)"columns");
this.tableName = tableName;
this.columns = columns;
}
@NotNull
public final String component1() {
return this.tableName;
}
@NotNull
public final List<ColumnModel> component2() {
return this.columns;
}
...... 等等

下载#

原版代码风格不是很适应,因此改了好多自我感觉不合理的地方,应该不会提pull request了.
https://github.com/mrdear/asm-bytecode-intellij

感谢您的阅读,本文由 屈定's Blog 版权所有。如若转载,请注明出处:屈定's Blog(http://mrdear.cn/2018/02/04/工具/IDEA插件ASM Bytecode Outline/
Kotlin学习资料整理
使用RSS和Wordpress定制化阅读