'How to replace all `public void` "Test"-methods with just "void" (with SSR and IntelliJ)

I've recently joined a codebase that no one seemed to ever run SonarLint against, and now every test class I open in IntelliJ is highlighted like a Christmas tree - all test methods are public, even though JUnit5 is used.

Tired of removing those public modifiers manually, I decided to implement an SSR template to do that for me. However, I can't seem to make it work with method parameter annotations! (which seem to be rather usual thing with JMockit)

The best I can have thus far is this:

  1. Open Edit->Find->Replace structurally
  2. Paste this into Search field:
        @$MethodAnnotation$
        public void $MethodName$(@mockit.Injectable $ParameterType$ $Parameter$) {
            $statement$;
        }
    
  3. Choose file type: Java - Class Member
  4. Add filter for MethodAnnotation variable: Text=org.junit.jupiter.api.Test
  5. Add Min=0 for statement and Parameter variables
  6. Paste this into Replace field:
        @$MethodAnnotation$
        void $MethodName$(@Injectable $ParameterType$ $Parameter$) {
            $statement$;
        }
    
    (mind the indentation, otherwise it will be problematic!)
  7. Select Complete match value for Search target
  8. Find

As you can see, the annotation is hard-coded, which of course limits the applicability of this snippet seriously.

Is this a problem with IntelliJ or rather my bad knowledge of SSR? What would be a proposed solution?



Sources

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

Source: Stack Overflow

Solution Source