vazexqi / CodingSpectator

Watches and analyzes code edits in the Eclipse IDE non-invasively
http://codingspectator.cs.illinois.edu
Other
20 stars 14 forks source link

Instrument extract super class #144

Closed reprogrammer closed 13 years ago

reprogrammer commented 13 years ago

The extract super class refactoring reuses the pull up refactoring. Since we've already instrumented the pull up refactoring (See issue #22), it makes sense to support extract superclass as well.

reprogrammer commented 13 years ago

eb25f7f4b0874337a596a5f7726578cf52eceaaf is our initial attempt in instrumenting the extract superclass refactoring.

We need to capture invocations of the unavailable extract superclass refactoring. Also, I encountered the following exception while trying out the instrumented extract superclass refactoring.

!ENTRY org.eclipse.jdt.ui 4 10001 2011-02-01 19:19:12.123
!MESSAGE Internal Error
!STACK 1
Java Model Exception: Java Model Status [C [in [Working copy] C.java [in  [in src [in P]]]] does not exist]
    at org.eclipse.jdt.internal.core.JavaElement.newNotPresentException(JavaElement.java:492)
    at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed(JavaElement.java:526)
    at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:252)
    at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:238)
    at org.eclipse.jdt.internal.core.SourceType.isInterface(SourceType.java:591)
    at org.eclipse.jdt.internal.ui.refactoring.PullUpMemberPage.isDestinationInterface(PullUpMemberPage.java:873)
    at org.eclipse.jdt.internal.ui.refactoring.PullUpMemberPage.getMembersForAction(PullUpMemberPage.java:851)
    at org.eclipse.jdt.internal.ui.refactoring.PullUpMemberPage.getMethodsForAction(PullUpMemberPage.java:846)
    at org.eclipse.jdt.internal.ui.refactoring.PullUpMemberPage.initializeRefactoring(PullUpMemberPage.java:953)
    at org.eclipse.jdt.internal.ui.refactoring.PullUpMemberPage.updateRefactoringProcessor(PullUpMemberPage.java:1068)
    at org.eclipse.jdt.internal.ui.refactoring.ExtractSupertypeMemberPage.updateRefactoringProcessor(ExtractSupertypeMemberPage.java:588)
    at org.eclipse.jdt.internal.ui.refactoring.ExtractSupertypeMemberPage.handleNameChanged(ExtractSupertypeMemberPage.java:562)
    at org.eclipse.jdt.internal.ui.refactoring.ExtractSupertypeMemberPage$7.modifyText(ExtractSupertypeMemberPage.java:432)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:173)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3540)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3161)
    at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
    at org.eclipse.jface.window.Window.open(Window.java:801)
    at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation$1.run(RefactoringWizardOpenOperation.java:186)
    at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
    at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation.run(RefactoringWizardOpenOperation.java:199)
    at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation.run(RefactoringWizardOpenOperation.java:117)
    at org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter.activate(RefactoringStarter.java:38)
    at org.eclipse.jdt.internal.corext.refactoring.RefactoringExecutionStarter.startExtractSupertypeRefactoring(RefactoringExecutionStarter.java:307)
    at org.eclipse.jdt.internal.ui.actions.ExtractSuperClassAction.run(ExtractSuperClassAction.java:157)
    at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:278)
    at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:250)
    at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
    at org.eclipse.ui.actions.RetargetAction.runWithEvent(RetargetAction.java:230)
    at org.eclipse.ui.internal.WWinPluginAction.runWithEvent(WWinPluginAction.java:234)
    at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
    at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
    at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3540)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3161)
    at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640)
    at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
    at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
    at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
!SUBENTRY 1 org.eclipse.jdt.core 4 969 2011-02-01 19:19:12.124
!MESSAGE C [in [Working copy] C.java [in  [in src [in P]]]] does not exist

The above exception gets thrown only when a prefix of the superclass name does not exist.

vazexqi commented 13 years ago

To make this clearer, here is how we can reproduce the problem:

  1. Type the following into a compilation unit called D.java. class C1 {

    }

    class C3 extends C1 {

    }

    class C2 extends C1 {

    }

  2. Select the class C3 and perform an "Extract Superclass" refactoring on it.
  3. In the dialog, enter 'D'.

You should now see the error above. This is because in the dialog, you will get an error status saying that the compilation unit D already exists. However, because of the way we have instrumented the dialog, we will call initializeRefactoring() which will go ahead and try to perform certain validations on that compilation unit. This is a problem since compilation unit D already exists so you should not perform other validations on it.

vazexqi commented 13 years ago

Addressed in 0cfe99cb68b46059216471f481d0d989a24e8ea9

reprogrammer commented 13 years ago

I ran the test InvalidPullUpSelectedMethodTest on my laptop (Linux) and saw the error show up in a dialog instead of a wizard page. Anyways, the test passes on my machine.

reprogrammer commented 13 years ago

Recorded unavailability of extract super class in 9bb2f9af2bdee17fe554c981b3c5a27a28026b8c .. 3677f2a8e0b94285f7ccd2c0738fe8d0369a99a4.

reprogrammer commented 13 years ago

I merged the branch instrument-extract-supertype into master.

vazexqi commented 13 years ago

Addressed minor typos in be057cda291de2ad57bd1bdd786581d61c6e0ab3