Package org.eclipse.handly.refactoring
Class SourceFileChange
java.lang.Object
org.eclipse.ltk.core.refactoring.Change
org.eclipse.ltk.core.refactoring.TextEditBasedChange
org.eclipse.handly.refactoring.SourceFileChange
- All Implemented Interfaces:
org.eclipse.core.runtime.IAdaptable
public class SourceFileChange
extends org.eclipse.ltk.core.refactoring.TextEditBasedChange
A
TextEditBasedChange that operates on a ISourceFile.-
Constructor Summary
ConstructorsConstructorDescriptionSourceFileChange(String name, ISourceFile sourceFile) Creates a source file change that initially contains only an empty root edit.SourceFileChange(String name, ISourceFile sourceFile, org.eclipse.text.edits.TextEdit edit) Creates a source file change with the given edit tree. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEdit(org.eclipse.text.edits.TextEdit edit) Adds the given edit by auto inserting it into the change's edit tree.voidaddEdits(org.eclipse.text.edits.TextEdit[] edits) Adds the given edits by auto inserting them into the change's edit tree.voidaddGroupedEdits(org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup group) Inserts the edits of the given group into the change's edit tree and thenaddsthe group itself to the change.voidaddGroupedEdits(org.eclipse.text.edits.TextEditGroup group) Inserts the edits of the given group into the change's edit tree and thenaddsthe group itself to the change.Object[]getBase()Returns the snapshot on which the change's edit tree is based, ornullif the snapshot is unknown.getCurrentContent(org.eclipse.core.runtime.IProgressMonitor pm) getCurrentContent(org.eclipse.jface.text.IRegion region, boolean expandRegionToFullLine, int surroundingLines, org.eclipse.core.runtime.IProgressMonitor pm) org.eclipse.text.edits.TextEditgetEdit()Returns the root of the change's edit tree.getPreviewContent(org.eclipse.core.runtime.IProgressMonitor pm) getPreviewContent(org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup[] changeGroups, org.eclipse.jface.text.IRegion region, boolean expandRegionToFullLine, int surroundingLines, org.eclipse.core.runtime.IProgressMonitor pm) org.eclipse.jface.text.IDocumentgetPreviewDocument(org.eclipse.core.runtime.IProgressMonitor pm) Returns a document containing a preview of this change.org.eclipse.text.edits.TextEditgetPreviewEdit(org.eclipse.text.edits.TextEdit original) Returns the edit that got executed during preview generation instead of the given original edit.org.eclipse.text.edits.TextEdit[]getPreviewEdits(org.eclipse.text.edits.TextEdit[] originals) Returns the edits that got executed during preview generation instead of the given array of original edits.Returns the save mode associated with this change.voidinitializeValidationData(org.eclipse.core.runtime.IProgressMonitor pm) org.eclipse.ltk.core.refactoring.RefactoringStatusisValid(org.eclipse.core.runtime.IProgressMonitor pm) org.eclipse.ltk.core.refactoring.Changeperform(org.eclipse.core.runtime.IProgressMonitor pm) voidSets the snapshot on which the change's edit tree is based.voidsetKeepPreviewEdits(boolean keep) voidsetSaveMode(SaveMode saveMode) Sets the save mode of this change.Methods inherited from class org.eclipse.ltk.core.refactoring.TextEditBasedChange
addChangeGroup, addTextEditGroup, getChangeGroups, getKeepPreviewEdits, getName, getTextType, hasOneGroupCategory, setEnabled, setTextTypeMethods inherited from class org.eclipse.ltk.core.refactoring.Change
dispose, getAdapter, getDescriptor, getParent, isEnabled, setEnabledShallow
-
Constructor Details
-
SourceFileChange
Creates a source file change that initially contains only an empty root edit.- Parameters:
name- the change's name, mainly used to render the change in the UI - must not benullsourceFile- the source file this change works on - must not benull
-
SourceFileChange
Creates a source file change with the given edit tree. The structure of the tree may be modified later.- Parameters:
name- the change's name, mainly used to render the change in the UI - must not benullsourceFile- the source file this change works on - must not benulledit- the root of the change's edit tree - must not benull
-
-
Method Details
-
getEdit
public org.eclipse.text.edits.TextEdit getEdit()Returns the root of the change's edit tree.- Returns:
- the root of the change's edit tree (never
null)
-
addEdit
public void addEdit(org.eclipse.text.edits.TextEdit edit) Adds the given edit by auto inserting it into the change's edit tree. Convenience method.- Parameters:
edit- the edit to add - must not benull- Throws:
org.eclipse.text.edits.MalformedTreeException- if the edit could not be inserted
-
addEdits
public void addEdits(org.eclipse.text.edits.TextEdit[] edits) Adds the given edits by auto inserting them into the change's edit tree. Convenience method.- Parameters:
edits- the edits to add - must not benull- Throws:
org.eclipse.text.edits.MalformedTreeException- if the edits could not be inserted
-
addGroupedEdits
public void addGroupedEdits(org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup group) Inserts the edits of the given group into the change's edit tree and thenaddsthe group itself to the change. Convenience method.- Parameters:
group- the group to add - must not benull- Throws:
org.eclipse.text.edits.MalformedTreeException- if the edits could not be inserted
-
addGroupedEdits
public void addGroupedEdits(org.eclipse.text.edits.TextEditGroup group) Inserts the edits of the given group into the change's edit tree and thenaddsthe group itself to the change. Convenience method.- Parameters:
group- the group to add - must not benull- Throws:
org.eclipse.text.edits.MalformedTreeException- if the edits could not be inserted
-
setBase
Sets the snapshot on which the change's edit tree is based.- Parameters:
base- the snapshot on which the change is based, ornullif unknown
-
getBase
Returns the snapshot on which the change's edit tree is based, ornullif the snapshot is unknown.- Returns:
- the snapshot on which the change is based,
or
nullif unknown
-
setSaveMode
Sets the save mode of this change.- Parameters:
saveMode- a save mode
-
getSaveMode
Returns the save mode associated with this change.- Returns:
- the change's save mode
-
initializeValidationData
public void initializeValidationData(org.eclipse.core.runtime.IProgressMonitor pm) - Specified by:
initializeValidationDatain classorg.eclipse.ltk.core.refactoring.Change
-
isValid
public org.eclipse.ltk.core.refactoring.RefactoringStatus isValid(org.eclipse.core.runtime.IProgressMonitor pm) throws org.eclipse.core.runtime.CoreException, org.eclipse.core.runtime.OperationCanceledException - Specified by:
isValidin classorg.eclipse.ltk.core.refactoring.Change- Throws:
org.eclipse.core.runtime.CoreExceptionorg.eclipse.core.runtime.OperationCanceledException
-
perform
public org.eclipse.ltk.core.refactoring.Change perform(org.eclipse.core.runtime.IProgressMonitor pm) throws org.eclipse.core.runtime.CoreException - Specified by:
performin classorg.eclipse.ltk.core.refactoring.Change- Throws:
org.eclipse.core.runtime.CoreException
-
getModifiedElement
- Specified by:
getModifiedElementin classorg.eclipse.ltk.core.refactoring.Change
-
getAffectedObjects
- Overrides:
getAffectedObjectsin classorg.eclipse.ltk.core.refactoring.Change
-
getCurrentContent
public String getCurrentContent(org.eclipse.core.runtime.IProgressMonitor pm) throws org.eclipse.core.runtime.CoreException - Specified by:
getCurrentContentin classorg.eclipse.ltk.core.refactoring.TextEditBasedChange- Throws:
org.eclipse.core.runtime.CoreException
-
getCurrentContent
public String getCurrentContent(org.eclipse.jface.text.IRegion region, boolean expandRegionToFullLine, int surroundingLines, org.eclipse.core.runtime.IProgressMonitor pm) throws org.eclipse.core.runtime.CoreException - Specified by:
getCurrentContentin classorg.eclipse.ltk.core.refactoring.TextEditBasedChange- Throws:
org.eclipse.core.runtime.CoreException
-
getPreviewContent
public String getPreviewContent(org.eclipse.core.runtime.IProgressMonitor pm) throws org.eclipse.core.runtime.CoreException - Specified by:
getPreviewContentin classorg.eclipse.ltk.core.refactoring.TextEditBasedChange- Throws:
org.eclipse.core.runtime.CoreException
-
getPreviewContent
public String getPreviewContent(org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup[] changeGroups, org.eclipse.jface.text.IRegion region, boolean expandRegionToFullLine, int surroundingLines, org.eclipse.core.runtime.IProgressMonitor pm) throws org.eclipse.core.runtime.CoreException - Specified by:
getPreviewContentin classorg.eclipse.ltk.core.refactoring.TextEditBasedChange- Throws:
org.eclipse.core.runtime.CoreException
-
setKeepPreviewEdits
public void setKeepPreviewEdits(boolean keep) - Overrides:
setKeepPreviewEditsin classorg.eclipse.ltk.core.refactoring.TextEditBasedChange
-
getPreviewEdit
public org.eclipse.text.edits.TextEdit getPreviewEdit(org.eclipse.text.edits.TextEdit original) Returns the edit that got executed during preview generation instead of the given original edit. This method requires thatsetKeepPreviewEditsis set totrueand that a preview has been requested viagetPreviewContentorgetPreviewDocumentmethods.This method returns
nullif the original edit is not managed by this change.- Parameters:
original- the original edit - must not benull- Returns:
- the edit executed during preview generation, or
nullif the original edit is not managed by this change - Throws:
IllegalStateException- ifsetKeepPreviewEditsis set tofalseor a preview has not been requested
-
getPreviewEdits
public org.eclipse.text.edits.TextEdit[] getPreviewEdits(org.eclipse.text.edits.TextEdit[] originals) Returns the edits that got executed during preview generation instead of the given array of original edits. This method requires thatsetKeepPreviewEditsis set totrueand that a preview has been requested viagetPreviewContentorgetPreviewDocumentmethods.This method returns an empty array if none of the original edits is managed by this change. If some of the original edits are not managed by this change, the length of the returned array will be less than the length of the given array; the returned array never contains
nullelements.- Parameters:
originals- an array of original edits - must not containnullelements- Returns:
- an array of edits containing the corresponding edits
executed during preview generation (never
null) - Throws:
IllegalStateException- ifsetKeepPreviewEditsis set tofalseor a preview has not been requested
-
getPreviewDocument
public org.eclipse.jface.text.IDocument getPreviewDocument(org.eclipse.core.runtime.IProgressMonitor pm) throws org.eclipse.core.runtime.CoreException Returns a document containing a preview of this change. The preview is computed by executing text edits managed by this change. The method considers the active state of the added text edit change groups.- Parameters:
pm- a progress monitor to report progress, ornullif progress reporting is not desired. The caller must not rely onIProgressMonitor.done()having been called by the receiver- Returns:
- a document containing the preview of this change
(never
null) - Throws:
org.eclipse.core.runtime.CoreException- if the preview could not be created
-