commandId="no.uio.ifi.refaktor.commands.projectWideSearchBasedExtractAndMoveMethodChanger">
</handler>
<handler
- class="no.uio.ifi.refaktor.handlers.SearchBasedExtractAndMoveMethodChangerHandler"
+ class="no.uio.ifi.refaktor.handlers.entrypoints.SearchBasedExtractAndMoveMethodChangerHandler"
commandId="no.uio.ifi.refaktor.commands.searchBasedExtractAndMoveMethodChanger">
</handler>
<handler
commandId="no.uio.ifi.refaktor.commands.packageWideSearchBasedExtractAndMoveMethodChanger">
</handler>
<handler
- class="no.uio.ifi.refaktor.handlers.SearchBasedExtractLocalVariableWithAssertsHandler"
+ class="no.uio.ifi.refaktor.handlers.entrypoints.SearchBasedExtractLocalVariableWithAssertsHandler"
commandId="no.uio.ifi.refaktor.commands.searchBasedExtractLocalVariableWithAssertsChanger">
</handler>
<handler
- class="no.uio.ifi.refaktor.handlers.SearchBasedExtractLocalVariableWithoutAssertsHandler"
+ class="no.uio.ifi.refaktor.handlers.entrypoints.SearchBasedExtractLocalVariableWithoutAssertsHandler"
commandId="no.uio.ifi.refaktor.commands.searchBasedExtractLocalVariableWithoutAssertsChanger">
</handler>
</extension>
+++ /dev/null
-package no.uio.ifi.refaktor.handlers;
-
-import no.uio.ifi.refaktor.change.changers.ExtractAndMoveMethodChanger;
-import no.uio.ifi.refaktor.change.changers.RefaktorChanger;
-import no.uio.ifi.refaktor.change.exceptions.RefaktorChangerException;
-import no.uio.ifi.refaktor.textselection.CompilationUnitTextSelection;
-import no.uio.ifi.refaktor.utils.DocumentUtils;
-
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.dialogs.InputDialog;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-public class ExtractAndMoveMethodHandler extends WorkspaceModificationHandler {
-
- private CompilationUnitTextSelection compilationUnitTextSelection;
-
- @Override
- protected String getTitle() {
- return "Extract and Move Method";
- }
-
- @Override
- protected String getMessage() {
- return "Name of extracted method:";
- }
-
- @Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- compilationUnitTextSelection = DocumentUtils.getStrippedCompilationUnitTextSelectionFromExecutionEvent(event);
- DocumentUtils.setSelectionForEditor(compilationUnitTextSelection, DocumentUtils.getEditorFrom(event));
- return super.execute(event);
- }
-
- @Override
- protected boolean preconditionsAreMet(ExecutionEvent event) throws ExecutionException {
- try {
- getChanger().checkPreconditions();
- } catch (RefaktorChangerException e) {
- giveMessage(e.getMessage(), event);
- return false;
- }
- return true;
- }
-
- @Override
- protected boolean userConfirms(ExecutionEvent event)
- throws ExecutionException {
- IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
- InputDialog dialog = new InputDialog(window.getShell(), getTitle(), getMessage(), ExtractAndMoveMethodChanger.generateName(), null);
- int returnCode = dialog.open();
- String newMethodName = dialog.getValue().trim();
- ((ExtractAndMoveMethodChanger) getChanger()).setNewMethodName(newMethodName);
- return returnCode == InputDialog.OK;
- }
-
- private void giveMessage(String reason, ExecutionEvent event) throws ExecutionException {
- MessageDialog.openInformation(HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell(),
- "Preconditions are not met", reason);
- }
-
- @Override
- protected RefaktorChanger createChanger() {
- return new ExtractAndMoveMethodChanger(compilationUnitTextSelection);
- }
-
-}
+++ /dev/null
-//package no.uio.ifi.refaktor.handlers;
-//import org.eclipse.core.commands.AbstractHandler;
-//import org.eclipse.core.commands.ExecutionEvent;
-//import org.eclipse.core.commands.ExecutionException;
-//import org.eclipse.core.runtime.CoreException;
-//import org.eclipse.core.runtime.NullProgressMonitor;
-//import org.eclipse.jface.dialogs.MessageDialog;
-//import org.eclipse.ui.IWorkbenchWindow;
-//import org.eclipse.ui.handlers.HandlerUtil;
-//
-//import no.uio.ifi.refaktor.analyze.exceptions.SelectionInvalidException;
-//import no.uio.ifi.refaktor.change.changers.ExtractLocalVariableWithAssertsChanger;
-//import no.uio.ifi.refaktor.textselection.CompilationUnitTextSelection;
-//import no.uio.ifi.refaktor.utils.DocumentUtils;
-//
-///**
-// * This should not be used any more
-// * @author Anna E
-// *
-// */
-//public class ExtractLocalVariableWithAssertsHandler extends AbstractHandler {
-//
-//
-// @Override
-// public Object execute(ExecutionEvent event) throws ExecutionException {
-// CompilationUnitTextSelection cstextsel = DocumentUtils.getCompilationUnitTextSelectionFromExecutionEvent(event);
-//
-// ExtractLocalVariableWithAssertsChanger changer = new ExtractLocalVariableWithAssertsChanger(cstextsel);
-// try {
-// changer.checkPreconditions();
-// changer.execute(new NullProgressMonitor());
-// }catch(SelectionInvalidException e){
-// IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
-// MessageDialog.openInformation(window.getShell(), "no.uio.ifi.refaktor", "Invalid selection: " + cstextsel.getText());
-// }catch (CoreException e) {
-// e.printStackTrace();
-// }
-//
-//
-//
-// return null;
-// }
-//}
-package no.uio.ifi.refaktor.handlers;
+package no.uio.ifi.refaktor.handlers.entrypoints;
-import no.uio.ifi.refaktor.analyze.analyzers.SearchBasedExtractAndMoveMethodAnalyzer;
-import no.uio.ifi.refaktor.analyze.candidates.ExtractAndMoveMethodCandidate;
-import no.uio.ifi.refaktor.analyze.comparators.FavorNoUnfixesExtractAndMoveCandidateComparator;
+import no.uio.ifi.refaktor.analyze.analyzers.SearchBasedRefactorAnalyzer;
+import no.uio.ifi.refaktor.analyze.candidates.RefactorCandidate;
import no.uio.ifi.refaktor.analyze.exceptions.NoTargetFoundException;
import no.uio.ifi.refaktor.debugging.RefaktorDebug;
import no.uio.ifi.refaktor.statistics.StatisticsAspect;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
-public class SearchBasedExtractAndMoveMethodAnalysisHandler extends AbstractHandler {
+/**
+ * Not in use, but can easily be connected to a menu item to view information
+ * about the extract and move analysis
+ *
+ * @author Anna
+ *
+ */
+public abstract class RefactorAnalysisHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
String message = "";
try {
StatisticsAspect.init();
- SearchBasedExtractAndMoveMethodAnalyzer analyzer = new SearchBasedExtractAndMoveMethodAnalyzer(method, new FavorNoUnfixesExtractAndMoveCandidateComparator());
+
+ SearchBasedRefactorAnalyzer<RefactorCandidate> analyzer = getAnalyzer(method);
analyzer.analyze();
- ExtractAndMoveMethodCandidate result = analyzer.getCandidate();
+ RefactorCandidate result = analyzer.getCandidate();
+
message = "Result:\n\nText selection:\n" + result.getRefactoringArgument()
- + "\n\nNumber of text selections analyzed:\n" + result.numberOfTextSelectionsAnalyzed
- + "\n\nOriginal target:\n" + result.calculateOriginalTarget()
+ "\n\nSelected text:\n" + result.getRefactoringArgument().getText();
} catch (NoTargetFoundException e) {
message = "No solution found for " + method;
MessageDialog.openInformation(window.getShell(), "no.uio.ifi.refaktor", message);
return null;
}
+ /**
+ * Subclasses must implement this method
+ * @return the appropriate analyzer for the subclass
+ */
+ protected abstract SearchBasedRefactorAnalyzer<RefactorCandidate> getAnalyzer(IMethod method);
}
-package no.uio.ifi.refaktor.handlers;
+package no.uio.ifi.refaktor.handlers.entrypoints;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
assert selection instanceof ITreeSelection;
ITreeSelection treeSelection = (ITreeSelection) selection;
Object o = treeSelection.getFirstElement();
-// Object c = o.getClass();
Refactorer changer;
if(o instanceof IMethod && supports((IMethod) o)){
IMethod method = (IMethod) o;
-package no.uio.ifi.refaktor.handlers;
+package no.uio.ifi.refaktor.handlers.entrypoints;
import no.uio.ifi.refaktor.analyze.candidates.ExtractAndMoveMethodCandidate;
import no.uio.ifi.refaktor.change.SearchBasedRefactorChanger;
import no.uio.ifi.refaktor.factories.ExtractAndMoveMethodFactory;
import no.uio.ifi.refaktor.forTests.Refactorer;
-
import org.eclipse.core.resources.IProject;
import org.eclipse.jdt.core.IMethod;
/**
* The handler of Search based extract and move method; the class that is connected to the UI
+ *
* {@link RefactorHandler#execute(org.eclipse.core.commands.ExecutionEvent)} is called from the UI and shared with other subclasses of {@link RefactorHandler}
- * The only behavior specific to this subclass is which {@link Refactorer} subclass to be used and which types the changer can change. This must be expressed
- * in the implementation of the supports-methods.
+ * The only behavior specific to this subclass is which {@link RefactorCandidate} subclass to be used and which types of objects
+ * ({@link IMethod}, {@link IProject}) the changer can take as input.
+ *
+ * This must be expressed in the implementation of the supports-methods.
*
* @author Anna Eilertsen
*
@Override
protected Refactorer getChanger(IMethod method) {
return new SearchBasedRefactorChanger<ExtractAndMoveMethodCandidate>(method, new ExtractAndMoveMethodFactory());
- //return new SearchBasedExtractAndMoveMethodChanger(method);
}
@Override
-package no.uio.ifi.refaktor.handlers;
+package no.uio.ifi.refaktor.handlers.entrypoints;
import no.uio.ifi.refaktor.analyze.candidates.ExtractLocalVariableCandidate;
import no.uio.ifi.refaktor.change.SearchBasedRefactorChanger;
import no.uio.ifi.refaktor.change.changers.ProjectWideRefactorChanger;
-import no.uio.ifi.refaktor.change.changers.RefaktorChanger;
-import no.uio.ifi.refaktor.change.changers.SearchBasedExtractAndMoveMethodChanger;
-import no.uio.ifi.refaktor.change.exceptions.RefaktorChangerException;
-import no.uio.ifi.refaktor.debugging.RefaktorDebug;
import no.uio.ifi.refaktor.factories.ExtractLocalVariableWithAssertsFactory;
import no.uio.ifi.refaktor.forTests.Refactorer;
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.internal.core.JavaProject;
-import org.eclipse.jdt.internal.core.PackageFragment;
-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;
-
import org.eclipse.core.resources.IProject;
+/**
+ * The handler of Search based local variable with asserts; the class that is connected to the UI
+ *
+ * {@link RefactorHandler#execute(org.eclipse.core.commands.ExecutionEvent)} is called from the UI and shared with other subclasses of {@link RefactorHandler}
+ * The only behavior specific to this subclass is which {@link RefactorCandidate} subclass to be used and which types of objects
+ * ({@link IMethod}, {@link IProject}) the changer can take as input.
+ *
+ * This must be expressed in the implementation of the supports-methods.
+ *
+ * @author Anna Eilertsen
+ *
+ */
public class SearchBasedExtractLocalVariableWithAssertsHandler extends RefactorHandler{
@Override
-package no.uio.ifi.refaktor.handlers;
+package no.uio.ifi.refaktor.handlers.entrypoints;
import no.uio.ifi.refaktor.analyze.candidates.ExtractLocalVariableCandidate;
import no.uio.ifi.refaktor.change.SearchBasedRefactorChanger;
import no.uio.ifi.refaktor.change.changers.ProjectWideRefactorChanger;
-import no.uio.ifi.refaktor.change.changers.RefaktorChanger;
-import no.uio.ifi.refaktor.change.changers.SearchBasedExtractAndMoveMethodChanger;
-import no.uio.ifi.refaktor.change.exceptions.RefaktorChangerException;
-import no.uio.ifi.refaktor.debugging.RefaktorDebug;
-import no.uio.ifi.refaktor.factories.ExtractLocalVariableWithAssertsFactory;
import no.uio.ifi.refaktor.factories.ExtractLocalVariableWithoutAssertsFactory;
import no.uio.ifi.refaktor.forTests.Refactorer;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.internal.core.JavaProject;
-import org.eclipse.jdt.internal.core.PackageFragment;
-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;
-
import org.eclipse.core.resources.IProject;
-
+/**
+ * Currently not connected to the UI
+ *
+ * The handler of Search based extract local variable; the class that is connected to the UI
+ *
+ * {@link RefactorHandler#execute(org.eclipse.core.commands.ExecutionEvent)} is called from the UI and shared with other subclasses of {@link RefactorHandler}
+ * The only behavior specific to this subclass is which {@link RefactorCandidate} subclass to be used and which types of objects
+ * ({@link IMethod}, {@link IProject}) the changer can take as input.
+ *
+ * This must be expressed in the implementation of the supports-methods.
+ *
+ * @author Anna Eilertsen
+ *
+ */
public class SearchBasedExtractLocalVariableWithoutAssertsHandler extends RefactorHandler{
@Override
--- /dev/null
+package no.uio.ifi.refaktor.handlers.obsolite;
+//package no.uio.ifi.refaktor.handlers;
+//
+//import no.uio.ifi.refaktor.change.changers.ExtractAndMoveMethodChanger;
+//import no.uio.ifi.refaktor.change.changers.RefaktorChanger;
+//import no.uio.ifi.refaktor.change.exceptions.RefaktorChangerException;
+//import no.uio.ifi.refaktor.textselection.CompilationUnitTextSelection;
+//import no.uio.ifi.refaktor.utils.DocumentUtils;
+//
+//import org.eclipse.core.commands.ExecutionEvent;
+//import org.eclipse.core.commands.ExecutionException;
+//import org.eclipse.jface.dialogs.InputDialog;
+//import org.eclipse.jface.dialogs.MessageDialog;
+//import org.eclipse.ui.IWorkbenchWindow;
+//import org.eclipse.ui.handlers.HandlerUtil;
+// //this class should not be used any more
+//public class ExtractAndMoveMethodHandler extends WorkspaceModificationHandler {
+//
+// private CompilationUnitTextSelection compilationUnitTextSelection;
+//
+// @Override
+// protected String getTitle() {
+// return "Extract and Move Method";
+// }
+//
+// @Override
+// protected String getMessage() {
+// return "Name of extracted method:";
+// }
+//
+// @Override
+// public Object execute(ExecutionEvent event) throws ExecutionException {
+// compilationUnitTextSelection = DocumentUtils.getStrippedCompilationUnitTextSelectionFromExecutionEvent(event);
+// DocumentUtils.setSelectionForEditor(compilationUnitTextSelection, DocumentUtils.getEditorFrom(event));
+// return super.execute(event);
+// }
+//
+// @Override
+// protected boolean preconditionsAreMet(ExecutionEvent event) throws ExecutionException {
+// try {
+// getChanger().checkPreconditions();
+// } catch (RefaktorChangerException e) {
+// giveMessage(e.getMessage(), event);
+// return false;
+// }
+// return true;
+// }
+//
+// @Override
+// protected boolean userConfirms(ExecutionEvent event)
+// throws ExecutionException {
+// IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
+// InputDialog dialog = new InputDialog(window.getShell(), getTitle(), getMessage(), ExtractAndMoveMethodChanger.generateName(), null);
+// int returnCode = dialog.open();
+// String newMethodName = dialog.getValue().trim();
+// ((ExtractAndMoveMethodChanger) getChanger()).setNewMethodName(newMethodName);
+// return returnCode == InputDialog.OK;
+// }
+//
+// private void giveMessage(String reason, ExecutionEvent event) throws ExecutionException {
+// MessageDialog.openInformation(HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell(),
+// "Preconditions are not met", reason);
+// }
+//
+// @Override
+// protected RefaktorChanger createChanger() {
+// return new ExtractAndMoveMethodChanger(compilationUnitTextSelection);
+// }
+//
+//}