How to automatically replace arguments in a method and all its invocations
Suppose I have a Java method:
void method(int a, int b) {}
and lots of places where it is called:
method(10, 12);
method(33, 44);
...
How would you automatically refactor arguments replacing to achieve the following result?:
void method(int b, int a) {}
method(12, 10);
method(44, 33);
...
Note: I am looking for a generic solution handling all cases of methods and arguments and prefer using Eclipse tooling.
Edit: Is ther开发者_如何学运维e a way to do it programmatically for a set methods matching given criteria from various classes?
Right-click the method (in the source code editor, the outline view or any other view) and select Refactor -> Change Method Signature.
This will pop up a dialog where you can change a lot of options about the method. Changing the order of the arguments will also change the invocations of that method (use preview to verify this).
http://fhc.quickmediasolutions.com/image/1635916007.png
Note that the changes in the invocation only works when you've got the source code of the class doing the invocation checked out and it references the source you're manipulating.
You can refactor the method declaration. Then it will updates all method call instances according to your change.
You can find more details here.
精彩评论