|
|||||||||
| Home >> All >> org >> eclipse >> ltk >> core >> [ refactoring overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.eclipse.ltk.core.refactoring
Class Change

java.lang.Objectorg.eclipse.ltk.core.refactoring.Change
- All Implemented Interfaces:
- org.eclipse.core.runtime.IAdaptable
- Direct Known Subclasses:
- CompositeChange, NullChange, TextChange, UndoTextFileChange
- public abstract class Change
- extends java.lang.Object
- implements org.eclipse.core.runtime.IAdaptable
- extends java.lang.Object
An abstract base implementation for object representing a generic change
to the workbench. A Change object is typically created by
calling Refactoring.createChange(). This class should be
subclassed by clients wishing to provide new changes.
Changes are best executed by using a PerformChangeOperation. If clients execute a change directly then the following life cycle has to be honored:
- after a single change or a tree of changes has been created, the
method
initializeValidationStatehas to be called. - the method
isValidcan be used to determine if a change can still be applied to the workspace. If the method returns a RefactoringStatus with a severity of FATAL then the change has to be treated as invalid. Performing an invalid change isn't allowed and results in an unspecified result. This method can be called multiple times. - then the method perform can be called. An disabled change must not
be executed. The perform method can only be called once. After a change
as been executed only the method
disposemust be called. - the method dispose has to be called either after the perform method
has been called or if a change is no longer needed. The second case
for example occurs when the undo stack gets flushed and all change
objects managed by the undo stack are no longer needed. The method
dispose is typically implemented to unregister listeners register during the
method
initializeValidationState. There is no guarantee thatinitializeValidationState,isValidorperformhas been called, beforedisposeis called.
Change change= createChange();
try {
change.initializeValidationState(pm);
....
if (!change.isEnabled())
return;
RefactoringStatus valid= change.isValid(new SubProgressMonitor(pm, 1));
if (valid.hasFatalError())
return;
Change undo= change.perform(new SubProgressMonitor(pm, 1));
if (undo != null) {
undo.initializeValidationState(new SubProgressMonitor(pm, 1));
// do something with the undo object
}
} finally {
change.dispose();
}
It is important that implementors of this abstract class provide an adequate
implementation of isValid and that they provide an undo change
via the return value of the method perform. If no undo can be
provided then the perform method is allowed to return null. But
implementors should be aware that not providing an undo object for a change
object that is part of a larger change tree will result in the fact that for
the whole change tree no undo object will be present.
Clients may subclass this class.
- Since:
- 3.0
| Field Summary | |
private boolean |
fIsEnabled
|
private Change |
fParent
|
| Constructor Summary | |
protected |
Change()
Constructs a new change object. |
| Method Summary | |
void |
dispose()
Disposes this change. |
java.lang.Object |
getAdapter(java.lang.Class adapter)
null |
abstract java.lang.Object |
getModifiedElement()
Returns the element modified by this Change. |
abstract java.lang.String |
getName()
Returns the human readable name of this change. |
Change |
getParent()
Returns the parent change. |
abstract void |
initializeValidationData(org.eclipse.core.runtime.IProgressMonitor pm)
Hook method to initialize some internal state to provide an adequate answer for the isValid method. |
boolean |
isEnabled()
Returns whether this change is enabled or not. |
abstract RefactoringStatus |
isValid(org.eclipse.core.runtime.IProgressMonitor pm)
Verifies that this change object is still valid and can be executed by calling perform. |
abstract Change |
perform(org.eclipse.core.runtime.IProgressMonitor pm)
Performs this change. |
void |
setEnabled(boolean enabled)
Sets whether this change is enabled or not. |
(package private) void |
setParent(Change parent)
Sets the parent of this change. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
fParent
private Change fParent
fIsEnabled
private boolean fIsEnabled
| Constructor Detail |
Change
protected Change()
- Constructs a new change object.
| Method Detail |
getName
public abstract java.lang.String getName()
- Returns the human readable name of this change. The
name MUST not be
null.
isEnabled
public boolean isEnabled()
- Returns whether this change is enabled or not. Disabled changes
must not be executed.
setEnabled
public void setEnabled(boolean enabled)
- Sets whether this change is enabled or not.
getParent
public Change getParent()
- Returns the parent change. Returns
nullif no parent exists.
setParent
void setParent(Change parent)
- Sets the parent of this change. Requires that this change isn't already
connected to a parent. The parent can be
nullto disconnect this change from a parent.
initializeValidationData
public abstract void initializeValidationData(org.eclipse.core.runtime.IProgressMonitor pm)
- Hook method to initialize some internal state to provide an adequate answer
for the
isValidmethod. This method gets called after a change or a whole change tree has been created.Typically this method is implemented in one of the following ways:
- the change hooks up a listener on some delta notification mechanism
and marks itself as invalid if it receives a certain delta. Is this
the case the implementor must take care of unhooking the listener
in
dispose. - the change remembers some information allowing to decide if a change
object is still valid when
isValidis called.
For example, a change object that manipulates the content of an
IFilecould either listen to resource changes and detect that the file got changed or it could remember some content stamp and compare it with the actual content stamp whenisValidis called. - the change hooks up a listener on some delta notification mechanism
and marks itself as invalid if it receives a certain delta. Is this
the case the implementor must take care of unhooking the listener
in
isValid
public abstract RefactoringStatus isValid(org.eclipse.core.runtime.IProgressMonitor pm) throws org.eclipse.core.runtime.CoreException, org.eclipse.core.runtime.OperationCanceledException
- Verifies that this change object is still valid and can be executed by calling
perform. If a refactoring status with a severity ofRefactoringStatus.FATAL55 is returned then the change has to be treated as invalid and can no longer be executed. Performing such a change produces an unspecified result and will very likely throw an exception.This method is also called by the UndoManager to decide if an undo or redo change is still valid and therefore can be executed.
perform
public abstract Change perform(org.eclipse.core.runtime.IProgressMonitor pm) throws org.eclipse.core.runtime.CoreException
- Performs this change. If this method is call on an invalid or disabled change
object the result is unspecified. Changes should in general not respond to
IProgressMonitor.isCanceled()>
IProgressMonitor.isCanceled()55 since canceling a change tree in the middle of its execution leaves the workspace in a half changed state.
dispose
public void dispose()
- Disposes this change. Subclasses that override this method typically
unregister listeners which got registered during the call to
initializeValidationState.Subclasses may override this method.
getModifiedElement
public abstract java.lang.Object getModifiedElement()
- Returns the element modified by this
Change. The method may returnnullif the change isn't related to an element.
getAdapter
public java.lang.Object getAdapter(java.lang.Class adapter)
- null
- Specified by:
getAdapterin interfaceorg.eclipse.core.runtime.IAdaptable
|
|||||||||
| Home >> All >> org >> eclipse >> ltk >> core >> [ refactoring overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.eclipse.ltk.core.refactoring.Change