Community
Participate
Working Groups
Hi, considering the following code it looks reasonable to be able to move the toBeMoved method to Destination. In the context of the method run() the "target" is visibile and the method is not used in any other part of the class neither of the project. I can move it manually without problems so I think I should be able to do it automatically. I'm assuming the "target search" is dependent of the selection/cursor location. If not so it could inspect all the method calls looking for shared targets or just for the full list. Bye Lorenzo public class Test { public static void main(String[] args) { Test t = new Test(); t.run(); } public void run() { Destination d = new Destination(); toBeMoved(); } public void toBeMoved() { } } class Destination { }
How would update the reference to 'toBeMoved' in 'run'? The target search is currently limited to the types of the method parameters. There we know how to update the references. run(x) -> x.run(this)
Hi, the method I want to move is the toBeMoved method. So I expect this transformation this.toBeMoved() -> d.toBeMoved(this); Side note: In this specific case the toBeMoved() is not referencing any field or method of the enclosing instance (it could be made static without errors) so I think the "this" reference should not the passed, or at least to be passed as optional. But this is a separate issue. Bye Lorenzo
How do we know to take 'd' in d.toBeMoved()?
You can provide a list of all available targets to be choosed from, just like it happens when you move a method to a class field. I'm assuming the target list building can be dependant on the selection/cursor location. So if I select the method call inside run() then only the targets visibile in the run() method are available in addition to the class fields. Instead if you activate the refactoring selecting the method declaration you could inspect all the method calls (in this and other classes) looking for targets shared by all "calling context" or just for the full list. This can be quite complex for big projects, so maybe only the first option could be provided.
You can't prompt if there are lots of references to the moved method. It's also not clear to me what happens when there is no instance around. I think we should go for the refactoring 'make static' (bug 118032) and then what you want will be possible as a two step process. At the moment you have to make the method static yourself first. Or you add the target as argument, and then use 'move method'. No plans for this.