Community
Participate
Working Groups
I20070417-0800. Have this: c.doIt(1); c.doIt(i); c.doIt(j); If I extract c.doIt(j) it will also find and update c.doIt(i); but not c.doIt(1);
Looks like a bug, indeed!
Same applies to expression that would resolve to the same binding eg. c.doIt(i+j)
This seems related to bug 112072. I will try to infer what is happening: It look like the "Extract method refactoring" is only looking at like for like AST when attempting to match common code. So if the AST of the code to be extracted contains a variable of type int (or String), then it will be able to extract common code if it also contains a variable of the same type. However, what happens in this case is that there is a int literal (or String), but it is not a int (or String) variable hence why the extract method fails to recognize common code. At least, the extract method code should be enhanced to recognize a literal as a variable-like and extract this literal like it does with a variable to support the sample refactoring provided by Dani Megert. At best, the extract method code should be enhanced to look for expressions of the same type and extract this expression like it does with a variable to support the sample refactoring provided by Benjamin Muskalla. However, I understand that this could be much harder or have performance implications for the algorithm.
For me the workaround is manageable but painful. It transforms a short operation into a long one. Here is my workflow: * Extract methods on all the blocks of code I want to extract, so I often extract several methods to avoid any impact when doing the rest of the steps. * Extract many local variables (Ctrl+Shift+I) on each of the methods * Move the local variables out of the code to extract (Shift+Up) * If the code is big enough, I then attempt an "Extract method" ** If it fails I open WinMerge, compare the code of 2 methods and look for differences. *** Often variable names prevent me from seeing the real AST differences, so I rename them in Eclipse (Ctrl+Shift+R). ** So I go back and forth between Eclipse and WinMerge. ** Once I am happy I found the differences and make the code look the same in both method, then I do the "Extract method" and even then sometimes it fails, then I give up. ** I need to repeat the same process for every extracted methods that I want to extract further. So if the current bug could be fixed, it would be a good improvement to the process above!
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.