Class Refactoring
- All Implemented Interfaces:
IAdaptable
- Direct Known Subclasses:
ProcessorBasedRefactoring
- methods to check conditions to determine if the refactoring can be carried out in general and if transformation will be behavior-preserving.
- a method to create a
Change
object that represents the actual work space modifications.
- the refactoring gets created
- the refactoring is initialized with the elements to be refactored. It is up to a concrete refactoring implementation to provide corresponding API.
checkInitialConditions(IProgressMonitor)
is called. The method can be called more than once.- additional arguments are provided to perform the refactoring (for example the new name of a element in the case of a rename refactoring). It is up to a concrete implementation to provide corresponding API.
checkFinalConditions(IProgressMonitor)
is called. The method can be called more than once. The method must not be called ifcheckInitialConditions(IProgressMonitor)
returns a refactoring status of severityRefactoringStatus.FATAL
.createChange(IProgressMonitor)
is called. The method must only be called once after each call tocheckFinalConditions(IProgressMonitor)
and should not be called if one of the condition checking methods returns a refactoring status of severityRefactoringStatus.FATAL
.- steps 4 to 6 can be executed repeatedly (for example when the user goes back from the preview page).
A refactoring can not assume that all resources are saved before any methods are called on it. Therefore a refactoring must be able to deal with unsaved resources.
The class should be subclassed by clients wishing to implement new refactorings.
- Since:
- 3.0
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionChecks all conditions.abstract RefactoringStatus
AftercheckInitialConditions
has been performed and the user has provided all input necessary to perform the refactoring this method is called to check the remaining preconditions.abstract RefactoringStatus
Checks some initial conditions based on the element to be refactored.abstract Change
Creates aChange
object that performs the actual workspace transformation.protected RefactoringTickProvider
Hook method to provide the tick provider used for progress reporting.<T> T
getAdapter
(Class<T> adapter) Returns an object which is an instance of the given class associated with this object.abstract String
getName()
Returns the refactoring's name.final RefactoringTickProvider
Returns the tick provider used for progress reporting for this refactoring.final Object
Returns the validation contextfinal void
setValidationContext
(Object context) Sets the validation context used when callingIWorkspace.validateEdit(org.eclipse.core.resources.IFile[], java.lang.Object)
.toString()
-
Constructor Details
-
Refactoring
public Refactoring()
-
-
Method Details
-
setValidationContext
Sets the validation context used when callingIWorkspace.validateEdit(org.eclipse.core.resources.IFile[], java.lang.Object)
.- Parameters:
context
- theorg.eclipse.swt.widgets.Shell
that is to be used to parent any dialogs with the user, ornull
if there is no UI context (declared as anObject
to avoid any direct references on the SWT component)
-
getValidationContext
Returns the validation context- Returns:
- the validation context or
null
if no validation context has been set.
-
getName
Returns the refactoring's name.- Returns:
- the refactoring's human readable name. Must not be
null
-
getRefactoringTickProvider
Returns the tick provider used for progress reporting for this refactoring.- Returns:
- the refactoring tick provider used for progress reporting
- Since:
- 3.2
-
doGetRefactoringTickProvider
Hook method to provide the tick provider used for progress reporting.Subclasses may override this method
- Returns:
- the refactoring tick provider used for progress reporting
- Since:
- 3.2
-
checkAllConditions
public RefactoringStatus checkAllConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException Checks all conditions. This implementation callscheckInitialConditions
andcheckFinalConditions
.Subclasses may extend this method to provide additional condition checks.
- Parameters:
pm
- a progress monitor to report progress- Returns:
- a refactoring status. If the status is
RefactoringStatus#FATAL
the refactoring has to be considered as not being executable. - Throws:
CoreException
- if an exception occurred during condition checking. If this happens then the condition checking has to be interpreted as failedOperationCanceledException
- if the condition checking got canceled- See Also:
-
checkInitialConditions
public abstract RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException Checks some initial conditions based on the element to be refactored. The method is typically called by the UI to perform an initial checks after an action has been executed.The refactoring has to be considered as not being executable if the returned status has the severity of
RefactoringStatus#FATAL
.This method can be called more than once.
- Parameters:
pm
- a progress monitor to report progress. Although initial checks are supposed to execute fast, there can be certain situations where progress reporting is necessary. For example rebuilding a corrupted index may report progress.- Returns:
- a refactoring status. If the status is
RefactoringStatus#FATAL
the refactoring has to be considered as not being executable. - Throws:
CoreException
- if an exception occurred during initial condition checking. If this happens then the initial condition checking has to be interpreted as failedOperationCanceledException
- if the condition checking got canceled- See Also:
-
checkFinalConditions
public abstract RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException AftercheckInitialConditions
has been performed and the user has provided all input necessary to perform the refactoring this method is called to check the remaining preconditions.The refactoring has to be considered as not being executable if the returned status has the severity of
RefactoringStatus#FATAL
.This method can be called more than once.
- Parameters:
pm
- a progress monitor to report progress- Returns:
- a refactoring status. If the status is
RefactoringStatus#FATAL
the refactoring is considered as not being executable. - Throws:
CoreException
- if an exception occurred during final condition checking If this happens then the final condition checking is interpreted as failedOperationCanceledException
- if the condition checking got canceled- See Also:
-
createChange
public abstract Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException Creates aChange
object that performs the actual workspace transformation.- Parameters:
pm
- a progress monitor to report progress- Returns:
- the change representing the workspace modifications of the refactoring
- Throws:
CoreException
- if an error occurred while creating the changeOperationCanceledException
- if the condition checking got canceled
-
getAdapter
Description copied from class:PlatformObject
Returns an object which is an instance of the given class associated with this object. Returnsnull
if no such object can be found.This implementation of the method declared by
IAdaptable
passes the request along to the platform's adapter manager; roughlyPlatform.getAdapterManager().getAdapter(this, adapter)
. Subclasses may override this method (however, if they do so, they should invoke the method on their superclass to ensure that the Platform's adapter manager is consulted).- Specified by:
getAdapter
in interfaceIAdaptable
- Overrides:
getAdapter
in classPlatformObject
- Type Parameters:
T
- the class type- Parameters:
adapter
- the class to adapt to- Returns:
- the adapted object or
null
- See Also:
-
toString
-