### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.manipulation Index: META-INF/MANIFEST.MF =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.manipulation/META-INF/MANIFEST.MF,v retrieving revision 1.22 diff -u -r1.22 MANIFEST.MF --- META-INF/MANIFEST.MF 4 Mar 2011 18:57:12 -0000 1.22 +++ META-INF/MANIFEST.MF 21 Jul 2011 22:58:23 -0000 @@ -2,7 +2,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.jdt.core.manipulation; singleton:=true -Bundle-Version: 1.4.0.qualifier +Bundle-Version: 1.5.0.qualifier Bundle-Vendor: %providerName Bundle-Activator: org.eclipse.jdt.internal.core.manipulation.JavaManipulationPlugin Bundle-Localization: plugin Index: refactoring/org/eclipse/jdt/core/refactoring/descriptors/JavaRefactoringContribution.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/core/refactoring/descriptors/JavaRefactoringContribution.java,v retrieving revision 1.8 diff -u -r1.8 JavaRefactoringContribution.java --- refactoring/org/eclipse/jdt/core/refactoring/descriptors/JavaRefactoringContribution.java 11 Sep 2008 11:58:11 -0000 1.8 +++ refactoring/org/eclipse/jdt/core/refactoring/descriptors/JavaRefactoringContribution.java 21 Jul 2011 22:58:23 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. + * Copyright (c) 2006, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.jdt.core.refactoring.descriptors; @@ -16,6 +17,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.ltk.core.refactoring.Refactoring; +import org.eclipse.ltk.core.refactoring.RefactoringContext; import org.eclipse.ltk.core.refactoring.RefactoringContribution; import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; import org.eclipse.ltk.core.refactoring.RefactoringStatus; @@ -53,8 +55,39 @@ * @return * the refactoring, or null * @throws CoreException - * if an error occurs while creating the refactoring + * if an error occurs while creating the refactoring * @since 1.2 + * @deprecated since 1.5. Override + * {@link #createRefactoringContext(JavaRefactoringDescriptor, RefactoringStatus)} instead. */ - public abstract Refactoring createRefactoring(JavaRefactoringDescriptor descriptor, RefactoringStatus status) throws CoreException; + public Refactoring createRefactoring(JavaRefactoringDescriptor descriptor, + RefactoringStatus status) throws CoreException { + return null; + } + + /** + * Creates the a new refactoring context. + *

+ * The default implementation of this method wraps refactoring in a trivial refactoring + * context. Subclasses may override this method to create a custom refactoring context. + *

+ * + * @param descriptor + * the refactoring descriptor + * @param status + * the status used for the resulting status + * @return + * the refactoring, or null + * @throws CoreException + * if an error occurs while creating the refactoring context + * @since 1.5 + */ + public RefactoringContext createRefactoringContext(JavaRefactoringDescriptor descriptor, + RefactoringStatus status) throws CoreException { + // Delegate to createRefactoring method for backward compatibility. + Refactoring refactoring= createRefactoring(descriptor, status); + if (refactoring == null) + return null; + return new RefactoringContext(refactoring); + } } \ No newline at end of file Index: refactoring/org/eclipse/jdt/internal/core/refactoring/descriptors/RenameResourceRefactoringContribution.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/internal/core/refactoring/descriptors/RenameResourceRefactoringContribution.java,v retrieving revision 1.3 diff -u -r1.3 RenameResourceRefactoringContribution.java --- refactoring/org/eclipse/jdt/internal/core/refactoring/descriptors/RenameResourceRefactoringContribution.java 11 Sep 2008 11:58:13 -0000 1.3 +++ refactoring/org/eclipse/jdt/internal/core/refactoring/descriptors/RenameResourceRefactoringContribution.java 21 Jul 2011 22:58:23 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. + * Copyright (c) 2005, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.jdt.internal.core.refactoring.descriptors; @@ -15,6 +16,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.ltk.core.refactoring.Refactoring; +import org.eclipse.ltk.core.refactoring.RefactoringContext; import org.eclipse.ltk.core.refactoring.RefactoringContribution; import org.eclipse.ltk.core.refactoring.RefactoringCore; import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; @@ -35,6 +37,8 @@ /** * {@inheritDoc} + * @deprecated since 1.4. Use + * {@link #createRefactoringContext(JavaRefactoringDescriptor, RefactoringStatus)} instead. */ public Refactoring createRefactoring(JavaRefactoringDescriptor javaDescriptor, RefactoringStatus status) throws CoreException { if (javaDescriptor instanceof RenameResourceDescriptor) { @@ -59,6 +63,29 @@ /** * {@inheritDoc} */ + public RefactoringContext createRefactoringContext(JavaRefactoringDescriptor javaDescriptor, RefactoringStatus status) throws CoreException { + if (javaDescriptor instanceof RenameResourceDescriptor) { + RenameResourceDescriptor descriptor= (RenameResourceDescriptor) javaDescriptor; + + // use the LTK RenameResourceDescriptor to create the refactoring + + RefactoringContribution newContribution= RefactoringCore.getRefactoringContribution(org.eclipse.ltk.core.refactoring.resource.RenameResourceDescriptor.ID); + if (newContribution != null) { + RefactoringDescriptor ltkDescriptor= newContribution.createDescriptor(); + if (ltkDescriptor instanceof org.eclipse.ltk.core.refactoring.resource.RenameResourceDescriptor) { + ((org.eclipse.ltk.core.refactoring.resource.RenameResourceDescriptor) ltkDescriptor).setNewName(descriptor.getNewName()); + ((org.eclipse.ltk.core.refactoring.resource.RenameResourceDescriptor) ltkDescriptor).setResourcePath(descriptor.getResourcePath()); + return ltkDescriptor.createRefactoringContext(status); + } + } + status.addFatalError(DescriptorMessages.RenameResourceRefactoringContribution_error_cannot_access); + } + return null; + } + + /** + * {@inheritDoc} + */ public RefactoringDescriptor createDescriptor() { return new RenameResourceDescriptor(); } #P org.eclipse.jdt.ui Index: META-INF/MANIFEST.MF =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/META-INF/MANIFEST.MF,v retrieving revision 1.89 diff -u -r1.89 MANIFEST.MF --- META-INF/MANIFEST.MF 4 Mar 2011 18:57:13 -0000 1.89 +++ META-INF/MANIFEST.MF 21 Jul 2011 22:58:24 -0000 @@ -2,7 +2,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.jdt.ui; singleton:=true -Bundle-Version: 3.7.0.qualifier +Bundle-Version: 3.8.0.qualifier Bundle-Activator: org.eclipse.jdt.internal.ui.JavaPlugin Bundle-ActivationPolicy: lazy Bundle-Vendor: %providerName Index: core refactoring/org/eclipse/jdt/internal/corext/refactoring/RefactoringExecutionStarter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/RefactoringExecutionStarter.java,v retrieving revision 1.66 diff -u -r1.66 RefactoringExecutionStarter.java --- core refactoring/org/eclipse/jdt/internal/corext/refactoring/RefactoringExecutionStarter.java 27 Apr 2011 07:45:26 -0000 1.66 +++ core refactoring/org/eclipse/jdt/internal/corext/refactoring/RefactoringExecutionStarter.java 21 Jul 2011 22:58:25 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.jdt.internal.corext.refactoring; @@ -434,8 +435,14 @@ public static void startRenameRefactoring(final IJavaElement element, final Shell shell) throws CoreException { final RenameSupport support= createRenameSupport(element, null, RenameSupport.UPDATE_REFERENCES); - if (support != null && support.preCheck().isOK()) - support.openDialog(shell); + if (support != null) { + try { + if (support.preCheck().isOK()) + support.openDialog(shell); + } finally { + support.dispose(); + } + } } public static void startRenameResourceRefactoring(final IResource resource, final Shell shell) { Index: ui refactoring/org/eclipse/jdt/internal/ui/refactoring/binary/BinaryRefactoringHistoryWizard.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/binary/BinaryRefactoringHistoryWizard.java,v retrieving revision 1.17 diff -u -r1.17 BinaryRefactoringHistoryWizard.java --- ui refactoring/org/eclipse/jdt/internal/ui/refactoring/binary/BinaryRefactoringHistoryWizard.java 1 Mar 2011 11:51:09 -0000 1.17 +++ ui refactoring/org/eclipse/jdt/internal/ui/refactoring/binary/BinaryRefactoringHistoryWizard.java 21 Jul 2011 22:58:25 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.jdt.internal.ui.refactoring.binary; @@ -38,6 +39,7 @@ import org.eclipse.ltk.core.refactoring.Change; import org.eclipse.ltk.core.refactoring.Refactoring; +import org.eclipse.ltk.core.refactoring.RefactoringContext; import org.eclipse.ltk.core.refactoring.RefactoringContribution; import org.eclipse.ltk.core.refactoring.RefactoringCore; import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; @@ -485,7 +487,7 @@ * {@inheritDoc} */ @Override - protected Refactoring createRefactoring(RefactoringDescriptor descriptor, RefactoringStatus status, IProgressMonitor monitor) throws CoreException { + protected RefactoringContext createRefactoringContext(RefactoringDescriptor descriptor, RefactoringStatus status, IProgressMonitor monitor) throws CoreException { Assert.isNotNull(descriptor); createNecessarySourceCode(monitor); @@ -523,7 +525,7 @@ return null; } } - return descriptor.createRefactoring(status); + return descriptor.createRefactoringContext(status); } /** Index: ui refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/RenameLinkedMode.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/RenameLinkedMode.java,v retrieving revision 1.37 diff -u -r1.37 RenameLinkedMode.java --- ui refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/RenameLinkedMode.java 1 Mar 2011 11:50:56 -0000 1.37 +++ ui refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/RenameLinkedMode.java 21 Jul 2011 22:58:25 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.jdt.internal.ui.refactoring.reorg; @@ -354,14 +355,19 @@ if (renameSupport == null) return; - Shell shell= fEditor.getSite().getShell(); boolean executed; - if (fShowPreview) { // could have been updated by undoAndCreateRenameSupport(..) - executed= renameSupport.openDialog(shell, true); - } else { - renameSupport.perform(shell, fEditor.getSite().getWorkbenchWindow()); - executed= true; + try { + Shell shell= fEditor.getSite().getShell(); + if (fShowPreview) { // could have been updated by undoAndCreateRenameSupport(..) + executed= renameSupport.openDialog(shell, true); + } else { + renameSupport.perform(shell, fEditor.getSite().getWorkbenchWindow()); + executed= true; + } + } finally { + renameSupport.dispose(); } + if (executed) { restoreFullSelection(); } @@ -454,15 +460,18 @@ public void startFullDialog() { cancel(); + RenameSupport renameSupport= null; try { String newName= fNamePosition.getContent(); - RenameSupport renameSupport= undoAndCreateRenameSupport(newName); + renameSupport= undoAndCreateRenameSupport(newName); if (renameSupport != null) renameSupport.openDialog(fEditor.getSite().getShell()); } catch (CoreException e) { JavaPlugin.log(e); } catch (BadLocationException e) { JavaPlugin.log(e); + } finally { + renameSupport.dispose(); } } Index: ui/org/eclipse/jdt/ui/refactoring/RenameSupport.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/refactoring/RenameSupport.java,v retrieving revision 1.58 diff -u -r1.58 RenameSupport.java --- ui/org/eclipse/jdt/ui/refactoring/RenameSupport.java 27 Apr 2011 07:29:05 -0000 1.58 +++ ui/org/eclipse/jdt/ui/refactoring/RenameSupport.java 21 Jul 2011 22:58:25 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.jdt.ui.refactoring; @@ -21,6 +22,7 @@ import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.operation.IRunnableContext; +import org.eclipse.ltk.core.refactoring.RefactoringContext; import org.eclipse.ltk.core.refactoring.RefactoringCore; import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.ltk.core.refactoring.participants.RenameProcessor; @@ -74,7 +76,7 @@ * @noextend This class is not intended to be subclassed by clients. */ public class RenameSupport { - + private RefactoringContext fRefactoringContext; private RenameRefactoring fRefactoring; private RefactoringStatus fPreCheckStatus; @@ -104,6 +106,20 @@ } /** + * Disposes of this object and the associated refactoring context. The dispose method + * will be called exactly once after the refactoring operation is complete or reported an error. + *

+ * Note: Since the dispose method was introduced in 3.8 (Juno), it may not be called + * reliably by older code. + *

+ * @since 3.8 + */ + public void dispose() { + if (fRefactoringContext != null) + fRefactoringContext.dispose(); + } + + /** * Opens the refactoring dialog for this rename support. * * @param parent a shell used as a parent for the refactoring dialog. @@ -241,7 +257,9 @@ private RenameSupport(RenameJavaElementDescriptor descriptor) throws CoreException { RefactoringStatus refactoringStatus= new RefactoringStatus(); - fRefactoring= (RenameRefactoring) descriptor.createRefactoring(refactoringStatus); + fRefactoringContext= descriptor.createRefactoringContext(refactoringStatus); + fRefactoring= fRefactoringContext != null ? + (RenameRefactoring) fRefactoringContext.getRefactoring() : null; if (refactoringStatus.hasFatalError()) { fPreCheckStatus= refactoringStatus; } else { #P org.eclipse.jdt.ui.tests Index: examples/org/eclipse/jdt/ui/examples/TestMoveDescriptorAction.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests/examples/org/eclipse/jdt/ui/examples/TestMoveDescriptorAction.java,v retrieving revision 1.3 diff -u -r1.3 TestMoveDescriptorAction.java --- examples/org/eclipse/jdt/ui/examples/TestMoveDescriptorAction.java 31 Dec 2008 21:14:27 -0000 1.3 +++ examples/org/eclipse/jdt/ui/examples/TestMoveDescriptorAction.java 21 Jul 2011 22:58:29 -0000 @@ -32,6 +32,7 @@ import org.eclipse.ltk.core.refactoring.CheckConditionsOperation; import org.eclipse.ltk.core.refactoring.PerformRefactoringOperation; import org.eclipse.ltk.core.refactoring.Refactoring; +import org.eclipse.ltk.core.refactoring.RefactoringContext; import org.eclipse.ltk.core.refactoring.RefactoringContribution; import org.eclipse.ltk.core.refactoring.RefactoringCore; import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; @@ -85,10 +86,9 @@ } catch (Exception e) { JavaTestPlugin.log(e); } - } + private void performAction(IProgressMonitor monitor) throws CoreException { - IPackageFragmentRoot root= (IPackageFragmentRoot) fCU.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); RefactoringContribution refactoringContribution= RefactoringCore.getRefactoringContribution(IJavaRefactorings.MOVE); @@ -103,14 +103,17 @@ RefactoringStatus status= new RefactoringStatus(); - Refactoring refactoring= moveDes.createRefactoring(status); - PerformRefactoringOperation op= new PerformRefactoringOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS); - - op.run(monitor); + final RefactoringContext context= moveDes.createRefactoringContext(status); + try { + final Refactoring refactoring= context != null ? context.getRefactoring() : null; + PerformRefactoringOperation op= new PerformRefactoringOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS); + op.run(monitor); + } finally { + if (context != null) + context.dispose(); + } } - - /* (non-Javadoc) * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) */ #P org.eclipse.jdt.ui.tests.refactoring Index: test cases/org/eclipse/jdt/ui/tests/refactoring/BinaryReferencesTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/BinaryReferencesTests.java,v retrieving revision 1.12 diff -u -r1.12 BinaryReferencesTests.java --- test cases/org/eclipse/jdt/ui/tests/refactoring/BinaryReferencesTests.java 6 Apr 2011 05:49:08 -0000 1.12 +++ test cases/org/eclipse/jdt/ui/tests/refactoring/BinaryReferencesTests.java 21 Jul 2011 22:58:30 -0000 @@ -26,6 +26,7 @@ import org.eclipse.ltk.core.refactoring.CheckConditionsOperation; import org.eclipse.ltk.core.refactoring.Refactoring; +import org.eclipse.ltk.core.refactoring.RefactoringContext; import org.eclipse.ltk.core.refactoring.RefactoringCore; import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.ltk.core.refactoring.participants.MoveRefactoring; @@ -119,10 +120,16 @@ private static List doRefactoring(JavaRefactoringDescriptor descriptor) throws CoreException { RefactoringStatus status= new RefactoringStatus(); - Refactoring refactoring= descriptor.createRefactoring(status); - assertTrue(status.isOK()); - - return doCheckConditions(refactoring); + final RefactoringContext context= descriptor.createRefactoringContext(status); + try { + final Refactoring refactoring= context != null ? context.getRefactoring() : null; + assertTrue(status.isOK()); + + return doCheckConditions(refactoring); + } finally { + if (context != null) + context.dispose(); + } } private static List doCheckConditions(Refactoring refactoring) throws CoreException { @@ -159,13 +166,21 @@ descriptor.setMatchStrategy(RenameJavaElementDescriptor.STRATEGY_SUFFIX); descriptor.setUpdateReferences(true); + RefactoringStatus validationStatus; RefactoringStatus status= new RefactoringStatus(); - Refactoring refactoring= descriptor.createRefactoring(status); - assertTrue(status.isOK()); + final RefactoringContext refactoringContext= descriptor.createRefactoringContext(status); + try { + final Refactoring refactoring= refactoringContext != null ? refactoringContext.getRefactoring() : null; + assertTrue(status.isOK()); + + CheckConditionsOperation op= new CheckConditionsOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS); + op.run(null); + validationStatus= op.getStatus(); + } finally { + if (refactoringContext != null) + refactoringContext.dispose(); + } - CheckConditionsOperation op= new CheckConditionsOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS); - op.run(null); - RefactoringStatus validationStatus= op.getStatus(); assertTrue(!validationStatus.hasFatalError()); assertTrue(validationStatus.hasError()); assertEquals(2, validationStatus.getEntries().length); @@ -298,16 +313,23 @@ descriptor.setUpdateReferences(true); descriptor.setUpdateHierarchy(true); + RefactoringStatus validationStatus; RefactoringStatus status= new RefactoringStatus(); - Refactoring refactoring= descriptor.createRefactoring(status); - assertTrue(status.isOK()); - CheckConditionsOperation op= new CheckConditionsOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS); - op.run(null); - RefactoringStatus validationStatus= op.getStatus(); + final RefactoringContext refactoringContext= descriptor.createRefactoringContext(status); + try { + final Refactoring refactoring= refactoringContext != null ? refactoringContext.getRefactoring() : null; + assertTrue(status.isOK()); + CheckConditionsOperation op= new CheckConditionsOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS); + op.run(null); + validationStatus= op.getStatus(); + } finally { + if (refactoringContext != null) + refactoringContext.dispose(); + } + assertTrue(!validationStatus.hasFatalError()); assertTrue(validationStatus.hasError()); assertEquals(2, validationStatus.getEntries().length); - ReferencesInBinaryContext context= (ReferencesInBinaryContext) validationStatus.getEntryAt(0).getContext(); List matches= context.getMatches(); assertContainsMatches(matches, new String[] { Index: test cases/org/eclipse/jdt/ui/tests/refactoring/RefactoringTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RefactoringTest.java,v retrieving revision 1.63 diff -u -r1.63 RefactoringTest.java --- test cases/org/eclipse/jdt/ui/tests/refactoring/RefactoringTest.java 22 Feb 2011 08:27:12 -0000 1.63 +++ test cases/org/eclipse/jdt/ui/tests/refactoring/RefactoringTest.java 21 Jul 2011 22:58:30 -0000 @@ -43,6 +43,7 @@ import org.eclipse.ltk.core.refactoring.PerformChangeOperation; import org.eclipse.ltk.core.refactoring.Refactoring; import org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor; +import org.eclipse.ltk.core.refactoring.RefactoringContext; import org.eclipse.ltk.core.refactoring.RefactoringContribution; import org.eclipse.ltk.core.refactoring.RefactoringCore; import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; @@ -262,7 +263,9 @@ RefactoringContribution contribution= RefactoringCore.getRefactoringContribution(jrd.getID()); jrd= (JavaRefactoringDescriptor) contribution.createDescriptor(jrd.getID(), jrd.getProject(), jrd.getDescription(), jrd.getComment(), contribution.retrieveArgumentMap(jrd), jrd.getFlags()); assertEquals(expected, jrd.getClass()); - ref= jrd.createRefactoring(refactoringStatus); + final RefactoringContext context= jrd.createRefactoringContext(refactoringStatus); + if (context != null) + context.dispose(); if (!refactoringStatus.isOK()) return refactoringStatus; TestRenameParticipantSingle.reset(); Index: test cases/org/eclipse/jdt/ui/tests/refactoring/RenameTempTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameTempTests.java,v retrieving revision 1.63 diff -u -r1.63 RenameTempTests.java --- test cases/org/eclipse/jdt/ui/tests/refactoring/RenameTempTests.java 5 Oct 2009 12:46:52 -0000 1.63 +++ test cases/org/eclipse/jdt/ui/tests/refactoring/RenameTempTests.java 21 Jul 2011 22:58:30 -0000 @@ -14,6 +14,7 @@ import junit.framework.TestSuite; import org.eclipse.ltk.core.refactoring.Refactoring; +import org.eclipse.ltk.core.refactoring.RefactoringContext; import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.jdt.core.ICompilationUnit; @@ -90,12 +91,18 @@ descriptor.setUpdateReferences(updateReferences); final RefactoringStatus status= new RefactoringStatus(); - final Refactoring refactoring= descriptor.createRefactoring(status); - assertTrue("status should be ok", status.isOK()); - assertNotNull("refactoring should not be null", refactoring); - - RefactoringStatus result= performRefactoring(refactoring); - assertEquals("precondition was supposed to pass", null, result); + final RefactoringContext context= descriptor.createRefactoringContext(status); + try { + final Refactoring refactoring= context != null ? context.getRefactoring() : null; + assertTrue("status should be ok", status.isOK()); + assertNotNull("refactoring should not be null", refactoring); + + RefactoringStatus result= performRefactoring(refactoring); + assertEquals("precondition was supposed to pass", null, result); + } finally { + if (context != null) + context.dispose(); + } IPackageFragment pack= (IPackageFragment) cu.getParent(); String newCuName= getSimpleTestFileName(true, true); @@ -137,12 +144,18 @@ descriptor.setUpdateReferences(updateReferences); final RefactoringStatus status= new RefactoringStatus(); - final Refactoring refactoring= descriptor.createRefactoring(status); - assertTrue("status should be ok", status.isOK()); - assertNotNull("refactoring should not be null", refactoring); - - RefactoringStatus result= performRefactoring(refactoring); - assertNotNull("precondition was supposed to fail", result); + final RefactoringContext context= descriptor.createRefactoringContext(status); + try { + final Refactoring refactoring= context != null ? context.getRefactoring() : null; + assertTrue("status should be ok", status.isOK()); + assertNotNull("refactoring should not be null", refactoring); + + RefactoringStatus result= performRefactoring(refactoring); + assertNotNull("precondition was supposed to fail", result); + } finally { + if (context != null) + context.dispose(); + } } private void helper2(String newName, boolean updateReferences) throws Exception{ Index: test cases/org/eclipse/jdt/ui/tests/refactoring/RenameVirtualMethodInClassTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameVirtualMethodInClassTests.java,v retrieving revision 1.47 diff -u -r1.47 RenameVirtualMethodInClassTests.java --- test cases/org/eclipse/jdt/ui/tests/refactoring/RenameVirtualMethodInClassTests.java 31 Dec 2008 21:14:41 -0000 1.47 +++ test cases/org/eclipse/jdt/ui/tests/refactoring/RenameVirtualMethodInClassTests.java 21 Jul 2011 22:58:31 -0000 @@ -16,6 +16,7 @@ import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.ltk.core.refactoring.Refactoring; +import org.eclipse.ltk.core.refactoring.RefactoringContext; import org.eclipse.ltk.core.refactoring.RefactoringCore; import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.ltk.core.refactoring.participants.RenameRefactoring; @@ -85,10 +86,17 @@ descriptor.setKeepOriginal(createDelegate); descriptor.setDeprecateDelegate(createDelegate); final RefactoringStatus status= new RefactoringStatus(); - final Refactoring refactoring= descriptor.createRefactoring(status); - assertNotNull("Refactoring should not be null", refactoring); - assertTrue("status should be ok", status.isOK()); - assertEquals("was supposed to pass", null, performRefactoring(refactoring)); + final RefactoringContext context= descriptor.createRefactoringContext(status); + try { + final Refactoring refactoring= context != null ? context.getRefactoring() : null; + assertNotNull("Refactoring should not be null", refactoring); + assertTrue("status should be ok", status.isOK()); + assertEquals("was supposed to pass", null, performRefactoring(refactoring)); + } finally { + if (context != null) + context.dispose(); + } + if (!shouldPass){ assertTrue("incorrect renaming because of java model", ! getFileContents(getOutputTestFileName("A")).equals(cu.getSource())); return; @@ -400,11 +408,17 @@ descriptor.setNewName("kk"); descriptor.setUpdateReferences(true); final RefactoringStatus status= new RefactoringStatus(); - final Refactoring refactoring= descriptor.createRefactoring(status); - assertNotNull("Refactoring should not be null", refactoring); - assertTrue("status should be ok", status.isOK()); - - assertEquals("was supposed to pass", null, performRefactoring(refactoring)); + final RefactoringContext context= descriptor.createRefactoringContext(status); + try { + final Refactoring refactoring= context != null ? context.getRefactoring() : null; + assertNotNull("Refactoring should not be null", refactoring); + assertTrue("status should be ok", status.isOK()); + + assertEquals("was supposed to pass", null, performRefactoring(refactoring)); + } finally { + if (context != null) + context.dispose(); + } assertEqualLines("invalid renaming A", getFileContents(getOutputTestFileName("A")), cu.getSource()); assertEqualLines("invalid renaming C", getFileContents(getOutputTestFileName("C")), cuC.getSource()); } @@ -511,11 +525,17 @@ descriptor.setNewName("method2"); descriptor.setUpdateReferences(true); final RefactoringStatus status= new RefactoringStatus(); - final Refactoring refactoring= descriptor.createRefactoring(status); - assertNotNull("Refactoring should not be null", refactoring); - assertTrue("status should be ok", status.isOK()); - - assertEquals("was supposed to pass", null, performRefactoring(refactoring)); + final RefactoringContext context= descriptor.createRefactoringContext(status); + try { + final Refactoring refactoring= context != null ? context.getRefactoring() : null; + assertNotNull("Refactoring should not be null", refactoring); + assertTrue("status should be ok", status.isOK()); + + assertEquals("was supposed to pass", null, performRefactoring(refactoring)); + } finally { + if (context != null) + context.dispose(); + } assertEqualLines("invalid renaming A", getFileContents(getOutputTestFileName("A")), cu.getSource()); } Index: test cases/org/eclipse/jdt/ui/tests/refactoring/UseSupertypeWherePossibleTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/UseSupertypeWherePossibleTests.java,v retrieving revision 1.34 diff -u -r1.34 UseSupertypeWherePossibleTests.java --- test cases/org/eclipse/jdt/ui/tests/refactoring/UseSupertypeWherePossibleTests.java 20 Apr 2009 16:15:07 -0000 1.34 +++ test cases/org/eclipse/jdt/ui/tests/refactoring/UseSupertypeWherePossibleTests.java 21 Jul 2011 22:58:31 -0000 @@ -16,6 +16,7 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.ltk.core.refactoring.Refactoring; +import org.eclipse.ltk.core.refactoring.RefactoringContext; import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.jdt.core.ICompilationUnit; @@ -72,7 +73,6 @@ units[i]= subType.getCompilationUnit(); else units[i]= createCUfromTestFile(subType.getPackageFragment(), cuNames[i]); - } final IType superType= subType.getJavaProject().findType(superTypeFullName, (IProgressMonitor) null); final UseSupertypeDescriptor descriptor= RefactoringSignatureDescriptorFactory.createUseSupertypeDescriptor(); @@ -80,10 +80,16 @@ descriptor.setSupertype(superType); descriptor.setReplaceInstanceof(replaceInstanceOf); final RefactoringStatus status= new RefactoringStatus(); - final Refactoring refactoring= descriptor.createRefactoring(status); - assertTrue("status should be ok", status.isOK()); - assertNotNull("refactoring should not be null", refactoring); - assertEquals("was supposed to pass", null, performRefactoring(refactoring)); + final RefactoringContext context= descriptor.createRefactoringContext(status); + try { + final Refactoring refactoring= context != null ? context.getRefactoring() : null; + assertTrue("status should be ok", status.isOK()); + assertNotNull("refactoring should not be null", refactoring); + assertEquals("was supposed to pass", null, performRefactoring(refactoring)); + } finally { + if (context != null) + context.dispose(); + } for (int i= 0; i < units.length; i++) { String expected= getFileContents(getOutputTestFileName(cuNames[i])); #P org.eclipse.ltk.core.refactoring Index: META-INF/MANIFEST.MF =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ltk.core.refactoring/META-INF/MANIFEST.MF,v retrieving revision 1.37 diff -u -r1.37 MANIFEST.MF --- META-INF/MANIFEST.MF 9 Jun 2011 14:42:16 -0000 1.37 +++ META-INF/MANIFEST.MF 21 Jul 2011 22:58:32 -0000 @@ -2,7 +2,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.ltk.core.refactoring; singleton:=true -Bundle-Version: 3.5.300.qualifier +Bundle-Version: 3.6.0.qualifier Bundle-Activator: org.eclipse.ltk.internal.core.refactoring.RefactoringCorePlugin Bundle-ActivationPolicy: lazy Bundle-Vendor: %providerName Index: src/org/eclipse/ltk/core/refactoring/PerformRefactoringHistoryOperation.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/PerformRefactoringHistoryOperation.java,v retrieving revision 1.13 diff -u -r1.13 PerformRefactoringHistoryOperation.java --- src/org/eclipse/ltk/core/refactoring/PerformRefactoringHistoryOperation.java 11 Sep 2008 11:57:55 -0000 1.13 +++ src/org/eclipse/ltk/core/refactoring/PerformRefactoringHistoryOperation.java 21 Jul 2011 22:58:32 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. + * Copyright (c) 2005, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.ltk.core.refactoring; @@ -127,6 +128,7 @@ * if an error occurs while creating the refactoring instance * * @since 3.4 + * @deprecated since 3.6. Override {@link #createRefactoringContext(RefactoringDescriptor, RefactoringStatus, IProgressMonitor)} instead */ protected Refactoring createRefactoring(final RefactoringDescriptor descriptor, final RefactoringStatus status, final IProgressMonitor monitor) throws CoreException { try { @@ -140,6 +142,37 @@ } /** + * Method which is called to create a refactoring context from a refactoring descriptor. + * The refactoring context must contain a refactoring in an initialized state at the return + * of the method call. + * The default implementation delegates the task to the refactoring descriptor. + * + * @param descriptor + * the refactoring descriptor + * @param status + * a refactoring status to describe the outcome of the initialization + * @param monitor + * the progress monitor to use + * @return the refactoring context, or null if this refactoring descriptor + * represents the unknown refactoring, or if no refactoring contribution is + * available for this refactoring descriptor + * @throws CoreException + * if an error occurs while creating the refactoring context + * @since 3.6 + */ + protected RefactoringContext createRefactoringContext(final RefactoringDescriptor descriptor, + final RefactoringStatus status, final IProgressMonitor monitor) throws CoreException { + try { + Assert.isNotNull(descriptor); + return descriptor.createRefactoringContext(status); + } finally { + if (monitor != null) { + monitor.done(); + } + } + } + + /** * Returns the execution status. Guaranteed not to be null. * * @return the status of the session @@ -177,15 +210,16 @@ for (int index= 0; index < proxies.length; index++) { final RefactoringDescriptor descriptor= proxies[index].requestDescriptor(new SubProgressMonitor(monitor, 10, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); if (descriptor != null) { - Refactoring refactoring= null; + RefactoringContext context= null; RefactoringStatus status= new RefactoringStatus(); try { try { - refactoring= createRefactoring(descriptor, status, new SubProgressMonitor(monitor, 30, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); + context= createRefactoringContext(descriptor, status, new SubProgressMonitor(monitor, 30, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); } catch (CoreException exception) { status.merge(RefactoringStatus.create(exception.getStatus())); } - if (refactoring != null && !status.hasFatalError()) { + if (context != null && !status.hasFatalError()) { + Refactoring refactoring= context.getRefactoring(); final PerformRefactoringOperation operation= new PerformRefactoringOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS); try { status.merge(aboutToPerformRefactoring(refactoring, descriptor, new SubProgressMonitor(monitor, 30, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL))); @@ -200,6 +234,8 @@ } } } finally { + if (context != null) + context.dispose(); fExecutionStatus.merge(status); } } Index: src/org/eclipse/ltk/core/refactoring/RefactoringContext.java =================================================================== RCS file: src/org/eclipse/ltk/core/refactoring/RefactoringContext.java diff -N src/org/eclipse/ltk/core/refactoring/RefactoringContext.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/ltk/core/refactoring/RefactoringContext.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2011 Google, Inc and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sergey Prigogin (Google) - initial API and implementation + *******************************************************************************/ +package org.eclipse.ltk.core.refactoring; + +/** + *

+ * Refactoring context is a disposable object that can be used by a refactoring to hold resources + * that have to be explicitly released. The refactoring context is guaranteed to receive + * a {@link #dispose()} call after the associated refactoring has finished or produced an error. + * At this point, the refactoring context must release all resources and detach all listeners. + * A refactoring context can only be disposed once; it cannot be reused. + *

+ *

+ * The class is intended to be subclassed by clients wishing to implement new refactorings that + * depend on resources that have to be explicitly released. + *

+ * @since 3.6 + */ +public class RefactoringContext { + private Refactoring fRefactoring; + + /** + * Creates a context for the given refactoring. + * + * @param refactoring The refactoring associated with the context. Cannot be null. + * @throws NullPointerException if refactoring is null. + */ + public RefactoringContext(Refactoring refactoring) { + if (refactoring == null) + throw new NullPointerException(); + fRefactoring= refactoring; + } + + /** + * Returns the refactoring associated with the context. + *

+ * The returned refactoring must be in an initialized state, i.e. ready to + * be executed via {@link PerformRefactoringOperation}. + *

+ * @return The refactoring associated with the context. + */ + public Refactoring getRefactoring() { + return fRefactoring; + } + + /** + * Disposes of the context. This method will be called exactly once during the life cycle + * of the context after the associated refactoring has finished or produced an error. + */ + public void dispose() { + if (fRefactoring == null) + throw new IllegalStateException("dispose() called more than once."); //$NON-NLS-1$ + fRefactoring = null; + } +} Index: src/org/eclipse/ltk/core/refactoring/RefactoringDescriptor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/RefactoringDescriptor.java,v retrieving revision 1.63 diff -u -r1.63 RefactoringDescriptor.java --- src/org/eclipse/ltk/core/refactoring/RefactoringDescriptor.java 11 Sep 2008 11:57:55 -0000 1.63 +++ src/org/eclipse/ltk/core/refactoring/RefactoringDescriptor.java 21 Jul 2011 22:58:33 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. + * Copyright (c) 2005, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.ltk.core.refactoring; @@ -229,28 +230,57 @@ /** * Creates the a new refactoring instance for this refactoring descriptor. *

- * This method is used by the refactoring framework to instantiate a - * refactoring from a refactoring descriptor, in order to apply it later on - * a local or remote workspace. - *

- *

* The returned refactoring must be in an initialized state, i.e. ready to * be executed via {@link PerformRefactoringOperation}. *

+ *

+ * This method is not intended to be called directly from code that does not belong to this + * class and its subclasses. External code should call + * {@link #createRefactoringContext(RefactoringStatus)} and obtain the refactoring object from + * the refactoring context. + *

* * @param status - * a refactoring status used to describe the outcome of the - * initialization + * a refactoring status used to describe the outcome of the initialization * @return the refactoring, or null if this refactoring * descriptor represents the unknown refactoring, or if no * refactoring contribution is available for this refactoring * descriptor which is capable to create a refactoring * @throws CoreException - * if an error occurs while creating the refactoring instance + * if an error occurs while creating the refactoring instance */ public abstract Refactoring createRefactoring(RefactoringStatus status) throws CoreException; /** + * Creates the a new refactoring context and the associated refactoring instance for this + * refactoring descriptor. + *

+ * This method is used by the refactoring framework to instantiate a refactoring + * from a refactoring descriptor, in order to apply it later on a local or remote workspace. + *

+ *

+ * The default implementation of this method wraps refactoring in a trivial refactoring + * context. Subclasses may override this method to create a custom refactoring context. + *

+ * + * @param status + * a refactoring status used to describe the outcome of the initialization + * @return the refactoring context, or null if this refactoring + * descriptor represents the unknown refactoring, or if no + * refactoring contribution is available for this refactoring + * descriptor which is capable to create a refactoring. + * @throws CoreException + * if an error occurs while creating the refactoring context + * @since 3.6 + */ + public RefactoringContext createRefactoringContext(RefactoringStatus status) throws CoreException { + Refactoring refactoring= createRefactoring(status); + if (refactoring == null) + return null; + return new RefactoringContext(refactoring); + } + + /** * {@inheritDoc} */ public final boolean equals(final Object object) { #P org.eclipse.ltk.core.refactoring.tests Index: src/org/eclipse/ltk/core/refactoring/tests/resource/ResourceRefactoringTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ltk.core.refactoring.tests/src/org/eclipse/ltk/core/refactoring/tests/resource/ResourceRefactoringTests.java,v retrieving revision 1.6 diff -u -r1.6 ResourceRefactoringTests.java --- src/org/eclipse/ltk/core/refactoring/tests/resource/ResourceRefactoringTests.java 9 Jun 2011 14:38:53 -0000 1.6 +++ src/org/eclipse/ltk/core/refactoring/tests/resource/ResourceRefactoringTests.java 21 Jul 2011 22:58:34 -0000 @@ -35,6 +35,7 @@ import org.eclipse.ltk.core.refactoring.PerformChangeOperation; import org.eclipse.ltk.core.refactoring.PerformRefactoringOperation; import org.eclipse.ltk.core.refactoring.Refactoring; +import org.eclipse.ltk.core.refactoring.RefactoringContext; import org.eclipse.ltk.core.refactoring.RefactoringContribution; import org.eclipse.ltk.core.refactoring.RefactoringCore; import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; @@ -302,14 +303,20 @@ private Change perform(RefactoringDescriptor descriptor) throws CoreException { RefactoringStatus status= new RefactoringStatus(); - Refactoring refactoring= descriptor.createRefactoring(status); - assertTrue(status.isOK()); + final RefactoringContext context= descriptor.createRefactoringContext(status); + try { + final Refactoring refactoring= context != null ? context.getRefactoring() : null; + assertTrue(status.isOK()); - PerformRefactoringOperation op= new PerformRefactoringOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS); - op.run(null); - RefactoringStatus validationStatus= op.getValidationStatus(); - assertTrue(!validationStatus.hasFatalError() && !validationStatus.hasError()); - return op.getUndoChange(); + PerformRefactoringOperation op= new PerformRefactoringOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS); + op.run(null); + RefactoringStatus validationStatus= op.getValidationStatus(); + assertTrue(!validationStatus.hasFatalError() && !validationStatus.hasError()); + return op.getUndoChange(); + } finally { + if (context != null) + context.dispose(); + } } private IResource assertMove(IResource source, IContainer destination, String content) throws CoreException, IOException { Index: src/org/eclipse/ltk/core/refactoring/tests/resource/ResourceRefactoringUndoTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ltk.core.refactoring.tests/src/org/eclipse/ltk/core/refactoring/tests/resource/ResourceRefactoringUndoTests.java,v retrieving revision 1.4 diff -u -r1.4 ResourceRefactoringUndoTests.java --- src/org/eclipse/ltk/core/refactoring/tests/resource/ResourceRefactoringUndoTests.java 31 Dec 2008 21:14:19 -0000 1.4 +++ src/org/eclipse/ltk/core/refactoring/tests/resource/ResourceRefactoringUndoTests.java 21 Jul 2011 22:58:35 -0000 @@ -50,6 +50,7 @@ import org.eclipse.ltk.core.refactoring.CheckConditionsOperation; import org.eclipse.ltk.core.refactoring.PerformRefactoringOperation; import org.eclipse.ltk.core.refactoring.Refactoring; +import org.eclipse.ltk.core.refactoring.RefactoringContext; import org.eclipse.ltk.core.refactoring.RefactoringContribution; import org.eclipse.ltk.core.refactoring.RefactoringCore; import org.eclipse.ltk.core.refactoring.RefactoringStatus; @@ -135,10 +136,19 @@ RenameResourceDescriptor desc= (RenameResourceDescriptor) renameContribution.createDescriptor(); desc.setResourcePath(testFile.getFullPath()); desc.setNewName(TEST_NEWFILE_NAME); - PerformRefactoringOperation op= new PerformRefactoringOperation(desc.createRefactoring(new RefactoringStatus()), CheckConditionsOperation.ALL_CONDITIONS); - FileSnapshot snap= new FileSnapshot(testFile); - execute(op); + FileSnapshot snap; + final RefactoringContext refactoringContext= desc.createRefactoringContext(new RefactoringStatus()); + try { + final Refactoring refactoring= refactoringContext != null ? refactoringContext.getRefactoring() : null; + PerformRefactoringOperation op= new PerformRefactoringOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS); + + snap= new FileSnapshot(testFile); + execute(op); + } finally { + if (refactoringContext != null) + refactoringContext.dispose(); + } IFile renamedFile= testFolder.getFile(TEST_NEWFILE_NAME); assertTrue("File rename failed", renamedFile.exists()); @@ -160,10 +170,20 @@ RenameResourceDescriptor desc= (RenameResourceDescriptor) renameContribution.createDescriptor(); desc.setResourcePath(testFolder.getFullPath()); desc.setNewName(TEST_NEWFOLDER_NAME); - PerformRefactoringOperation op= new PerformRefactoringOperation(desc.createRefactoring(new RefactoringStatus()), CheckConditionsOperation.ALL_CONDITIONS); - FolderSnapshot snap= new FolderSnapshot(testFolder); - execute(op); + FolderSnapshot snap; + final RefactoringContext refactoringContext= desc.createRefactoringContext(new RefactoringStatus()); + try { + final Refactoring refactoring= refactoringContext != null ? refactoringContext.getRefactoring() : null; + PerformRefactoringOperation op= new PerformRefactoringOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS); + + snap= new FolderSnapshot(testFolder); + execute(op); + } finally { + if (refactoringContext != null) + refactoringContext.dispose(); + } + IFolder renamedFolder= fProject.getProject().getFolder(TEST_NEWFOLDER_NAME); assertTrue("Project rename failed", renamedFolder.exists()); snap.name= TEST_NEWFOLDER_NAME; @@ -184,10 +204,20 @@ RenameResourceDescriptor desc= (RenameResourceDescriptor) renameContribution.createDescriptor(); desc.setResourcePath(fProject.getProject().getFullPath()); desc.setNewName(TEST_NEWPROJECT_NAME); - PerformRefactoringOperation op= new PerformRefactoringOperation(desc.createRefactoring(new RefactoringStatus()), CheckConditionsOperation.ALL_CONDITIONS); - ProjectSnapshot snap= new ProjectSnapshot(fProject.getProject()); - execute(op); + ProjectSnapshot snap; + final RefactoringContext refactoringContext= desc.createRefactoringContext(new RefactoringStatus()); + try { + final Refactoring refactoring= refactoringContext != null ? refactoringContext.getRefactoring() : null; + PerformRefactoringOperation op= new PerformRefactoringOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS); + + snap= new ProjectSnapshot(fProject.getProject()); + execute(op); + } finally { + if (refactoringContext != null) + refactoringContext.dispose(); + } + IProject renamedProject= getWorkspaceRoot().getProject(TEST_NEWPROJECT_NAME); assertTrue("Project rename failed", renamedProject.exists()); snap.name= TEST_NEWPROJECT_NAME; @@ -206,11 +236,18 @@ DeleteResourcesDescriptor desc= (DeleteResourcesDescriptor) renameContribution.createDescriptor(); desc.setResourcePaths(new IPath[] { testFile.getFullPath() }); - PerformRefactoringOperation op= new PerformRefactoringOperation(desc.createRefactoring(new RefactoringStatus()), CheckConditionsOperation.ALL_CONDITIONS); - - FileSnapshot snap= new FileSnapshot(testFile); + FileSnapshot snap; + final RefactoringContext refactoringContext= desc.createRefactoringContext(new RefactoringStatus()); + try { + final Refactoring refactoring= refactoringContext != null ? refactoringContext.getRefactoring() : null; + PerformRefactoringOperation op= new PerformRefactoringOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS); - execute(op); + snap= new FileSnapshot(testFile); + execute(op); + } finally { + if (refactoringContext != null) + refactoringContext.dispose(); + } assertFalse("File delete failed", testFile.exists()); undo(); @@ -225,11 +262,18 @@ DeleteResourcesDescriptor desc= (DeleteResourcesDescriptor) renameContribution.createDescriptor(); desc.setResourcePaths(new IPath[] { testLinkedFile.getFullPath() }); - PerformRefactoringOperation op= new PerformRefactoringOperation(desc.createRefactoring(new RefactoringStatus()), CheckConditionsOperation.ALL_CONDITIONS); - - FileSnapshot snap= new FileSnapshot(testLinkedFile); + FileSnapshot snap; + final RefactoringContext refactoringContext= desc.createRefactoringContext(new RefactoringStatus()); + try { + final Refactoring refactoring= refactoringContext != null ? refactoringContext.getRefactoring() : null; + PerformRefactoringOperation op= new PerformRefactoringOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS); - execute(op); + snap= new FileSnapshot(testLinkedFile); + execute(op); + } finally { + if (refactoringContext != null) + refactoringContext.dispose(); + } assertFalse("File delete failed", testLinkedFile.exists()); undo(); @@ -244,11 +288,18 @@ DeleteResourcesDescriptor desc= (DeleteResourcesDescriptor) renameContribution.createDescriptor(); desc.setResourcePaths(new IPath[] { testSubFolder.getFullPath() }); - PerformRefactoringOperation op= new PerformRefactoringOperation(desc.createRefactoring(new RefactoringStatus()), CheckConditionsOperation.ALL_CONDITIONS); - - FolderSnapshot snap= new FolderSnapshot(testSubFolder); + FolderSnapshot snap; + final RefactoringContext refactoringContext= desc.createRefactoringContext(new RefactoringStatus()); + try { + final Refactoring refactoring= refactoringContext != null ? refactoringContext.getRefactoring() : null; + PerformRefactoringOperation op= new PerformRefactoringOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS); - execute(op); + snap= new FolderSnapshot(testSubFolder); + execute(op); + } finally { + if (refactoringContext != null) + refactoringContext.dispose(); + } assertFalse("Folder delete failed", testSubFolder.exists()); undo(); @@ -263,10 +314,19 @@ DeleteResourcesDescriptor desc= (DeleteResourcesDescriptor) renameContribution.createDescriptor(); desc.setResourcePaths(new IPath[] { testLinkedFolder.getFullPath() }); - PerformRefactoringOperation op= new PerformRefactoringOperation(desc.createRefactoring(new RefactoringStatus()), CheckConditionsOperation.ALL_CONDITIONS); + FolderSnapshot snap; + final RefactoringContext refactoringContext= desc.createRefactoringContext(new RefactoringStatus()); + try { + final Refactoring refactoring= refactoringContext != null ? refactoringContext.getRefactoring() : null; + PerformRefactoringOperation op= new PerformRefactoringOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS); + + snap= new FolderSnapshot(testLinkedFolder); + execute(op); + } finally { + if (refactoringContext != null) + refactoringContext.dispose(); + } - FolderSnapshot snap= new FolderSnapshot(testLinkedFolder); - execute(op); assertFalse("Folder delete failed", testLinkedFolder.exists()); undo(); assertTrue("Folder recreation failed", testLinkedFolder.exists()); @@ -280,9 +340,17 @@ DeleteResourcesDescriptor desc= (DeleteResourcesDescriptor) renameContribution.createDescriptor(); desc.setResourcePaths(new IPath[] { fProject.getProject().getFullPath() }); - PerformRefactoringOperation op= new PerformRefactoringOperation(desc.createRefactoring(new RefactoringStatus()), CheckConditionsOperation.ALL_CONDITIONS); + final RefactoringContext refactoringContext= desc.createRefactoringContext(new RefactoringStatus()); + try { + final Refactoring refactoring= refactoringContext != null ? refactoringContext.getRefactoring() : null; + PerformRefactoringOperation op= new PerformRefactoringOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS); + + execute(op); + } finally { + if (refactoringContext != null) + refactoringContext.dispose(); + } - execute(op); assertFalse("Project delete failed", fProject.getProject().exists()); undo(); assertTrue("Project recreation failed", fProject.getProject().exists()); @@ -312,10 +380,18 @@ desc.setResourcePaths(new IPath[] { fProject.getProject().getFullPath() }); desc.setDeleteContents(true); - PerformRefactoringOperation op= new PerformRefactoringOperation(desc.createRefactoring(new RefactoringStatus()), CheckConditionsOperation.ALL_CONDITIONS); + final RefactoringContext refactoringContext= desc.createRefactoringContext(new RefactoringStatus()); + try { + final Refactoring refactoring= refactoringContext != null ? refactoringContext.getRefactoring() : null; + PerformRefactoringOperation op= new PerformRefactoringOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS); + + // We don't snapshot since CONTENT will be deleted + execute(op); + } finally { + if (refactoringContext != null) + refactoringContext.dispose(); + } -// we don't snapshot since CONTENT will be deleted - execute(op); assertFalse("Project delete failed", fProject.getProject().exists()); undo(); assertTrue("Project was recreated", fProject.getProject().exists()); #P org.eclipse.ltk.ui.refactoring Index: META-INF/MANIFEST.MF =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ltk.ui.refactoring/META-INF/MANIFEST.MF,v retrieving revision 1.39 diff -u -r1.39 MANIFEST.MF --- META-INF/MANIFEST.MF 7 Mar 2011 17:13:19 -0000 1.39 +++ META-INF/MANIFEST.MF 21 Jul 2011 22:58:35 -0000 @@ -2,7 +2,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.ltk.ui.refactoring; singleton:=true -Bundle-Version: 3.6.0.qualifier +Bundle-Version: 3.7.0.qualifier Bundle-Activator: org.eclipse.ltk.internal.ui.refactoring.RefactoringUIPlugin Bundle-ActivationPolicy: lazy Bundle-Vendor: %providerName Index: src/org/eclipse/ltk/ui/refactoring/history/RefactoringHistoryWizard.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/ui/refactoring/history/RefactoringHistoryWizard.java,v retrieving revision 1.66 diff -u -r1.66 RefactoringHistoryWizard.java --- src/org/eclipse/ltk/ui/refactoring/history/RefactoringHistoryWizard.java 11 Sep 2008 12:01:12 -0000 1.66 +++ src/org/eclipse/ltk/ui/refactoring/history/RefactoringHistoryWizard.java 21 Jul 2011 22:58:36 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. + * Copyright (c) 2005, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.ltk.ui.refactoring.history; @@ -57,6 +58,7 @@ import org.eclipse.ltk.core.refactoring.PerformChangeOperation; import org.eclipse.ltk.core.refactoring.PerformRefactoringHistoryOperation; import org.eclipse.ltk.core.refactoring.Refactoring; +import org.eclipse.ltk.core.refactoring.RefactoringContext; import org.eclipse.ltk.core.refactoring.RefactoringCore; import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy; @@ -553,6 +555,7 @@ * descriptor * @throws CoreException * if an error occurs while creating the refactoring instance + * @deprecated since 3.6. Override {@link #createRefactoringContext(RefactoringDescriptor, RefactoringStatus, IProgressMonitor)} instead */ protected Refactoring createRefactoring(final RefactoringDescriptor descriptor, final RefactoringStatus status) throws CoreException { Assert.isNotNull(descriptor); @@ -581,6 +584,7 @@ * if an error occurs while creating the refactoring instance * * @since 3.4 + * @deprecated since 3.7. Override {@link #createRefactoringContext(RefactoringDescriptor, RefactoringStatus, IProgressMonitor)} instead */ protected Refactoring createRefactoring(final RefactoringDescriptor descriptor, final RefactoringStatus status, final IProgressMonitor monitor) throws CoreException { final Refactoring refactoring= createRefactoring(descriptor, status); @@ -594,6 +598,43 @@ } /** + * Creates a refactoring context from the specified refactoring descriptor. + *

+ * The default implementation calls + * {@link RefactoringDescriptor#createRefactoringContext(RefactoringStatus)} followed by + * {@link #aboutToPerformRefactoring(Refactoring, RefactoringDescriptor, IProgressMonitor)}. + * Implementors can replace this implementation. + *

+ * + * @param descriptor + * the refactoring descriptor + * @param status + * the refactoring status + * @param monitor + * the progress monitor to use + * @return the refactoring context, or null if this refactoring descriptor + * represents the unknown refactoring, or if no refactoring contribution is available + * for this refactoring descriptor + * @throws CoreException + * if an error occurs while creating the refactoring context + * + * @since 3.7 + */ + protected RefactoringContext createRefactoringContext(final RefactoringDescriptor descriptor, final RefactoringStatus status, final IProgressMonitor monitor) throws CoreException { + Assert.isNotNull(descriptor); + final RefactoringContext context= descriptor.createRefactoringContext(status); + if (context != null) { + final Refactoring refactoring= context.getRefactoring(); + status.merge(aboutToPerformRefactoring(refactoring, descriptor, monitor)); + if (!status.hasFatalError()) + return context; + } else { + status.addFatalError(Messages.format(RefactoringUIMessages.RefactoringHistoryWizard_error_instantiate_refactoring, descriptor.getDescription())); + } + return null; + } + + /** * {@inheritDoc} */ public void dispose() { @@ -825,33 +866,39 @@ service.connect(); final RefactoringDescriptor descriptor= proxy.requestDescriptor(new SubProgressMonitor(monitor, 10, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); if (descriptor != null) { - final Refactoring refactoring= createRefactoring(descriptor, status, new SubProgressMonitor(monitor, 60, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); - if (refactoring != null && status.isOK()) { - fPreviewPage.setRefactoring(refactoring); - fErrorPage.setRefactoring(refactoring); - status.merge(checkConditions(refactoring, new SubProgressMonitor(monitor, 20, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL), CheckConditionsOperation.INITIAL_CONDITONS)); - if (!status.isOK()) { - prepareErrorPage(status, proxy, status.hasFatalError(), last); - result[0]= fErrorPage; - } else { - status.merge(checkConditions(refactoring, new SubProgressMonitor(monitor, 65, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL), CheckConditionsOperation.FINAL_CONDITIONS)); + final RefactoringContext context= createRefactoringContext(descriptor, status, new SubProgressMonitor(monitor, 60, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); + try { + if (context != null && status.isOK()) { + final Refactoring refactoring= context.getRefactoring(); + fPreviewPage.setRefactoring(refactoring); + fErrorPage.setRefactoring(refactoring); + status.merge(checkConditions(refactoring, new SubProgressMonitor(monitor, 20, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL), CheckConditionsOperation.INITIAL_CONDITONS)); if (!status.isOK()) { prepareErrorPage(status, proxy, status.hasFatalError(), last); result[0]= fErrorPage; } else { - final Change change= createChange(refactoring, new SubProgressMonitor(monitor, 5, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); - getShell().getDisplay().syncExec(new Runnable() { - - public final void run() { - fPreviewPage.setChange(change); - } - }); - result[0]= fPreviewPage; + status.merge(checkConditions(refactoring, new SubProgressMonitor(monitor, 65, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL), CheckConditionsOperation.FINAL_CONDITIONS)); + if (!status.isOK()) { + prepareErrorPage(status, proxy, status.hasFatalError(), last); + result[0]= fErrorPage; + } else { + final Change change= createChange(refactoring, new SubProgressMonitor(monitor, 5, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); + getShell().getDisplay().syncExec(new Runnable() { + + public final void run() { + fPreviewPage.setChange(change); + } + }); + result[0]= fPreviewPage; + } } + } else { + prepareErrorPage(status, proxy, status.hasFatalError(), last); + result[0]= fErrorPage; } - } else { - prepareErrorPage(status, proxy, status.hasFatalError(), last); - result[0]= fErrorPage; + } finally { + if (context != null) + context.dispose(); } } else { status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringUIMessages.RefactoringHistoryWizard_error_resolving_refactoring)); @@ -1031,8 +1078,8 @@ } final PerformRefactoringHistoryOperation operation= new PerformRefactoringHistoryOperation(new RefactoringHistoryImplementation(descriptors)) { - protected Refactoring createRefactoring(final RefactoringDescriptor descriptor, final RefactoringStatus state, IProgressMonitor monitor) throws CoreException { - return RefactoringHistoryWizard.this.createRefactoring(descriptor, state, monitor); + protected RefactoringContext createRefactoringContext(final RefactoringDescriptor descriptor, final RefactoringStatus state, IProgressMonitor monitor) throws CoreException { + return RefactoringHistoryWizard.this.createRefactoringContext(descriptor, state, monitor); } protected void refactoringPerformed(final Refactoring refactoring, final IProgressMonitor monitor) { #P org.eclipse.ui.navigator.resources Index: src/org/eclipse/ui/navigator/resources/ResourceDropAdapterAssistant.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/navigator/resources/ResourceDropAdapterAssistant.java,v retrieving revision 1.18 diff -u -r1.18 ResourceDropAdapterAssistant.java --- src/org/eclipse/ui/navigator/resources/ResourceDropAdapterAssistant.java 21 Apr 2011 07:26:13 -0000 1.18 +++ src/org/eclipse/ui/navigator/resources/ResourceDropAdapterAssistant.java 21 Jul 2011 22:58:37 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.ui.navigator.resources; @@ -62,6 +63,7 @@ import org.eclipse.ltk.core.refactoring.CheckConditionsOperation; import org.eclipse.ltk.core.refactoring.PerformRefactoringOperation; import org.eclipse.ltk.core.refactoring.Refactoring; +import org.eclipse.ltk.core.refactoring.RefactoringContext; import org.eclipse.ltk.core.refactoring.RefactoringContribution; import org.eclipse.ltk.core.refactoring.RefactoringCore; import org.eclipse.ltk.core.refactoring.RefactoringStatus; @@ -483,6 +485,7 @@ WorkbenchNavigatorMessages.MoveResourceAction_checkMoveMessage); sources = checker.checkReadOnlyResources(sources); + RefactoringContext context= null; try { RefactoringContribution contribution = RefactoringCore .getRefactoringContribution(MoveResourcesDescriptor.ID); @@ -490,7 +493,8 @@ descriptor.setResourcesToMove(sources); descriptor.setDestination(target); refactoringStatus = new RefactoringStatus(); - final Refactoring refactoring = descriptor.createRefactoring(refactoringStatus); + context = descriptor.createRefactoringContext(refactoringStatus); + final Refactoring refactoring = context != null ? context.getRefactoring() : null; returnStatus = null; IRunnableWithProgress checkOp = new IRunnableWithProgress() { @@ -554,6 +558,9 @@ } catch (CoreException ex) { return WorkbenchNavigatorPlugin.createErrorStatus(0, ex.getLocalizedMessage(), ex); } catch (OperationCanceledException e) { + } finally { + if (context != null) + context.dispose(); } }