使用宏进行 intellij 大规模重构
我正在使用 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;
}
有没有办法使用某种宏来实现此目的? 这种代码跨越多个文件,这些文件的名称中都具有相同的后缀,
谢谢
I am working on a project in intellij using java and spring.
I want to change in multiple files my api's in a similar way like this:
instead of:
public void someApi(HttpServletRequest request, HttpServletResponse response) throws Exception {
someThrift thriftRequest = getThrift(...);
someOtherThrift thriftResponse = …
setThriftResponse(...);
}
use this:
@ThriftResponse
public someThrift getReports(@ThriftRequestBody someThrift thriftRequest) throws Exception {
someOtherThrift thriftResponse = …
return thriftResponse;
}
is there a way to achieve this using some sort of a macro?
this kind of code spans on multiple files that all have the same suffix in their name as well
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如评论中所述,您可以使用 结构搜索和替换< /a>.它允许您使用通过计数、正则表达式甚至 Groovy 脚本定义的变量约束的模板来搜索和替换代码片段。
创建模板的最简单方法是浏览现有模板列表,找到与您想要实现的目标相似的模板并对其进行修改。
As said in the comments, you can use Structural search and replace. It allows you to search and replace fragment of codes using a template defined with variables constraint by count numbers, regular expressions, and even Groovy scripts.
The easiest way to create a template is to browse the list of existing ones, find one similar to what you want to achieve and modify it.