1 package no.uio.ifi.refaktor.handlers;
3 import no.uio.ifi.refaktor.analyze.ExtractAndMoveMethodCandidate;
4 import no.uio.ifi.refaktor.analyze.analyzers.SearchBasedExtractAndMoveMethodAnalyzer;
5 import no.uio.ifi.refaktor.analyze.comparators.FavorNoUnfixesExtractAndMoveCandidateComparator;
6 import no.uio.ifi.refaktor.analyze.exceptions.NoTargetFoundException;
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;
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;
21 public class SearchBasedExtractAndMoveMethodAnalysisHandler extends AbstractHandler {
24 public Object execute(ExecutionEvent event) throws ExecutionException {
25 ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
26 IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
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;
36 StatisticsAspect.init();
37 SearchBasedExtractAndMoveMethodAnalyzer analyzer = new SearchBasedExtractAndMoveMethodAnalyzer(method, new FavorNoUnfixesExtractAndMoveCandidateComparator());
39 ExtractAndMoveMethodCandidate result = analyzer.getCandidate();
40 message = "Result:\n\nText selection:\n" + result.textSelection
41 + "\n\nNumber of text selections analyzed:\n" + result.numberOfTextSelectionsAnalyzed
42 + "\n\nOriginal target:\n" + result.calculateOriginalTarget()
43 + "\n\nSelected text:\n" + result.textSelection.getText();
44 } catch (NoTargetFoundException e) {
45 message = "No solution found for " + method;
47 Statistics snapshot = StatisticsAspect.getSnapshot();
48 RefaktorDebug.log(snapshot.toString());
51 MessageDialog.openInformation(window.getShell(), "no.uio.ifi.refaktor", message);