]> git.uio.no Git - ifi-stolz-refaktor.git/blob - software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/SearchBasedExtractAndMoveMethodAnalysisHandler.java
ExtractAndMoveMethodAnalysisResult: renaming to ExtractAndMoveMethodCandidate
[ifi-stolz-refaktor.git] / software / no.uio.ifi.refaktor / src / no / uio / ifi / refaktor / handlers / SearchBasedExtractAndMoveMethodAnalysisHandler.java
1 package no.uio.ifi.refaktor.handlers;
2
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.FavorNoUnfixesCandidateComparator;
6 import no.uio.ifi.refaktor.analyze.exceptions.NoTargetFoundException;
7
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;
17
18 public class SearchBasedExtractAndMoveMethodAnalysisHandler extends AbstractHandler {
19
20         @Override
21         public Object execute(ExecutionEvent event) throws ExecutionException {
22                 ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
23                 IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
24
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;
30
31                 String message = "";
32                 try {
33                         SearchBasedExtractAndMoveMethodAnalyzer analyzer = new SearchBasedExtractAndMoveMethodAnalyzer(method, new FavorNoUnfixesCandidateComparator());
34                         analyzer.analyze();
35                         ExtractAndMoveMethodCandidate result = analyzer.getCandidate();
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;
42                 }
43
44                 MessageDialog.openInformation(window.getShell(), "no.uio.ifi.refaktor", message);
45                 return null;
46         }
47
48 }