]> git.uio.no Git - ifi-stolz-refaktor.git/blame - software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/SearchBasedExtractLocalVariableWithAssertsHandler.java
idk experimental stuff
[ifi-stolz-refaktor.git] / software / no.uio.ifi.refaktor / src / no / uio / ifi / refaktor / handlers / SearchBasedExtractLocalVariableWithAssertsHandler.java
CommitLineData
2d553c1f
AE
1package no.uio.ifi.refaktor.handlers;
2
3import no.uio.ifi.refaktor.change.SearchBasedExtractLocalVariableWithAssertsChanger;
4import no.uio.ifi.refaktor.change.changers.RefaktorChanger;
5import no.uio.ifi.refaktor.change.changers.SearchBasedExtractAndMoveMethodChanger;
6import no.uio.ifi.refaktor.change.exceptions.RefaktorChangerException;
7import no.uio.ifi.refaktor.debugging.RefaktorDebug;
8
9import org.eclipse.core.commands.AbstractHandler;
10import org.eclipse.core.commands.ExecutionEvent;
11import org.eclipse.core.commands.ExecutionException;
12import org.eclipse.core.runtime.CoreException;
13import org.eclipse.core.runtime.NullProgressMonitor;
14import org.eclipse.jdt.core.IMethod;
15import org.eclipse.jface.dialogs.MessageDialog;
16import org.eclipse.jface.viewers.ISelection;
17import org.eclipse.jface.viewers.ITreeSelection;
18import org.eclipse.ui.IWorkbenchWindow;
19import org.eclipse.ui.handlers.HandlerUtil;
20
21public 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}