Project: JDT
Bug 254721 org.eclipse.jdt.ui.actions.MoveAction doesn't work with explicitly given selection
Reported: 2008-11-10 05:28:57 | Status: resolved fixed

Build ID: M20080911-1700 Steps To Reproduce: 1. In your code instantiate the org.eclipse.jdt.ui.actions.MoveAction 2. Invoke run(IStructuredSelection selection) with a selection corresponding to certain java class Result: The command won't be invoked with the given selection. Instead of this the selection from the IWorkbenchSite object will be taken (if it's possible) More information: I've debugged the code and found out that (in that particular use case) the run(IStructuredSelection selection) method invokes the internal org.eclipse.jdt.internal.ui.refactoring.reorg.ReorgMoveAction. But it doesn't invoke it with the IStructuredSelection object given as parameter. Instead, it invokes its run() method without parameters and, as a result, ReorgMoveAction tries to get the selection from the IWorkbenchSite object with which it was initialized, instead of the given IStructuredSelection as parameter of the method. This way it makes impossible to use the MoveAction for moving java classes if we want to give selection directly to the run() method. As a workaround I use directly ReorgMoveAction which is not very clear, since it's an internal API. I would've think that this is an intended behavior, but, if it is so, why the run(IStructuredSelection selection) is exposed as a public API? Besides, the RenameAction, for example works well for the same use case!

Files changed in fix:
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/MoveAction.java