I have a whole load of method calls like this:
thing.doOneThing(a);
thing.doOneThing(b);
thing.doOneThing(c);
thing.doOneThing(d);
// ... etc
But the Thing
class has an equivalent doManyThings
method, so this could be rewritten as:
thing.doManyThings(a, b, c, d /* etc */);
What's the right way to do this refactoring in intellij?
I've been using structural replacements to do:
- Replace
$t$.doOneThing($a$); $t$.doOneThing($b$);
with$t$.doManyThings($a$, $b$);
- Replace
$t$.doManyThings($a$); $t$.doOneThing($b$);
($a$
having infinite multiplicity) with$t$.doManyThings($a$, $b$);
- Replace
$t$.doManyThings($a$); $t$.doManyThings($b$);
($a$
and$b$
having infinite multiplicities) with$t$.doManyThings($a$, $b$);
I have to keep on doing the last step over and over, because it merges pairs of matching statements, so this just halves the number of calls to doManyThings
each time, and it needs to be done a few times to merge them all.
This feels harder than it ought to be - please can you point me to the super-obvious better way to achieve this? :)