Bug 365286 - [move method] Propose to convert to static (if possible) when no target is found
Summary: [move method] Propose to convert to static (if possible) when no target is found
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.8   Edit
Hardware: PC Windows 7
: P4 enhancement with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-01 04:47 EST by Deepak Azad CLA
Modified: 2011-12-01 11:49 EST (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 Deepak Azad CLA 2011-12-01 04:47:00 EST
From bug 364947 comment 2
> Our participants received the following error message from the Move Instance
> Method refactoring five times:
> 
> > This method cannot be moved, since no possible targets have been found.
> >
> > Only a class which is reachable from within this method can be a valid target. The target must therefore be the declaring class of a parameter or field type. In addition the target must be writable.
> 
> Out of the 16 failed attempts to apply the Move Instance Method refactoring, at
> least six of the failures could have been easily avoided had the tool inferred
> that the selected instance method could safely be made static.

bug 364947 comment 4
> Created attachment 207601 [details]
> In the second alternative design of the input dialog of the Move Instance
> Method refactoring tool, the tool may infer that the selected method can be
> safely made static.
> 
> Another way of making the refactoring tool more flexible is to detect if the
> selected method can be safely converted to a static method. If the selected
> method doesn't depend on any instance fields or methods of the enclosing class,
> it could be made static. Once the method is made static, it can be easily moved
> to any class. In this case, the refactoring dialog would only need to ask for
> the destination class. See the attached figure for how the dialog could be
> simplified in this case.
In case no target is found, it might be useful to propose to convert the method to static. Since 3.7 we have the compiler diagnostic 'Method can be made static'. Maybe we can leverage the feature or its implementation here? Once this situation is detected we can use the 'Move Static Members' refactoring.

Another alternative solution is proposed in bug 364947 comment 5.
Comment 1 Markus Keller CLA 2011-12-01 10:49:11 EST
See also bug 118032 and bug 10605.