]> git.uio.no Git - ifi-stolz-refaktor.git/blame - software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/SearchBasedExtractAndMoveMethodAnalysisHandler.java
Moving analyzers to no.uio.ifi.refaktor.analyze.analyzers
[ifi-stolz-refaktor.git] / software / no.uio.ifi.refaktor / src / no / uio / ifi / refaktor / handlers / SearchBasedExtractAndMoveMethodAnalysisHandler.java
CommitLineData
c0b43d62
EK
1package no.uio.ifi.refaktor.handlers;
2
3import static no.uio.ifi.refaktor.RefaktorAssert.assertThat;
4import static org.hamcrest.CoreMatchers.instanceOf;
5import no.uio.ifi.refaktor.analyze.ExtractAndMoveMethodAnalysisResult;
c0b43d62 6import no.uio.ifi.refaktor.analyze.NoTargetFoundException;
33b364ef 7import no.uio.ifi.refaktor.analyze.analyzers.SearchBasedExtractAndMoveMethodAnalyzer;
d6c79186 8import no.uio.ifi.refaktor.analyze.comparators.FavorNoUnfixesAnalysisResultComparator;
c0b43d62
EK
9
10import org.eclipse.core.commands.AbstractHandler;
11import org.eclipse.core.commands.ExecutionEvent;
12import org.eclipse.core.commands.ExecutionException;
13import org.eclipse.jdt.core.IMethod;
14import org.eclipse.jface.dialogs.MessageDialog;
15import org.eclipse.jface.viewers.ISelection;
16import org.eclipse.jface.viewers.ITreeSelection;
17import org.eclipse.ui.IWorkbenchWindow;
18import org.eclipse.ui.handlers.HandlerUtil;
19
20public class SearchBasedExtractAndMoveMethodAnalysisHandler extends AbstractHandler {
21
22 @Override
23 public Object execute(ExecutionEvent event) throws ExecutionException {
24 ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
25 IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
26
27 assertThat(selection, instanceOf(ITreeSelection.class));
28 ITreeSelection treeSelection = (ITreeSelection) selection;
29 Object o = treeSelection.getFirstElement();
30 assertThat(o, instanceOf(IMethod.class));
31 IMethod method = (IMethod) o;
32
33 String message = "";
34 try {
35 SearchBasedExtractAndMoveMethodAnalyzer analyzer = new SearchBasedExtractAndMoveMethodAnalyzer(method, new FavorNoUnfixesAnalysisResultComparator());
36 analyzer.analyze();
37 ExtractAndMoveMethodAnalysisResult result = analyzer.getResult();
38 message = "Result:\n\nText selection:\n" + result.textSelection
39 + "\n\nSelected text:\n" + result.textSelection.getText()
40 + "\n\nNumber of text selections analyzed:\n" + result.numberOfTextSelectionsAnalyzed
41 + "\n\nOriginal target:\n" + result.calculateOriginalTarget();
42 } catch (NoTargetFoundException e) {
43 message = "No solution found for " + method;
44 }
45
46 MessageDialog.openInformation(window.getShell(), "no.uio.ifi.refaktor", message);
47 return null;
48 }
49
50}