【发布时间】:2020-05-06 03:57:07
【问题描述】:
我想知道是否有办法(gradle 脚本或任何脚本或任何其他没有 IDE 的方式)来删除带有某些注释的方法。示例:
class x {
public static void main(String[] args) {
int x = getValue();
System.out.println(x);
}
@RemoveEnabled(id = "getValueMethod1", return = "10")
int getValue() {
return 20;
}
}
现在当我运行脚本或 gradle 目标时,它应该删除 getValue() 方法,输出代码应该变成:
class x {
public static void main(String[] args) {
int x = 10;
System.out.println(x);
}
}
是否有现有的脚本或方法来实现这一点?它可能可以通过 grep 和字符串解析等来实现,但我正在寻找一种更简洁的解决方案,它能够通过注释 id 获取所有方法,并通过格式化删除它们。我尝试在 Google、Stack Overflow 等上搜索,但找不到解决方案。
【问题讨论】:
-
您希望在 IDE 中完成此操作,还是通过读取源代码的程序来完成?
-
嗨@MauricePerry - 最好是一个程序或一个gradle目标......可以独立调用的东西。谢谢。
标签: java code-generation automated-refactoring transpiler