I recently switched from Eclipse to IntelliJ Idea, and I'm very pleased with this change. But, I don't get how to write my own structural search template.
I'd like to identify all test methods containing try ... catch ... finally
blocks in order to remove them.
The replace template is second goal, first I'd like to understand how to find them.
I tried to use existing Idea templates to find all methods annotated with @Test
with this template slightly modified :
class $Class$ {
@Test
$ReturnType$ $MethodName$($ParameterType$ $Parameter$);
}
I also used a predefined template to find all try ... catch
blocks, I added the finally
detection:
try {
$TryStatement$;
} catch($ExceptionType$ $ExceptionDcl$) {
$CatchStatement$;
} finally{
$FinallyStatment$;
}
But I can't figure out how to go further and mix these two templates in order to find all test methods containing try ... catch ... finally
blocks.
Here are examples of "bad tests" I would like to find with it, and "good tests" which should not match the structural template:
public class Tests {
@Test
public void badTest() {
// some code
try {
// some code
} catch (Exception e) {
// some code
} finally {
// some code
}
// some code
}
@Test
public void goodTest() throws Exception {
// some code
}
}
Do you guys can give me a clue ?
Best regards,
Julien.