Class MultiStateTextFileChange
- All Implemented Interfaces:
IAdaptable
text edit trees
to a document. The multi state text file change manages the text edit trees.
A multi state text file change offers the ability to access the original content of
the document as well as creating a preview of the change. The edit
trees get copied when creating any kind of preview. Therefore no region
updating on the original edit trees takes place when requesting a preview
(for more information on region updating see class TextEdit
.
If region tracking is required for a preview it can be enabled via a call
to the method setKeepPreviewEdits
.
If enabled the multi state text file change keeps the copied edit trees executed for the
preview allowing clients to map an original edit to an executed edit. The
executed edit can then be used to determine its position in the preview.
- Since:
- 3.2
-
Constructor Summary
ConstructorDescriptionMultiStateTextFileChange
(String name, IFile file) Creates a new composite text file change. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
addChange
(TextChange change) Adds a new text change to this composite change.final void
dispose()
Disposes this change.final String
getCurrentContent
(IProgressMonitor monitor) Returns the current content of the document this text change is associated with.final String
getCurrentContent
(IRegion region, boolean expand, int surround, IProgressMonitor monitor) Returns the current content of the text edit change clipped to a specific region.final IDocument
getCurrentDocument
(IProgressMonitor monitor) Returns a document representing the current state of the buffer, prior to the application of the change.final Object
Returns the element modified by thisChange
.final String
getPreviewContent
(IProgressMonitor monitor) Returns the preview content as a string.final String
getPreviewContent
(TextEditBasedChangeGroup[] groups, IRegion region, boolean expand, int surround, IProgressMonitor monitor) Returns a preview of the text edit change clipped to a specific region.final IDocument
getPreviewDocument
(IProgressMonitor monitor) Returns a document representing the preview of the refactored buffer, after the application of the change object.final int
Returns the save mode of this change.final void
initializeValidationData
(IProgressMonitor monitor) Hook method to initialize some internal state to provide an adequate answer for theisValid
method.final RefactoringStatus
isValid
(IProgressMonitor monitor) Verifies that this change object is still valid and can be executed by callingperform
.final boolean
Does the change need saving?final Change
perform
(IProgressMonitor monitor) Performs this change.final void
setKeepPreviewEdits
(boolean keep) Controls whether the text edit change should keep executed edits during preview generation.final void
setSaveMode
(int mode) Sets the save mode.Methods inherited from class org.eclipse.ltk.core.refactoring.TextEditBasedChange
addChangeGroup, addTextEditGroup, getChangeGroups, getKeepPreviewEdits, getName, getTextType, hasOneGroupCategory, setEnabled, setTextType
Methods inherited from class org.eclipse.ltk.core.refactoring.Change
getAdapter, getAffectedObjects, getDescriptor, getParent, isEnabled, setEnabledShallow
-
Constructor Details
-
MultiStateTextFileChange
Creates a new composite text file change.The default text type is
txt
.- Parameters:
name
- the name of the composite text file changefile
- the text file to apply the change to
-
-
Method Details
-
addChange
Adds a new text change to this composite change.The text change which is added is not changed in any way. Rather the contents of the text change are retrieved and stored internally in this composite text change.
- Parameters:
change
- the text change to add
-
dispose
public final void dispose()Description copied from class:Change
Disposes this change. Subclasses that override this method typically unregister listeners which got registered during the call toinitializeValidationData
.Subclasses may override this method.
-
getCurrentContent
Description copied from class:TextEditBasedChange
Returns the current content of the document this text change is associated with.- Specified by:
getCurrentContent
in classTextEditBasedChange
- Parameters:
monitor
- a progress monitor to report progress ornull
if no progress reporting is desired- Returns:
- the current content of the text edit change
- Throws:
CoreException
- if the content can't be accessed
-
getCurrentContent
public final String getCurrentContent(IRegion region, boolean expand, int surround, IProgressMonitor monitor) throws CoreException Description copied from class:TextEditBasedChange
Returns the current content of the text edit change clipped to a specific region. The region is determined as follows:- if
expandRegionToFullLine
isfalse
then the parameterregion
determines the clipping. - if
expandRegionToFullLine
istrue
then the region determined by the parameterregion
is extended to cover full lines. - if
surroundingLines
> 0 then the given number of surrounding lines is added. The value ofsurroundingLines
is only considered ifexpandRegionToFullLine
istrue
- Specified by:
getCurrentContent
in classTextEditBasedChange
- Parameters:
region
- the starting region for the text to be returnedexpand
- iftrue
is passed the region is extended to cover full linessurround
- the number of surrounding lines to be added to the clipping region. Is only considered ifexpandRegionToFullLine
istrue
monitor
- a progress monitor to report progress ornull
if no progress reporting is desired- Returns:
- the current content of the text edit change clipped to a region determined by the given parameters.
- Throws:
CoreException
- if an exception occurs while accessing the current content
- if
-
getCurrentDocument
Returns a document representing the current state of the buffer, prior to the application of the change.The returned document should not be modified.
- Parameters:
monitor
- the progress monitor to use, ornull
- Returns:
- the current document, or the empty document
- Throws:
CoreException
- if no document could be acquired
-
getModifiedElement
Description copied from class:Change
Returns the element modified by thisChange
. The method may returnnull
if the change isn't related to an element.- Specified by:
getModifiedElement
in classChange
- Returns:
- the element modified by this change
-
getPreviewContent
public final String getPreviewContent(TextEditBasedChangeGroup[] groups, IRegion region, boolean expand, int surround, IProgressMonitor monitor) throws CoreException Description copied from class:TextEditBasedChange
Returns a preview of the text edit change clipped to a specific region. The preview is created by applying the text edits managed by the given array oftext edit change groups
. The region is determined as follows:- if
expandRegionToFullLine
isfalse
then the parameterregion
determines the clipping. - if
expandRegionToFullLine
istrue
then the region determined by the parameterregion
is extended to cover full lines. - if
surroundingLines
> 0 then the given number of surrounding lines is added. The value ofsurroundingLines
is only considered ifexpandRegionToFullLine
istrue
- Specified by:
getPreviewContent
in classTextEditBasedChange
- Parameters:
groups
- a set of change groups for which a preview is to be generatedregion
- the starting region for the clippingexpand
- iftrue
is passed the region is extended to cover full linessurround
- the number of surrounding lines to be added to the clipping region. Is only considered ifexpandRegionToFullLine
istrue
monitor
- a progress monitor to report progress ornull
if no progress reporting is desired- Returns:
- the current content of the text change clipped to a region determined by the given parameters.
- Throws:
CoreException
- if an exception occurs while generating the preview- See Also:
- if
-
getPreviewContent
Description copied from class:TextEditBasedChange
Returns the preview content as a string.- Specified by:
getPreviewContent
in classTextEditBasedChange
- Parameters:
monitor
- a progress monitor to report progress ornull
if no progress reporting is desired- Returns:
- the preview
- Throws:
CoreException
- if the preview can't be created
-
getPreviewDocument
Returns a document representing the preview of the refactored buffer, after the application of the change object.- Parameters:
monitor
- the progress monitor to use, ornull
- Returns:
- the preview document, or an empty document
- Throws:
CoreException
- if no document could be acquired
-
getSaveMode
public final int getSaveMode()Returns the save mode of this change.- Returns:
- the save mode
-
initializeValidationData
Description copied from class:Change
Hook method to initialize some internal state to provide an adequate answer for theisValid
method. 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
isValid
is called.
For example, a change object that manipulates the content of an
IFile
could 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 whenisValid
is called.- Specified by:
initializeValidationData
in classChange
- Parameters:
monitor
- a progress monitor
- 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 final RefactoringStatus isValid(IProgressMonitor monitor) throws CoreException, OperationCanceledException Description copied from class:Change
Verifies that this change object is still valid and can be executed by callingperform
. If a refactoring status with a severity ofRefactoringStatus.FATAL
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.- Specified by:
isValid
in classChange
- Parameters:
monitor
- a progress monitor.- Returns:
- a refactoring status describing the outcome of the validation check
- Throws:
CoreException
- if an error occurred during validation check. The change is to be treated as invalid if an exception occursOperationCanceledException
- if the validation check got canceled
-
needsSaving
public final boolean needsSaving()Does the change need saving?- Returns:
true
if it needs saving,false
otherwise
-
perform
Description copied from class:Change
Performs this change. If this method is called on an invalid or disabled change object the result is unspecified. Changes should in general not respond toIProgressMonitor.isCanceled()
since canceling a change tree in the middle of its execution leaves the workspace in a half changed state.- Specified by:
perform
in classChange
- Parameters:
monitor
- a progress monitor- Returns:
- the undo change for this change object or
null
if no undo is provided - Throws:
CoreException
- if an error occurred during change execution
-
setKeepPreviewEdits
public final void setKeepPreviewEdits(boolean keep) Description copied from class:TextEditBasedChange
Controls whether the text edit change should keep executed edits during preview generation.- Overrides:
setKeepPreviewEdits
in classTextEditBasedChange
- Parameters:
keep
- iftrue
executed preview edits are kept
-
setSaveMode
public final void setSaveMode(int mode) Sets the save mode.- Parameters:
mode
- The mode to set
-