Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.eclipse.ltk.core.refactoring
Class TextChange  view TextChange download TextChange.java

java.lang.Object
  extended byorg.eclipse.ltk.core.refactoring.Change
      extended byorg.eclipse.ltk.core.refactoring.TextChange
All Implemented Interfaces:
org.eclipse.core.runtime.IAdaptable
Direct Known Subclasses:
DocumentChange, TextFileChange

public abstract class TextChange
extends Change

A text change is a special change object that applies a text edit tree to a document. The text change manages the text edit tree. Access to the document must be provided by concrete subclasses via the method aquireDocument 55 , commitDocument 55 , and releaseDocument 55 .

A text change offers the ability to access the original content of the document as well as creating a preview of the change. The edit tree gets copied when creating any king of preview. Therefore no region updating on the original edit tree 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 55 . If enabled the text change keeps the copied edit tree 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.

Note: this class is not intended to be subclassed outside the refactoring framework.

Since:
3.0

Nested Class Summary
private static class TextChange.LocalTextEditProcessor
           
private static class TextChange.PreviewAndRegion
           
 
Field Summary
private static TextEditChangeGroup[] ALL_EDITS
          A special object denoting all edits managed by the text change.
private  org.eclipse.text.edits.TextEditCopier fCopier
           
private  org.eclipse.text.edits.TextEdit fEdit
           
private  java.lang.String fName
           
private  java.util.List fTextEditChangeGroups
           
private  java.lang.String fTextType
           
private  boolean fTrackEdits
           
 
Fields inherited from class org.eclipse.ltk.core.refactoring.Change
 
Constructor Summary
protected TextChange(java.lang.String name)
          Creates a new text change with the specified name.
 
Method Summary
protected abstract  org.eclipse.jface.text.IDocument acquireDocument(org.eclipse.core.runtime.IProgressMonitor pm)
          Acquires a reference to the document to be changed by this text change.
 void addTextEditChangeGroup(TextEditChangeGroup group)
          Adds a text edit change group.
 void addTextEditGroup(org.eclipse.text.edits.TextEditGroup group)
          Adds a text edit group.
protected abstract  void commit(org.eclipse.jface.text.IDocument document, org.eclipse.core.runtime.IProgressMonitor pm)
          Commits the document acquired via a call to aquireDocument 55 .
private  org.eclipse.text.edits.TextEditProcessor createTextEditProcessor(org.eclipse.jface.text.IDocument document, int flags, boolean preview)
           
private  org.eclipse.text.edits.TextEditProcessor createTextEditProcessor(org.eclipse.jface.text.IDocument document, int flags, TextEditChangeGroup[] changes)
           
protected abstract  Change createUndoChange(org.eclipse.text.edits.UndoEdit edit)
          Hook to create an undo change for the given undo edit.
private  java.lang.String getContent(org.eclipse.jface.text.IDocument document, org.eclipse.jface.text.IRegion region, boolean expandRegionToFullLine, int surroundingLines)
           
 java.lang.String getCurrentContent(org.eclipse.core.runtime.IProgressMonitor pm)
          Returns the current content of the document this text change is associated with.
 java.lang.String getCurrentContent(org.eclipse.jface.text.IRegion region, boolean expandRegionToFullLine, int surroundingLines, org.eclipse.core.runtime.IProgressMonitor pm)
          Returns the current content of the text change clipped to a specific region.
 org.eclipse.jface.text.IDocument getCurrentDocument(org.eclipse.core.runtime.IProgressMonitor pm)
          Returns the document this text change is associated to.
 org.eclipse.text.edits.TextEdit getEdit()
          Returns the root text edit.
 boolean getKeepPreviewEdits()
          Returns whether preview edits are remembered for further region tracking or not.
 java.lang.String getName()
          null
private  org.eclipse.jface.text.IRegion getNewRegion(TextEditChangeGroup[] changes)
           
 java.lang.String getPreviewContent(org.eclipse.core.runtime.IProgressMonitor pm)
          Returns the preview content as a string.
 java.lang.String getPreviewContent(TextEditChangeGroup[] changeGroups, org.eclipse.jface.text.IRegion region, boolean expandRegionToFullLine, int surroundingLines, org.eclipse.core.runtime.IProgressMonitor pm)
          Returns a preview of the text change clipped to a specific region.
 org.eclipse.jface.text.IDocument getPreviewDocument(org.eclipse.core.runtime.IProgressMonitor pm)
          Returns a document containing a preview of the text change.
private  TextChange.PreviewAndRegion getPreviewDocument(TextEditChangeGroup[] changes, org.eclipse.core.runtime.IProgressMonitor pm)
           
 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.
 org.eclipse.text.edits.TextEdit[] getPreviewEdits(org.eclipse.text.edits.TextEdit[] originals)
          Returns the edits that were executed during preview generation instead of the given array of original edits.
private  org.eclipse.jface.text.IRegion getRegion(TextEditChangeGroup[] changes)
           
 TextEditChangeGroup[] getTextEditChangeGroups()
          Returns the text edit change groups managed by this text change.
 java.lang.String getTextType()
          Returns the text change's text type.
private  org.eclipse.text.edits.TextEdit[] mapEdits(org.eclipse.text.edits.TextEdit[] edits, org.eclipse.text.edits.TextEditCopier copier)
           
 Change perform(org.eclipse.core.runtime.IProgressMonitor pm)
          null
protected abstract  void releaseDocument(org.eclipse.jface.text.IDocument document, org.eclipse.core.runtime.IProgressMonitor pm)
          Releases the document acquired via a call to aquireDocument 55 .
 void setEdit(org.eclipse.text.edits.TextEdit edit)
          Sets the root text edit that should be applied to the document represented by this text change.
 void setEnabled(boolean enabled)
          null
 void setKeepPreviewEdits(boolean keep)
          Controls whether the text change should keep executed edits during preview generation.
 void setTextType(java.lang.String type)
          Sets the text type.
 
Methods inherited from class org.eclipse.ltk.core.refactoring.Change
dispose, getAdapter, getModifiedElement, getParent, initializeValidationData, isEnabled, isValid, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fName

private java.lang.String fName

fTextEditChangeGroups

private java.util.List fTextEditChangeGroups

fCopier

private org.eclipse.text.edits.TextEditCopier fCopier

fEdit

private org.eclipse.text.edits.TextEdit fEdit

fTrackEdits

private boolean fTrackEdits

fTextType

private java.lang.String fTextType

ALL_EDITS

private static final TextEditChangeGroup[] ALL_EDITS
A special object denoting all edits managed by the text change. This even includes those edits not managed by a TextEditChangeGroup

Constructor Detail

TextChange

protected TextChange(java.lang.String name)
Creates a new text change with the specified name. The name is a human-readable value that is displayed to users. The name does not need to be unique, but it must not be null.

The text type of this text change is set to txt.

Method Detail

getName

public java.lang.String getName()
null

Specified by:
getName in class Change

setEnabled

public void setEnabled(boolean enabled)
null

Overrides:
setEnabled in class Change

setTextType

public void setTextType(java.lang.String type)
Sets the text type. The text type is used to determine the content merge viewer used to present the difference between the original and the preview content in the user interface. Content merge viewers are defined via the extension point org.eclipse.compare.contentMergeViewers.

The default text type is txt.


getTextType

public java.lang.String getTextType()
Returns the text change's text type.


setEdit

public void setEdit(org.eclipse.text.edits.TextEdit edit)
Sets the root text edit that should be applied to the document represented by this text change.


getEdit

public org.eclipse.text.edits.TextEdit getEdit()
Returns the root text edit.


addTextEditGroup

public void addTextEditGroup(org.eclipse.text.edits.TextEditGroup group)
Adds a text edit group. This method is a convenient method for calling change.addTextEditChangeGroup(new TextEditChangeGroup(change, group));.


addTextEditChangeGroup

public void addTextEditChangeGroup(TextEditChangeGroup group)
Adds a text edit change group. Calling the methods requires that a root edit has been set via the method setEdit 55 . The edits managed by the given text edit change group must be part of the change's root edit.


getTextEditChangeGroups

public TextEditChangeGroup[] getTextEditChangeGroups()
Returns the text edit change groups managed by this text change.


acquireDocument

protected abstract org.eclipse.jface.text.IDocument acquireDocument(org.eclipse.core.runtime.IProgressMonitor pm)
                                                             throws org.eclipse.core.runtime.CoreException
Acquires 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 releaseDocument(IDocument, IProgressMonitor) 55 .

The method releaseDocument must be call as many times as aquireDocument has been called.


commit

protected abstract void commit(org.eclipse.jface.text.IDocument document,
                               org.eclipse.core.runtime.IProgressMonitor pm)
                        throws org.eclipse.core.runtime.CoreException
Commits the document acquired via a call to aquireDocument 55 . 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.


releaseDocument

protected abstract void releaseDocument(org.eclipse.jface.text.IDocument document,
                                        org.eclipse.core.runtime.IProgressMonitor pm)
                                 throws org.eclipse.core.runtime.CoreException
Releases the document acquired via a call to aquireDocument 55 .


createUndoChange

protected abstract Change createUndoChange(org.eclipse.text.edits.UndoEdit edit)
Hook 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.


perform

public Change perform(org.eclipse.core.runtime.IProgressMonitor pm)
               throws org.eclipse.core.runtime.CoreException
null

Specified by:
perform in class Change

getCurrentDocument

public org.eclipse.jface.text.IDocument getCurrentDocument(org.eclipse.core.runtime.IProgressMonitor pm)
                                                    throws org.eclipse.core.runtime.CoreException
Returns the document this text change is associated to. The document returned is computed at the point in time when this method is called. So calling this method multiple times may return different document instances.

The returned document must not be modified by the client. Doing so will result in an unexpected behaviour when the change is performed.


getCurrentContent

public java.lang.String getCurrentContent(org.eclipse.core.runtime.IProgressMonitor pm)
                                   throws org.eclipse.core.runtime.CoreException
Returns the current content of the document this text change is associated with.


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
Returns the current content of the text change clipped to a specific region. The region is determined as follows:
  • if expandRegionToFullLine is false then the parameter region determines the clipping.
  • if expandRegionToFullLine is true then the region determined by the parameter region is extended to cover full lines.
  • if surroundingLines > 0 then the given number of surrounding lines is added. The value of surroundingLines is only considered if expandRegionToFullLine is true


setKeepPreviewEdits

public void setKeepPreviewEdits(boolean keep)
Controls whether the text change should keep executed edits during preview generation.


getKeepPreviewEdits

public boolean getKeepPreviewEdits()
Returns whether preview edits are remembered for further region tracking or not.


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. The method requires that setKeepPreviewEdits is set to true and that a preview has been requested via one of the getPreview* methods.

The method returns null if the original isn't managed by this text change.


getPreviewEdits

public org.eclipse.text.edits.TextEdit[] getPreviewEdits(org.eclipse.text.edits.TextEdit[] originals)
Returns the edits that were executed during preview generation instead of the given array of original edits. The method requires that setKeepPreviewEdits is set to true and that a preview has been requested via one of the getPreview* methods.

The method returns an empty array if none of the original edits is managed by this text change.


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 the text change. The preview is computed by executing the all managed text edits. The method considers the active state of the added text edit change groups.


getPreviewContent

public java.lang.String getPreviewContent(org.eclipse.core.runtime.IProgressMonitor pm)
                                   throws org.eclipse.core.runtime.CoreException
Returns the preview content as a string. This is a convenient method for calling getPreviewDocument(IProgressMonitor).get().


getPreviewContent

public java.lang.String getPreviewContent(TextEditChangeGroup[] changeGroups,
                                          org.eclipse.jface.text.IRegion region,
                                          boolean expandRegionToFullLine,
                                          int surroundingLines,
                                          org.eclipse.core.runtime.IProgressMonitor pm)
                                   throws org.eclipse.core.runtime.CoreException
Returns a preview of the text change clipped to a specific region. The preview is created by applying the text edits managed by the given array of text edit change groups. The region is determined as follows:
  • if expandRegionToFullLine is false then the parameter region determines the clipping.
  • if expandRegionToFullLine is true then the region determined by the parameter region is extended to cover full lines.
  • if surroundingLines > 0 then the given number of surrounding lines is added. The value of surroundingLines is only considered if expandRegionToFullLine is true


getPreviewDocument

private TextChange.PreviewAndRegion getPreviewDocument(TextEditChangeGroup[] changes,
                                                       org.eclipse.core.runtime.IProgressMonitor pm)
                                                throws org.eclipse.core.runtime.CoreException

createTextEditProcessor

private org.eclipse.text.edits.TextEditProcessor createTextEditProcessor(org.eclipse.jface.text.IDocument document,
                                                                         int flags,
                                                                         boolean preview)

createTextEditProcessor

private org.eclipse.text.edits.TextEditProcessor createTextEditProcessor(org.eclipse.jface.text.IDocument document,
                                                                         int flags,
                                                                         TextEditChangeGroup[] changes)

mapEdits

private org.eclipse.text.edits.TextEdit[] mapEdits(org.eclipse.text.edits.TextEdit[] edits,
                                                   org.eclipse.text.edits.TextEditCopier copier)

getContent

private java.lang.String getContent(org.eclipse.jface.text.IDocument document,
                                    org.eclipse.jface.text.IRegion region,
                                    boolean expandRegionToFullLine,
                                    int surroundingLines)
                             throws org.eclipse.core.runtime.CoreException

getRegion

private org.eclipse.jface.text.IRegion getRegion(TextEditChangeGroup[] changes)

getNewRegion

private org.eclipse.jface.text.IRegion getNewRegion(TextEditChangeGroup[] changes)