Customize extract field refactoring


We have an old service loader, which would be used as MyService.get().doSomething(). As we clean up code and move to autowiring, it's a 2 step process:
1. refactor: extract field, so that now i have private final MyService myService = MyService.get(); and myService.doSomething() in code
2. find/replace with regex:
find: private final (\w+ \w+) = \w+\.get\(\);
replace: @Autowired private $1;
It'd be great if I could customize the format of the extract field refactor so I don't need to do the 2nd step, which is extra annoying since I can't have find/replace presets, so I keep the patterns in a separate text file...


"Extract field" is hardly related to repalcing.

There is a solution though. Insterad of find/replace, you can use structural replace:

This way you could save it as a template, or as an inspection: 


Konstantin Annikov thanks for the info! I guess I should start familiarizing myself with the Structural SnR.

I still wish this could be done as a single step though, extract to an autowired field, but this is still better than nothing


Please sign in to leave a comment.