intellij-idea - 有没有办法将 1 添加到包含 intellij 中查找和替换数字的字符串中?
问题描述
我的代码如下所示:
公共无效 testSomething1() {
}
公共无效 testSomething2() {
}
公共无效 testSomething3() {
}
我希望使用查找和替换的结果看起来像这样:
公共无效 testSomething2() {
}
公共无效 testSomething3() {
}
公共无效 testSomething4() {
我需要这个,因为我刚刚意识到我需要在 2 和 3 之间添加另一个测试并保持其余部分不变。我希望我可以在最后添加它,但我不能,我必须使用这个测试生成工具并为学校项目实施测试。我有 51 个测试,我不想手动移动 n + 1 进行测试,特别是因为有一个评论提到了这个数字。哦,请告诉我有一种方法T_T。谢谢!
解决方案
你可以用Edit | Find | Replace Structurally
这个。使用如下模板:
<replaceConfiguration name="Counting" text="void $method$();" recursive="false" type="JAVA" pattern_context="member" reformatAccordingToStyle="false" shortenFQN="false" replacement="void $replacement$();">
<constraint name="__context__" within="" contains="" />
<constraint name="method" regexp="(testSomething)(\d+)" within="" contains="" />
<variableDefinition name="replacement" script=""def (_,name, number) = (method.name =~ /(\p{L}+)(\d+)/)[0] name + (Integer.parseInt(number) + 1) "" />
</replaceConfiguration>
您可以复制此模式并使用Import Template from Clipboard
结构搜索对话框工具按钮下的菜单中的操作。
推荐阅读
- java - 在 Quarkus 应用程序中需要 resteasy 吗?
- javascript - jquery Datatable 操作导致整个页面重新加载
- c# - 使用时间戳 python 查询 DNS RR
- c++ - 根据机器上安装的库依赖编译不同的代码
- powershell - powershell 返回错误:(403) WebException using New-pnpList
- javascript - 使用循环播放重复的歌曲
- spring - 如何处理 Observable
- html - 如何让项目与标签内联
- flash - 如何让 flash 在我的电子应用程序中工作?
- python - Python“魔术方法”是真正的方法吗?