有没有一种方法可以在find中给包含数字的字符串加1,并在intellij中替换



我有这样的代码:

public void testSomething1(({

}

public void testSomething2(({

}

public void testSomething3(({

}

我希望查找和替换的结果是这样的:

public void testSomething2(({

}

public void testSomething3(({

}

public void 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="&quot;def (_,name, number) = (method.name =~ /(p{L}+)(d+)/)[0]&#10;name + (Integer.parseInt(number) + 1)&#10;&quot;" />
</replaceConfiguration>

您可以复制此模式,并在"结构搜索"对话框的工具按钮下的菜单中使用Import Template from Clipboard操作。

最新更新