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

    Constructors
    Constructor and Description
    `SourceFileChange(java.lang.String name, ISourceFile sourceFile)` Creates a source file change that initially contains only an empty root edit.
    `SourceFileChange(java.lang.String name, ISourceFile sourceFile, org.eclipse.text.edits.TextEdit edit)` Creates a source file change with the given edit tree.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addEdit(org.eclipse.text.edits.TextEdit edit)` Adds the given edit by auto inserting it into the change's edit tree.
    `void` | `addEdits(org.eclipse.text.edits.TextEdit[] edits)` Adds the given edits by auto inserting them into the change's edit tree.
    `void` | `addGroupedEdits(org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup group)` Inserts the edits of the given group into the change's edit tree and then `adds` the group itself to the change.
    `void` | `addGroupedEdits(org.eclipse.text.edits.TextEditGroup group)` Inserts the edits of the given group into the change's edit tree and then `adds` the group itself to the change.
    `java.lang.Object[]` | `getAffectedObjects()`
    `ISnapshot` | `getBase()` Returns the snapshot on which the change's edit tree is based, or `null` if the snapshot is unknown.
    `java.lang.String` | `getCurrentContent(org.eclipse.core.runtime.IProgressMonitor pm)`
    `java.lang.String` | `getCurrentContent(org.eclipse.jface.text.IRegion region, boolean expandRegionToFullLine, int surroundingLines, org.eclipse.core.runtime.IProgressMonitor pm)`
    `org.eclipse.text.edits.TextEdit` | `getEdit()` Returns the root of the change's edit tree.
    `java.lang.Object` | `getModifiedElement()`
    `java.lang.String` | `getPreviewContent(org.eclipse.core.runtime.IProgressMonitor pm)`
    `java.lang.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)`
    `org.eclipse.jface.text.IDocument` | `getPreviewDocument(org.eclipse.core.runtime.IProgressMonitor pm)` Returns a document containing a preview of this change.
    `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.
    `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.
    `SaveMode` | `getSaveMode()` Returns the save mode associated with this change.
    `void` | `initializeValidationData(org.eclipse.core.runtime.IProgressMonitor pm)`
    `org.eclipse.ltk.core.refactoring.RefactoringStatus` | `isValid(org.eclipse.core.runtime.IProgressMonitor pm)`
    `org.eclipse.ltk.core.refactoring.Change` | `perform(org.eclipse.core.runtime.IProgressMonitor pm)`
    `void` | `setBase(ISnapshot base)` Sets the snapshot on which the change's edit tree is based.
    `void` | `setKeepPreviewEdits(boolean keep)`
    `void` | `setSaveMode(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, setTextType`

    - ### Methods inherited from class org.eclipse.ltk.core.refactoring.Change

      `dispose, getAdapter, getDescriptor, getParent, isEnabled, setEnabledShallow`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### SourceFileChange

          public SourceFileChange(java.lang.String name,
                                  ISourceFile sourceFile)

      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 be `null`
        `sourceFile` - the source file this change works on - must not be `null`

    - #### SourceFileChange

          public SourceFileChange(java.lang.String name,
                                  ISourceFile sourceFile,
                                  org.eclipse.text.edits.TextEdit edit)

      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 be `null`
        `sourceFile` - the source file this change works on - must not be `null`
        `edit` - the root of the change's edit tree - must not be `null`

  - ### Method Detail

    - #### 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 be `null`
      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 be `null`
      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 then `adds` the group itself to the change. Convenience method.
      Parameters:
        `group` - the group to add - must not be `null`
      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 then `adds` the group itself to the change. Convenience method.
      Parameters:
        `group` - the group to add - must not be `null`
      Throws:
        `org.eclipse.text.edits.MalformedTreeException` - if the edits could not be inserted

    - #### setBase

          public void setBase(ISnapshot base)

      Sets the snapshot on which the change's edit tree is based.
      Parameters:
        `base` - the snapshot on which the change is based, or `null` if unknown

    - #### getBase

          public ISnapshot getBase()

      Returns the snapshot on which the change's edit tree is based, or `null` if the snapshot is unknown.
      Returns:
        the snapshot on which the change is based, or `null` if unknown

    - #### setSaveMode

          public void setSaveMode(SaveMode saveMode)

      Sets the save mode of this change.
      Parameters:
        `saveMode` - a save mode

    - #### getSaveMode

          public SaveMode 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:
        `initializeValidationData` in class `org.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:
        `isValid` in class `org.eclipse.ltk.core.refactoring.Change`
      Throws:
        `org.eclipse.core.runtime.CoreException`
        `org.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:
        `perform` in class `org.eclipse.ltk.core.refactoring.Change`
      Throws:
        `org.eclipse.core.runtime.CoreException`

    - #### getModifiedElement

          public java.lang.Object getModifiedElement()

      Specified by:
        `getModifiedElement` in class `org.eclipse.ltk.core.refactoring.Change`

    - #### getAffectedObjects

          public java.lang.Object[] getAffectedObjects()

      Overrides:
        `getAffectedObjects` in class `org.eclipse.ltk.core.refactoring.Change`

    - #### getCurrentContent

          public java.lang.String getCurrentContent(org.eclipse.core.runtime.IProgressMonitor pm)
                                             throws org.eclipse.core.runtime.CoreException

      Specified by:
        `getCurrentContent` in class `org.eclipse.ltk.core.refactoring.TextEditBasedChange`
      Throws:
        `org.eclipse.core.runtime.CoreException`

    - #### getCurrentContent

          public java.lang.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:
        `getCurrentContent` in class `org.eclipse.ltk.core.refactoring.TextEditBasedChange`
      Throws:
        `org.eclipse.core.runtime.CoreException`

    - #### getPreviewContent

          public java.lang.String getPreviewContent(org.eclipse.core.runtime.IProgressMonitor pm)
                                             throws org.eclipse.core.runtime.CoreException

      Specified by:
        `getPreviewContent` in class `org.eclipse.ltk.core.refactoring.TextEditBasedChange`
      Throws:
        `org.eclipse.core.runtime.CoreException`

    - #### getPreviewContent

          public java.lang.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:
        `getPreviewContent` in class `org.eclipse.ltk.core.refactoring.TextEditBasedChange`
      Throws:
        `org.eclipse.core.runtime.CoreException`

    - #### setKeepPreviewEdits

          public void setKeepPreviewEdits(boolean keep)

      Overrides:
        `setKeepPreviewEdits` in class `org.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 that `setKeepPreviewEdits` is set to `true` and that a preview has been requested via `getPreviewContent` or `getPreviewDocument` methods.

      This method returns `null` if the original edit is not managed by this change.

      Parameters:
        `original` - the original edit - must not be `null`
      Returns:
        the edit executed during preview generation, or `null` if the original edit is not managed by this change
      Throws:
        `java.lang.IllegalStateException` - if `setKeepPreviewEdits` is set to `false` or 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 that `setKeepPreviewEdits` is set to `true` and that a preview has been requested via `getPreviewContent` or `getPreviewDocument` methods.

      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 `null` elements.

      Parameters:
        `originals` - an array of original edits - must not contain `null` elements
      Returns:
        an array of edits containing the corresponding edits executed during preview generation (never `null`)
      Throws:
        `java.lang.IllegalStateException` - if `setKeepPreviewEdits` is set to `false` or 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, or `null` if progress reporting is not desired. The caller must not rely on `IProgressMonitor.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

Copyright (c) 2014, 2020 1C-Soft LLC and others. Made available under the Eclipse Public License 2.0