]>
Commit | Line | Data |
---|---|---|
c0b43d62 EK |
1 | package no.uio.ifi.refaktor.handlers; |
2 | ||
7fa217a1 | 3 | import no.uio.ifi.refaktor.analyze.ExtractAndMoveMethodCandidate; |
33b364ef | 4 | import no.uio.ifi.refaktor.analyze.analyzers.SearchBasedExtractAndMoveMethodAnalyzer; |
df7eb88a | 5 | import no.uio.ifi.refaktor.analyze.comparators.FavorNoUnfixesExtractAndMoveCandidateComparator; |
ee0f23c0 | 6 | import no.uio.ifi.refaktor.analyze.exceptions.NoTargetFoundException; |
b76bc807 EK |
7 | import no.uio.ifi.refaktor.debugging.RefaktorDebug; |
8 | import no.uio.ifi.refaktor.statistics.StatisticsAspect; | |
9 | import no.uio.ifi.refaktor.statistics.StatisticsAspect.Statistics; | |
c0b43d62 EK |
10 | |
11 | import org.eclipse.core.commands.AbstractHandler; | |
12 | import org.eclipse.core.commands.ExecutionEvent; | |
13 | import org.eclipse.core.commands.ExecutionException; | |
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 SearchBasedExtractAndMoveMethodAnalysisHandler 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 | ||
3cb3a16b | 28 | assert selection instanceof ITreeSelection; |
c0b43d62 EK |
29 | ITreeSelection treeSelection = (ITreeSelection) selection; |
30 | Object o = treeSelection.getFirstElement(); | |
3cb3a16b | 31 | assert o instanceof IMethod; |
c0b43d62 EK |
32 | IMethod method = (IMethod) o; |
33 | ||
34 | String message = ""; | |
35 | try { | |
e62b181d | 36 | StatisticsAspect.init(); |
df7eb88a | 37 | SearchBasedExtractAndMoveMethodAnalyzer analyzer = new SearchBasedExtractAndMoveMethodAnalyzer(method, new FavorNoUnfixesExtractAndMoveCandidateComparator()); |
c0b43d62 | 38 | analyzer.analyze(); |
7fa217a1 | 39 | ExtractAndMoveMethodCandidate result = analyzer.getCandidate(); |
c0b43d62 | 40 | message = "Result:\n\nText selection:\n" + result.textSelection |
c0b43d62 | 41 | + "\n\nNumber of text selections analyzed:\n" + result.numberOfTextSelectionsAnalyzed |
5c77e485 EK |
42 | + "\n\nOriginal target:\n" + result.calculateOriginalTarget() |
43 | + "\n\nSelected text:\n" + result.textSelection.getText(); | |
c0b43d62 EK |
44 | } catch (NoTargetFoundException e) { |
45 | message = "No solution found for " + method; | |
e62b181d EK |
46 | } finally { |
47 | Statistics snapshot = StatisticsAspect.getSnapshot(); | |
48 | RefaktorDebug.log(snapshot.toString()); | |
c0b43d62 EK |
49 | } |
50 | ||
51 | MessageDialog.openInformation(window.getShell(), "no.uio.ifi.refaktor", message); | |
52 | return null; | |
53 | } | |
54 | ||
55 | } |