]>
Commit | Line | Data |
---|---|---|
c0b43d62 EK |
1 | package no.uio.ifi.refaktor.handlers; |
2 | ||
3 | import static no.uio.ifi.refaktor.RefaktorAssert.assertThat; | |
4 | import static org.hamcrest.CoreMatchers.instanceOf; | |
5 | import no.uio.ifi.refaktor.analyze.ExtractAndMoveMethodAnalysisResult; | |
c0b43d62 | 6 | import no.uio.ifi.refaktor.analyze.NoTargetFoundException; |
33b364ef | 7 | import no.uio.ifi.refaktor.analyze.analyzers.SearchBasedExtractAndMoveMethodAnalyzer; |
d6c79186 | 8 | import no.uio.ifi.refaktor.analyze.comparators.FavorNoUnfixesAnalysisResultComparator; |
c0b43d62 EK |
9 | |
10 | import org.eclipse.core.commands.AbstractHandler; | |
11 | import org.eclipse.core.commands.ExecutionEvent; | |
12 | import org.eclipse.core.commands.ExecutionException; | |
13 | import org.eclipse.jdt.core.IMethod; | |
14 | import org.eclipse.jface.dialogs.MessageDialog; | |
15 | import org.eclipse.jface.viewers.ISelection; | |
16 | import org.eclipse.jface.viewers.ITreeSelection; | |
17 | import org.eclipse.ui.IWorkbenchWindow; | |
18 | import org.eclipse.ui.handlers.HandlerUtil; | |
19 | ||
20 | public 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 | } |