前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >IDEA插件ASM Bytecode Outline

IDEA插件ASM Bytecode Outline

作者头像
屈定
发布2018-09-27 12:02:55
7.8K1
发布2018-09-27 12:02:55
举报
文章被收录于专栏:屈定‘s Blog屈定‘s Blog

这款插件对于我学习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

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-02-04,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 下载
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档