- All Implemented Interfaces:
IDocument. The document change uses a simple length compare to check if it is still valid. So as long as its length hasn't changed the text edits managed have a valid range and can be applied to the document. The same applies to the undo change returned from the perform method.
Note: this class is not intended to be extended by clients.
- This class is not intended to be subclassed by clients.
Method SummaryModifier and TypeMethodDescription
protected IDocumentAcquires a reference to the document to be changed by this text change.
protected voidCommits the document acquired via a call to
protected ChangeHook to create an undo change for the given undo edit.Returns the element modified by this
voidHook method to initialize some internal state to provide an adequate answer for the
isValidmethod.Verifies that this change object is still valid and can be executed by calling
protected UndoEditExecutes the text edits on the given document.
Methods inherited from class org.eclipse.ltk.core.refactoring.TextChange
addEdit, addTextEditChangeGroup, addTextEditGroup, getCurrentContent, getCurrentContent, getCurrentDocument, getEdit, getPreviewContent, getPreviewContent, getPreviewContent, getPreviewDocument, getPreviewEdit, getPreviewEdits, getTextEditChangeGroups, perform, setEdit, setKeepPreviewEdits
Methods inherited from class org.eclipse.ltk.core.refactoring.TextEditBasedChange
addChangeGroup, getChangeGroups, getKeepPreviewEdits, getName, getTextType, hasOneGroupCategory, setEnabled, setTextType
Methods inherited from class org.eclipse.ltk.core.refactoring.Change
dispose, getAdapter, getAffectedObjects, getDescriptor, getParent, isEnabled, setEnabledShallow
name- the change's name. Has to be a human readable name.
document- the document this change is working on
getModifiedElementpublic Object getModifiedElement()Returns the element modified by this
Change. The method may return
nullif the change isn't related to an element.
initializeValidationDatapublic void initializeValidationData
(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
- the change remembers some information allowing to decide if a change
object is still valid when
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 when
- 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
isValidVerifies that this change object is still valid and can be executed by calling
perform. If a refactoring status with a severity of
RefactoringStatus.FATALis 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
UndoManagerto decide if an undo or redo change is still valid and therefore can be executed.
acquireDocumentAcquires a reference to the document to be changed by this text change. A document acquired by this call MUST be released via a call to
releaseDocumentmust be called as many times as
aquireDocumenthas been called.
commitCommits the document acquired via a call to
aquireDocument. It is up to the implementors of this method to decide what committing a document means. Typically, the content of the document is written back to the file system.
performEditsprotected UndoEdit performEdits
(IDocument document) throws BadLocationException, MalformedTreeExceptionExecutes the text edits on the given document. Subclasses that override this method should call
document- the document
- an object representing the undo of the executed edits
BadLocationException- is thrown if one of the edits in the tree can't be executed. The state of the document is undefined if this exception is thrown.
MalformedTreeException- is thrown if the edit tree isn't in a valid state. This exception is thrown before any edit is executed. So the document is still in its original state.
createUndoChangeHook to create an undo change for the given undo edit. This hook gets called while performing the change to construct the corresponding undo change object.
- Specified by:
UndoEditto create an undo change for
- the undo change or
nullif no undo change can be created. Returning
nullresults in the fact that the whole change tree can't be undone. So returning
nullis only recommended if an exception occurred during the creation of the undo change.