'intellij mass refactoring using macros

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



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1