]> git.uio.no Git - ifi-stolz-refaktor.git/commitdiff
cleaning up, changing packages, adding javadoc
authorAnna <sowhow@gmail.com>
Thu, 25 Feb 2016 10:52:16 +0000 (11:52 +0100)
committerAnna <sowhow@gmail.com>
Thu, 25 Feb 2016 10:52:16 +0000 (11:52 +0100)
software/no.uio.ifi.refaktor/plugin.xml
software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/ExtractAndMoveMethodHandler.java [deleted file]
software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/ExtractLocalVariableWithAssertsHandler.java [deleted file]
software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/entrypoints/RefactorAnalysisHandler.java [moved from software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/SearchBasedExtractAndMoveMethodAnalysisHandler.java with 68% similarity]
software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/entrypoints/RefactorHandler.java [moved from software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/RefactorHandler.java with 97% similarity]
software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/entrypoints/SearchBasedExtractAndMoveMethodChangerHandler.java [moved from software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/SearchBasedExtractAndMoveMethodChangerHandler.java with 81% similarity]
software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/entrypoints/SearchBasedExtractLocalVariableWithAssertsHandler.java [moved from software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/SearchBasedExtractLocalVariableWithAssertsHandler.java with 53% similarity]
software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/entrypoints/SearchBasedExtractLocalVariableWithoutAssertsHandler.java [moved from software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/SearchBasedExtractLocalVariableWithoutAssertsHandler.java with 52% similarity]
software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/obsolite/ExtractAndMoveMethodHandler.java [new file with mode: 0644]

index 454095caaf4cc2d44cbe1c2981d3a2fb22c9ee58..31ff08f028b0aa7f5e3a935ae04f0bada2e30bf9 100644 (file)
@@ -92,7 +92,7 @@
             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>
diff --git a/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/ExtractAndMoveMethodHandler.java b/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/ExtractAndMoveMethodHandler.java
deleted file mode 100644 (file)
index abdbf05..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-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);
-       }
-
-}
diff --git a/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/ExtractLocalVariableWithAssertsHandler.java b/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/ExtractLocalVariableWithAssertsHandler.java
deleted file mode 100644 (file)
index d339204..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-//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;
-//     }
-//}
similarity index 68%
rename from software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/SearchBasedExtractAndMoveMethodAnalysisHandler.java
rename to software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/entrypoints/RefactorAnalysisHandler.java
index 4f2c06704021885a1ba073df0435befecfe10e20..797871321605533988cdceda96fe039ef5a20c68 100644 (file)
@@ -1,8 +1,7 @@
-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;
@@ -18,7 +17,14 @@ import org.eclipse.jface.viewers.ITreeSelection;
 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 {
@@ -34,12 +40,12 @@ public class SearchBasedExtractAndMoveMethodAnalysisHandler extends AbstractHand
                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;
@@ -51,5 +57,10 @@ public class SearchBasedExtractAndMoveMethodAnalysisHandler extends AbstractHand
                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);
 
 }
similarity index 97%
rename from software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/RefactorHandler.java
rename to software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/entrypoints/RefactorHandler.java
index d4f0a3f011d85895c29ee131f3c6d1263eb4dea9..596cb2d00104d1a4516dfd85d67b815d384f6ceb 100644 (file)
@@ -1,4 +1,4 @@
-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;
@@ -30,7 +30,6 @@ public abstract class RefactorHandler extends AbstractHandler{
                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;
@@ -1,18 +1,20 @@
-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
  *
@@ -32,7 +34,6 @@ public class SearchBasedExtractAndMoveMethodChangerHandler extends RefactorHandl
        @Override
        protected Refactorer getChanger(IMethod method) {
                return new SearchBasedRefactorChanger<ExtractAndMoveMethodCandidate>(method, new ExtractAndMoveMethodFactory());
-               //return new SearchBasedExtractAndMoveMethodChanger(method);
        }
 
        @Override
@@ -1,31 +1,26 @@
-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
@@ -1,32 +1,26 @@
-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
diff --git a/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/obsolite/ExtractAndMoveMethodHandler.java b/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/obsolite/ExtractAndMoveMethodHandler.java
new file mode 100644 (file)
index 0000000..ec279c1
--- /dev/null
@@ -0,0 +1,70 @@
+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);
+//     }
+//
+//}