]>
Commit | Line | Data |
---|---|---|
2d553c1f AE |
1 | package no.uio.ifi.refaktor.handlers; |
2 | ||
3 | import no.uio.ifi.refaktor.change.SearchBasedExtractLocalVariableWithAssertsChanger; | |
4 | import no.uio.ifi.refaktor.change.changers.RefaktorChanger; | |
5 | import no.uio.ifi.refaktor.change.changers.SearchBasedExtractAndMoveMethodChanger; | |
6 | import no.uio.ifi.refaktor.change.exceptions.RefaktorChangerException; | |
7 | import no.uio.ifi.refaktor.debugging.RefaktorDebug; | |
8 | ||
9 | import org.eclipse.core.commands.AbstractHandler; | |
10 | import org.eclipse.core.commands.ExecutionEvent; | |
11 | import org.eclipse.core.commands.ExecutionException; | |
12 | import org.eclipse.core.runtime.CoreException; | |
13 | import org.eclipse.core.runtime.NullProgressMonitor; | |
14 | import org.eclipse.jdt.core.IMethod; | |
15 | import org.eclipse.jface.dialogs.MessageDialog; | |
16 | import org.eclipse.jface.viewers.ISelection; | |
17 | import org.eclipse.jface.viewers.ITreeSelection; | |
18 | import org.eclipse.ui.IWorkbenchWindow; | |
19 | import org.eclipse.ui.handlers.HandlerUtil; | |
20 | ||
21 | public class SearchBasedExtractLocalVariableWithAssertsHandler extends AbstractHandler{ | |
22 | ||
23 | @Override | |
24 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
25 | ISelection selection = HandlerUtil.getCurrentSelectionChecked(event); | |
26 | IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); | |
27 | ||
28 | assert selection instanceof ITreeSelection; | |
29 | ITreeSelection treeSelection = (ITreeSelection) selection; | |
30 | Object o = treeSelection.getFirstElement(); | |
31 | assert o instanceof IMethod; | |
32 | IMethod method = (IMethod) o; | |
33 | ||
34 | RefaktorChanger changer = new SearchBasedExtractLocalVariableWithAssertsChanger(method); | |
df7eb88a AE |
35 | try { |
36 | changer.checkPreconditions(); | |
37 | changer.execute(new NullProgressMonitor()); | |
38 | MessageDialog.openInformation(window.getShell(), "no.uio.ifi.refaktor", changer.getClass() + " has been excuted"); | |
39 | return null; | |
40 | } catch (RefaktorChangerException e) { | |
41 | RefaktorDebug.log(e); | |
42 | } catch (CoreException e) { | |
43 | RefaktorDebug.log(e); | |
44 | } | |
45 | ||
46 | MessageDialog.openInformation(window.getShell(), "no.uio.ifi.refaktor", changer.getClass() + " did not execute correctly"); | |
2d553c1f AE |
47 | return null; |
48 | } | |
49 | ||
50 | } |