通过注释处理器中的 AST抽象语法树更改方法主体

问题描述

如何使用 AST 更改方法主体?

以这个类为例:

public class TestClass {

    private Boolean method1(Integer a) {
        Integer b = a + 6;
        return b > 10;
    }
}

我们需要使用 AST 在方法体中添加一行:

public class TestClass {

    private Boolean testMethod(Integer a) {
        Integer b = a + 6;
        b += 2;    //<-- We need to add this line via AST
        return b > 10;
    }
}

我尝试了很多方法,但我从来没有设法改变方法体。希望得到您的帮助!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)