Bug 232660 - [move method] Refactor move to a method local instance
Summary: [move method] Refactor move to a method local instance
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 118032
Blocks:
  Show dependency tree
 
Reported: 2008-05-17 11:09 EDT by lorenzo CLA
Modified: 2008-05-22 05:30 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description lorenzo CLA 2008-05-17 11:09:44 EDT
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 {
}
Comment 1 Martin Aeschlimann CLA 2008-05-19 03:59:33 EDT
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)
Comment 2 lorenzo CLA 2008-05-19 05:05:14 EDT
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

Comment 3 Martin Aeschlimann CLA 2008-05-19 05:48:25 EDT
How do we know to take 'd' in d.toBeMoved()? 
Comment 4 lorenzo CLA 2008-05-19 06:38:50 EDT
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.






Comment 5 Martin Aeschlimann CLA 2008-05-22 05:30:40 EDT
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.