Eclipse JDT
Release 3.0

org.eclipse.ltk.core.refactoring
Class DocumentChange

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

public class DocumentChange
extends TextChange

A text change that operates directly on instances of 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.

Since:
3.0

Constructor Summary
DocumentChange(String name, org.eclipse.jface.text.IDocument document)
          Creates a new DocumentChange for the given IDocument.
 
Method Summary
protected  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. A document acquired by this call MUST be released via a call to TextChange.releaseDocument(IDocument, IProgressMonitor).

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

protected  void commit(org.eclipse.jface.text.IDocument document, org.eclipse.core.runtime.IProgressMonitor pm)
          Commits 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.
protected  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.
 Object getModifiedElement()
          Returns the element modified by this Change. The method may return null if the change isn't related to an element.
 void initializeValidationData(org.eclipse.core.runtime.IProgressMonitor pm)
          Hook method to initialize some internal state to provide an adequate answer for the isValid 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 when isValid is called.

 RefactoringStatus isValid(org.eclipse.core.runtime.IProgressMonitor pm)
          Verifies that this change object is still valid and can be executed by calling perform. If a refactoring status with a severity of RefactoringStatus.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.

protected  void releaseDocument(org.eclipse.jface.text.IDocument document, org.eclipse.core.runtime.IProgressMonitor pm)
          Releases the document acquired via a call to aquireDocument.
 
Methods inherited from class org.eclipse.ltk.core.refactoring.TextChange
addTextEditChangeGroup, addTextEditGroup, getCurrentContent, getCurrentContent, getCurrentDocument, getEdit, getKeepPreviewEdits, getName, getPreviewContent, getPreviewContent, getPreviewDocument, getPreviewEdit, getPreviewEdits, getTextEditChangeGroups, getTextType, perform, setEdit, setEnabled, setKeepPreviewEdits, setTextType
 
Methods inherited from class org.eclipse.ltk.core.refactoring.Change
dispose, getAdapter, getParent, isEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DocumentChange

public DocumentChange(String name,
                      org.eclipse.jface.text.IDocument document)
Creates a new DocumentChange for the given IDocument.

Parameters:
name - the change's name. Has to be a human readable name.
document - the document this change is working on
Method Detail

getModifiedElement

public Object getModifiedElement()
Returns the element modified by this Change. The method may return null if the change isn't related to an element.

Specified by:
getModifiedElement in class Change
Returns:
the element modified by this change

initializeValidationData

public void initializeValidationData(org.eclipse.core.runtime.IProgressMonitor pm)
Hook method to initialize some internal state to provide an adequate answer for the isValid 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:

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 when isValid is called.

Specified by:
initializeValidationData in class Change
Parameters:
pm - a progress monitor

isValid

public RefactoringStatus isValid(org.eclipse.core.runtime.IProgressMonitor pm)
                          throws org.eclipse.core.runtime.CoreException
Verifies that this change object is still valid and can be executed by calling perform. If a refactoring status with a severity of RefactoringStatus.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 class Change
Parameters:
pm - a progress monitor.
Returns:
a refactoring status describing the outcome of the validation check
Throws:
org.eclipse.core.runtime.CoreException - if an error occurred during validation check. The change is to be treated as invalid if an exception occurs

acquireDocument

protected 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 TextChange.releaseDocument(IDocument, IProgressMonitor).

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

Specified by:
acquireDocument in class TextChange
Parameters:
pm - a progress monitor
Returns:
a reference to the document to be changed
Throws:
org.eclipse.core.runtime.CoreException - if the document can't be acquired

commit

protected 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. 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.

Specified by:
commit in class TextChange
Parameters:
document - the document to commit
pm - a progress monitor
Throws:
org.eclipse.core.runtime.CoreException - if the document can't be committed

releaseDocument

protected 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.

Specified by:
releaseDocument in class TextChange
Parameters:
document - the document to release
pm - a progress monitor
Throws:
org.eclipse.core.runtime.CoreException - if the document can't be released

createUndoChange

protected 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.

Specified by:
createUndoChange in class TextChange
Parameters:
edit - the UndoEdit to create an undo change for
Returns:
the undo change or null if no undo change can be created. Returning null results in the fact that the whole change tree can't be undone. So returning null is only recommended if an exception occurred during creating the undo change.

Eclipse JDT
Release 3.0

Copyright (c) IBM Corp. and others 2000, 2004. All Rights Reserved.