How do I search and replace structurally in Intellij
-
03-07-2019 - |
Question
I am migrating my Junit tests from Junit v3 to Junit v4.
I was hoping to use the search and replace structurally "srs" to add an @Test annotation before all methods starting with test.* using my favorite IDE Intellij.
I just cant figura out how to do it... I can create a query that will find all methods without an annotation (there is an example bundled in Intellij) but when used to do a replace either my class gets replaced by only the method names OR nothing is found.
Maybe a regexp is easier :-)
/Konstantin
Solution
It is not possible, as of now, but there are requests for class members replacements.
Here is a useful link for getting started with ssr: https://www.jetbrains.com/idea/docs/ssr.pdf
OTHER TIPS
I tried with the following SSR but I have the same problem than you :
Search template :
public class $TestCase$ extends $TestCaseClazz$ {
public void $testMethod$();
}
Replacement template :
@Test public void $testMethod$();
And I check "This variable is target of the search" on testMethod. The preview seems ok, but IntelliJ actually delete the whole method :(
Open Search -> Replace in path
Set Directory to the directory where your test is placed
Set search string to: public void test.
Set replace string to: @Test\n\tpublic void test.
Check Regular Expression box.
Enjoy.