org.eclipse.ui.editors,
org.eclipse.jdt.annotation,
org.hamcrest.core,
- org.junit
+ org.junit,
+ org.eclipse.core.expressions
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Import-Package: org.eclipse.jdt.internal.corext.refactoring,
id="no.uio.ifi.refaktor.commands.treeSelectionInfo"
name="Tree Selection Info">
</command>
+ <command
+ id="no.uio.ifi.refaktor.commands.searchBasedExtractAndMoveMethodAnalysis"
+ name="Search Based Extract And Move Method Analysis">
+ </command>
</extension>
<extension
point="org.eclipse.ui.handlers">
class="no.uio.ifi.refaktor.handlers.TreeSelectionInfoHandler"
commandId="no.uio.ifi.refaktor.commands.treeSelectionInfo">
</handler>
+ <handler
+ class="no.uio.ifi.refaktor.handlers.SearchBasedExtractAndMoveMethodAnalysisHandler"
+ commandId="no.uio.ifi.refaktor.commands.searchBasedExtractAndMoveMethodAnalysis">
+ </handler>
</extension>
<extension
point="org.eclipse.ui.menus">
label="Tree Selection Info"
style="push">
</command>
+ <command
+ commandId="no.uio.ifi.refaktor.commands.searchBasedExtractAndMoveMethodAnalysis"
+ label="Search Based Extract And Move Method Analysis"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <test
+ forcePluginActivation="true"
+ property="no.uio.ifi.refaktor.propertyTesters.treeSelectionPropertyTester.elementType"
+ value="org.eclipse.jdt.core.IMethod">
+ </test>
+ </with>
+ </visibleWhen>
+ </command>
</menu>
</menuContribution>
</extension>
label="Compute Cyclomatic Complexity"
menubarPath="no.uio.ifi.refaktor.menu1/group2">
</action>
- <action
- class="no.uio.ifi.refaktor.popup.actions.SearchBasedExtractAndMoveMethodAnalysisAction"
- enablesFor="1"
- id="no.uio.ifi.refaktor.searchBasedExtractAndMoveMethodAnalysis"
- label="Search Based Extract and Move Method Analysis"
- menubarPath="no.uio.ifi.refaktor.menu1/group2">
- </action>
</objectContribution>
</extension>
<extension
</view>
</perspectiveExtension>
</extension>
+ <extension
+ point="org.eclipse.core.expressions.propertyTesters">
+ <propertyTester
+ class="no.uio.ifi.refaktor.propertyTesters.TreeSelectionPropertyTester"
+ id="no.uio.ifi.refaktor.propertyTesters.treeSelectionPropertyTester"
+ namespace="no.uio.ifi.refaktor.propertyTesters.treeSelectionPropertyTester"
+ properties="elementType"
+ type="org.eclipse.jface.viewers.ITreeSelection">
+ </propertyTester>
+ </extension>
</plugin>
--- /dev/null
+package no.uio.ifi.refaktor.handlers;
+
+import static no.uio.ifi.refaktor.RefaktorAssert.assertThat;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import no.uio.ifi.refaktor.analyze.ExtractAndMoveMethodAnalysisResult;
+import no.uio.ifi.refaktor.analyze.FavorNoUnfixesAnalysisResultComparator;
+import no.uio.ifi.refaktor.analyze.NoTargetFoundException;
+import no.uio.ifi.refaktor.analyze.SearchBasedExtractAndMoveMethodAnalyzer;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+public class SearchBasedExtractAndMoveMethodAnalysisHandler extends AbstractHandler {
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
+ IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
+
+ assertThat(selection, instanceOf(ITreeSelection.class));
+ ITreeSelection treeSelection = (ITreeSelection) selection;
+ Object o = treeSelection.getFirstElement();
+ assertThat(o, instanceOf(IMethod.class));
+ IMethod method = (IMethod) o;
+
+ String message = "";
+ try {
+ SearchBasedExtractAndMoveMethodAnalyzer analyzer = new SearchBasedExtractAndMoveMethodAnalyzer(method, new FavorNoUnfixesAnalysisResultComparator());
+ analyzer.analyze();
+ ExtractAndMoveMethodAnalysisResult result = analyzer.getResult();
+ message = "Result:\n\nText selection:\n" + result.textSelection
+ + "\n\nSelected text:\n" + result.textSelection.getText()
+ + "\n\nNumber of text selections analyzed:\n" + result.numberOfTextSelectionsAnalyzed
+ + "\n\nOriginal target:\n" + result.calculateOriginalTarget();
+ } catch (NoTargetFoundException e) {
+ message = "No solution found for " + method;
+ }
+
+ MessageDialog.openInformation(window.getShell(), "no.uio.ifi.refaktor", message);
+ return null;
+ }
+
+}
+++ /dev/null
-package no.uio.ifi.refaktor.popup.actions;
-
-import no.uio.ifi.refaktor.analyze.ExtractAndMoveMethodAnalysisResult;
-import no.uio.ifi.refaktor.analyze.FavorNoUnfixesAnalysisResultComparator;
-import no.uio.ifi.refaktor.analyze.SearchBasedExtractAndMoveMethodAnalyzer;
-
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.dialogs.MessageDialog;
-
-public class SearchBasedExtractAndMoveMethodAnalysisAction extends IMethodAction {
-
- @Override
- public void run(IAction action) {
- SearchBasedExtractAndMoveMethodAnalyzer analyzer = new SearchBasedExtractAndMoveMethodAnalyzer(m, new FavorNoUnfixesAnalysisResultComparator());
- analyzer.analyze();
- ExtractAndMoveMethodAnalysisResult result = analyzer.getResult();
-
- String message = "Result:\n\nText selection:\n" + result.textSelection
- + "\n\nSelected text:\n" + result.textSelection.getText()
- + "\n\nNumber of text selections analyzed:\n" + result.numberOfTextSelectionsAnalyzed
- + "\n\nOriginal target:\n" + result.calculateOriginalTarget();
-
- MessageDialog.openInformation(shell, "no.uio.ifi.refaktor", message);
- }
-
-}
--- /dev/null
+package no.uio.ifi.refaktor.propertyTesters;
+
+import static no.uio.ifi.refaktor.RefaktorAssert.assertThat;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import no.uio.ifi.refaktor.utils.RefaktorDebug;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.jface.viewers.ITreeSelection;
+
+public class TreeSelectionPropertyTester extends PropertyTester{
+
+ private static final String ELEMENT_TYPE = "elementType";
+
+ @Override
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ assertThat(receiver, instanceOf(ITreeSelection.class));
+ ITreeSelection treeSelection = (ITreeSelection) receiver;
+
+ if (property.equals(ELEMENT_TYPE) && expectedValue instanceof String) {
+ return selectedTypeIsOfExpectedType(treeSelection, (String) expectedValue);
+ }
+
+ return false;
+ }
+
+ private boolean selectedTypeIsOfExpectedType(ITreeSelection treeSelection, String expectedTypeName) {
+ try {
+ Class<?> expectedClass = Class.forName(expectedTypeName);
+ return expectedClass.isInstance(treeSelection.getFirstElement());
+ } catch (ClassNotFoundException e) {
+ RefaktorDebug.log(e);
+ return false;
+ }
+ }
+
+}