1 package no.uio.ifi.refaktor.handlers;
3 import no.uio.ifi.refaktor.analyze.ExtractAndMoveMethodAnalysisResult;
4 import no.uio.ifi.refaktor.analyze.analyzers.SearchBasedExtractAndMoveMethodAnalyzer;
5 import no.uio.ifi.refaktor.analyze.comparators.FavorNoUnfixesAnalysisResultComparator;
6 import no.uio.ifi.refaktor.analyze.exceptions.NoTargetFoundException;
8 import org.eclipse.core.commands.AbstractHandler;
9 import org.eclipse.core.commands.ExecutionEvent;
10 import org.eclipse.core.commands.ExecutionException;
11 import org.eclipse.jdt.core.IMethod;
12 import org.eclipse.jface.dialogs.MessageDialog;
13 import org.eclipse.jface.viewers.ISelection;
14 import org.eclipse.jface.viewers.ITreeSelection;
15 import org.eclipse.ui.IWorkbenchWindow;
16 import org.eclipse.ui.handlers.HandlerUtil;
18 public class SearchBasedExtractAndMoveMethodAnalysisHandler extends AbstractHandler {
21 public Object execute(ExecutionEvent event) throws ExecutionException {
22 ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
23 IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
25 assert selection instanceof ITreeSelection;
26 ITreeSelection treeSelection = (ITreeSelection) selection;
27 Object o = treeSelection.getFirstElement();
28 assert o instanceof IMethod;
29 IMethod method = (IMethod) o;
33 SearchBasedExtractAndMoveMethodAnalyzer analyzer = new SearchBasedExtractAndMoveMethodAnalyzer(method, new FavorNoUnfixesAnalysisResultComparator());
35 ExtractAndMoveMethodAnalysisResult result = analyzer.getResult();
36 message = "Result:\n\nText selection:\n" + result.textSelection
37 + "\n\nNumber of text selections analyzed:\n" + result.numberOfTextSelectionsAnalyzed
38 + "\n\nOriginal target:\n" + result.calculateOriginalTarget()
39 + "\n\nSelected text:\n" + result.textSelection.getText();
40 } catch (NoTargetFoundException e) {
41 message = "No solution found for " + method;
44 MessageDialog.openInformation(window.getShell(), "no.uio.ifi.refaktor", message);