IDEA插件ASM Bytecode Outline

這款插件對於我學習JVM上的其他語言幫助非常大,很多高級語法糖反編譯之後能夠明白背後的原理,目前插件已經上傳到JetBrains官方倉庫,歡迎試用。 插件地址: https://plugins.jetbrains.com/plugin/11035-cfr-decompile

源碼地址: https://github.com/mrdear/asm-bytecode-intellij


對於有Java基礎的人學習kotlin的高效方式就是看反編譯的代碼.那麼對於其各種語法糖可以很好的瞭解背後的原理.那麼就需要一款反編譯插件ASM Bytecode Outline. https://github.com/melix/asm-bytecode-intellij,原版插件只支持翻譯爲字節碼指令對於開發人員來說不是很友好,比如下面代碼.

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

這反編譯的bytecode形式看起來不是很友好.

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後的結果如下,看起來清晰了許多.

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章