Community
Participate
Working Groups
The user story is: I am porting client code of our internal String util library to the Apache Jakarta Commons Land StringUtil. I want to replace all calls of OurStringClass.isEmpty(String) with Apache's StringUtils.isEmpty(String); and others too. This is could be possible if Refactor/Move... would itself be refactored such that I could pick an /existing/ method (as opposed to just a class now). Perhaps the new refactoring could be called Refactor/Replace... where the dialog's class list would have each class be a tree node which would expand to show methods (static and instance methods both). The workaround I use now is to replace the old method with a call to the new method and then do a Refactor/In line... This only works in the case where the arguments are the same of course. So either only matching argument methods need to be enabled in the tree node or the UI gets more complicated since params need to reordered. Thank you for considering this request.
+1 for that! I had exactly the same problem when porting our code to the new codeformatter. I would very hepful to have a refactoring that allows to redirect all calls to a method to a other method. Reordering or even be able to give expressions how parameters should be mapped would be great, but I would keep it simple simple and not offer it. What the user can do is the following: - create first a helper method in a utility class, that has the same signature as the source method. The implementation of this utility class calls the target method (including the reordering and calculation of the parameters) - redirect all calls to the source method to the helper method - inline the helper method.
I don't really see how this refactoring can do a better job than using the inline "workaround", except that you can't inline a whole class. Specify an expression how arguments are mapped is exactly what you would code in the body of the old method. In general what you are asking for is the find/replace in ASTs where you can use some sort of regexp for both the pattern to be found and the replacing AST node. Have you looked at Inject/J. They claim that they have a Eclipse plug-in as well.
How would you use the in-line workaround to replace one static reference with another? Should this case I just encountered be addressed in a separate ticket?
Sorry, I should have been more precise, in my case replacing a 'public static final String' with another in a different class.
this is planed to be implemented for 3.3: Replace invocations
Has there been any progress on this issue? It *seems* to have been planned for 3.2/3.3/3.4 but never landed and I never found anything stating if or why it was dropped. In my particular case I'd love to be able to effectively do a "Introduce Factory", but the factory method *already exists* and is in a binary-only reference (i.e. replace object instantiation with a specific constructor with an invocation of the existing factory method). I've explained my problem in some detail on this SO question: http://stackoverflow.com/questions/7566565/is-there-a-way-to-apply-a-refactoring-script-just-for-its-side-effects I don't know if this issue even includes my use case, but even if it doesn't work with constructors, I could still see this feature as being very useful. Especially in combination with refactoring scripts: developers of a library could distribute a set of refactoring scripts that do at least the trivial steps of conversion to the new version.
We once started work on Replace Invocations, but never found the time to finish it. Manual workaround: - apply Refactor > Introduce Indirection... on the method to replace - in the generated indirection method, replace the body with a call to the better implementation - apply Refactor > Inline... on the indirection method