使用宏的 intellij 质量重构

intellij mass refactoring using macros

我正在使用 java 和 spring 在 intellij 中开发一个项目。 我想以类似的方式更改 api 的多个文件:

而不是:

public void someApi(HttpServletRequest request, HttpServletResponse response) throws Exception {
    someThrift thriftRequest = getThrift(...);
    someOtherThrift thriftResponse = …
    setThriftResponse(...);
}

使用这个:

@ThriftResponse
public someThrift getReports(@ThriftRequestBody someThrift thriftRequest) throws Exception {
    someOtherThrift thriftResponse = …
    return thriftResponse;
}

有没有办法使用某种宏来实现这一点? 这种代码跨越多个文件,这些文件的名称也具有相同的后缀

谢谢

如评论中所述,可以使用Structural search and replace。它允许您使用由计数、正则表达式甚至 Groovy 脚本定义的变量约束定义的模板搜索和替换代码片段。

创建模板最简单的方法是浏览现有模板列表,找到一个与您想要实现的相似的模板并进行修改。