]> git.uio.no Git - ifi-stolz-refaktor.git/blame - software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/SearchBasedExtractAndMoveMethodAnalysisHandler.java
skeleton done!
[ifi-stolz-refaktor.git] / software / no.uio.ifi.refaktor / src / no / uio / ifi / refaktor / handlers / SearchBasedExtractAndMoveMethodAnalysisHandler.java
CommitLineData
c0b43d62
EK
1package no.uio.ifi.refaktor.handlers;
2
7fa217a1 3import no.uio.ifi.refaktor.analyze.ExtractAndMoveMethodCandidate;
33b364ef 4import no.uio.ifi.refaktor.analyze.analyzers.SearchBasedExtractAndMoveMethodAnalyzer;
df7eb88a 5import no.uio.ifi.refaktor.analyze.comparators.FavorNoUnfixesExtractAndMoveCandidateComparator;
ee0f23c0 6import no.uio.ifi.refaktor.analyze.exceptions.NoTargetFoundException;
b76bc807
EK
7import no.uio.ifi.refaktor.debugging.RefaktorDebug;
8import no.uio.ifi.refaktor.statistics.StatisticsAspect;
9import no.uio.ifi.refaktor.statistics.StatisticsAspect.Statistics;
c0b43d62
EK
10
11import org.eclipse.core.commands.AbstractHandler;
12import org.eclipse.core.commands.ExecutionEvent;
13import org.eclipse.core.commands.ExecutionException;
14import org.eclipse.jdt.core.IMethod;
15import org.eclipse.jface.dialogs.MessageDialog;
16import org.eclipse.jface.viewers.ISelection;
17import org.eclipse.jface.viewers.ITreeSelection;
18import org.eclipse.ui.IWorkbenchWindow;
19import org.eclipse.ui.handlers.HandlerUtil;
20
21public 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}