org.eclipse.xtext.ui.editor.model
Class XtextDocument

java.lang.Object
  extended by org.eclipse.jface.text.AbstractDocument
      extended by org.eclipse.jface.text.Document
          extended by org.eclipse.xtext.ui.editor.model.XtextDocument
All Implemented Interfaces:
org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocumentExtension, org.eclipse.jface.text.IDocumentExtension2, org.eclipse.jface.text.IDocumentExtension3, org.eclipse.jface.text.IDocumentExtension4, org.eclipse.jface.text.IRepairableDocument, org.eclipse.jface.text.IRepairableDocumentExtension, IXtextDocument, IReadAccess<XtextResource>, IWriteAccess<XtextResource>

public class XtextDocument
extends org.eclipse.jface.text.Document
implements IXtextDocument

Author:
Sven Efftinge - Initial contribution and API, Michael Clay, Jan Koehnlein

Nested Class Summary
protected  class XtextDocument.XtextDocumentLocker
           
 
Nested classes/interfaces inherited from interface org.eclipse.jface.text.IDocumentExtension
org.eclipse.jface.text.IDocumentExtension.IReplace
 
Field Summary
 
Fields inherited from interface org.eclipse.jface.text.IDocument
DEFAULT_CATEGORY, DEFAULT_CONTENT_TYPE
 
Fields inherited from interface org.eclipse.jface.text.IDocumentExtension3
DEFAULT_PARTITIONING
 
Fields inherited from interface org.eclipse.jface.text.IDocumentExtension4
UNKNOWN_MODIFICATION_STAMP
 
Constructor Summary
XtextDocument(DocumentTokenSource tokenSource, ITextEditComposer composer)
           
 
Method Summary
 void addModelListener(IXtextModelListener listener)
           
 void addPosition(org.eclipse.jface.text.Position position)
          Adds the position to the document's default position category.
 void addPosition(java.lang.String category, org.eclipse.jface.text.Position position)
          Adds the position to the specified position category of the document.
 void addXtextDocumentContentObserver(IXtextDocumentContentObserver observer)
           
 void checkAndUpdateAnnotations()
           
protected  XtextDocument.XtextDocumentLocker createDocumentLocker()
           
 void disposeInput()
           
protected  void ensureThatStateIsNotReturned(java.lang.Object exec, IUnitOfWork<?,XtextResource> uow)
           
protected  void fireDocumentChanged(org.eclipse.jface.text.DocumentEvent event)
          Updates the internal document structures and informs all document listeners if listener notification has been enabled.
<T> T
getAdapter(java.lang.Class<T> adapterType)
           
 org.eclipse.jface.text.IRegion getLastDamage()
           
 org.eclipse.jface.text.Position[] getPositions(java.lang.String category)
          Returns all positions of the given position category.
 org.eclipse.jface.text.Position[] getPositions(java.lang.String category, int offset, int length, boolean canStartBefore, boolean canEndAfter)
          Returns all positions of the given category that are inside the given region.
 java.lang.Iterable<ILexerTokenRegion> getTokens()
           
 org.eclipse.core.runtime.jobs.Job getValidationJob()
           
<T> T
internalModify(IUnitOfWork<T,XtextResource> work)
          Modifies the document's semantic model without reconciling the text nor the node model.
<T> T
modify(IUnitOfWork<T,XtextResource> work)
           
protected  void notifyModelListeners(XtextResource res)
           
<T> T
readOnly(IUnitOfWork<T,XtextResource> work)
           
 void removeModelListener(IXtextModelListener listener)
           
 void removePosition(org.eclipse.jface.text.Position position)
          Removes the given position from the document's default position category.
 void removePosition(java.lang.String category, org.eclipse.jface.text.Position position)
          Removes the given position from the specified position category.
 void removeXtextDocumentContentObserver(IXtextDocumentContentObserver observer)
           
 void setInput(XtextResource resource)
           
 void setValidationJob(org.eclipse.core.runtime.jobs.Job validationJob)
           
protected
<T> void
updateContentBeforeRead()
           
 
Methods inherited from class org.eclipse.jface.text.Document
isLineInformationRepairNeeded
 
Methods inherited from class org.eclipse.jface.text.AbstractDocument
acceptPostNotificationReplaces, addDocumentListener, addDocumentPartitioningListener, addDocumentRewriteSessionListener, addPositionCategory, addPositionUpdater, addPrenotifiedDocumentListener, checkStateOfPartitioner, completeInitialization, computeIndexInCategory, computeIndexInPositionList, computeIndexInPositionList, computeNumberOfLines, computePartitioning, computePartitioning, containsPosition, containsPositionCategory, doFireDocumentChanged, doFireDocumentChanged, doFireDocumentChanged2, fireDocumentAboutToBeChanged, fireDocumentPartitioningChanged, fireDocumentPartitioningChanged, fireDocumentPartitioningChanged, fireRewriteSessionChanged, get, get, getActiveRewriteSession, getChar, getContentType, getContentType, getDefaultLineDelimiter, getDocumentListeners, getDocumentManagedPositions, getDocumentPartitioner, getDocumentPartitioner, getDocumentPartitioningListeners, getLegalContentTypes, getLegalContentTypes, getLegalLineDelimiters, getLength, getLineDelimiter, getLineInformation, getLineInformationOfOffset, getLineLength, getLineOffset, getLineOfOffset, getModificationStamp, getNumberOfLines, getNumberOfLines, getPartition, getPartition, getPartitionings, getPositionCategories, getPositionUpdaters, getStore, getTracker, ignorePostNotificationReplaces, insertPositionUpdater, registerPostNotificationReplace, removeDocumentListener, removeDocumentPartitioningListener, removeDocumentRewriteSessionListener, removePositionCategory, removePositionUpdater, removePrenotifiedDocumentListener, repairLineInformation, replace, replace, resumeListenerNotification, resumePostNotificationProcessing, search, set, set, setDocumentPartitioner, setDocumentPartitioner, setInitialLineDelimiter, setLineTracker, setTextStore, startRewriteSession, startRewriteSessionOnPartitioners, startSequentialRewrite, stopListenerNotification, stopPostNotificationProcessing, stopRewriteSession, stopRewriteSessionOnPartitioners, stopSequentialRewrite, updateDocumentStructures, updatePositions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.jface.text.IDocument
addDocumentListener, addDocumentPartitioningListener, addPositionCategory, addPositionUpdater, addPrenotifiedDocumentListener, computeIndexInCategory, computeNumberOfLines, computePartitioning, containsPosition, containsPositionCategory, get, get, getChar, getContentType, getDocumentPartitioner, getLegalContentTypes, getLegalLineDelimiters, getLength, getLineDelimiter, getLineInformation, getLineInformationOfOffset, getLineLength, getLineOffset, getLineOfOffset, getNumberOfLines, getNumberOfLines, getPartition, getPositionCategories, getPositionUpdaters, insertPositionUpdater, removeDocumentListener, removeDocumentPartitioningListener, removePositionCategory, removePositionUpdater, removePrenotifiedDocumentListener, replace, search, set, setDocumentPartitioner
 
Methods inherited from interface org.eclipse.jface.text.IDocumentExtension3
computePartitioning, getContentType, getDocumentPartitioner, getLegalContentTypes, getPartition, getPartitionings, setDocumentPartitioner
 

Constructor Detail

XtextDocument

@Inject
public XtextDocument(DocumentTokenSource tokenSource,
                            ITextEditComposer composer)
Method Detail

setInput

public void setInput(XtextResource resource)

disposeInput

public void disposeInput()

createDocumentLocker

protected XtextDocument.XtextDocumentLocker createDocumentLocker()

readOnly

public <T> T readOnly(IUnitOfWork<T,XtextResource> work)
Specified by:
readOnly in interface IReadAccess<XtextResource>

modify

public <T> T modify(IUnitOfWork<T,XtextResource> work)
Specified by:
modify in interface IWriteAccess<XtextResource>

internalModify

public <T> T internalModify(IUnitOfWork<T,XtextResource> work)
Modifies the document's semantic model without reconciling the text nor the node model. For internal use only.


ensureThatStateIsNotReturned

protected void ensureThatStateIsNotReturned(java.lang.Object exec,
                                            IUnitOfWork<?,XtextResource> uow)

addModelListener

public void addModelListener(IXtextModelListener listener)
Specified by:
addModelListener in interface IXtextDocument

removeModelListener

public void removeModelListener(IXtextModelListener listener)
Specified by:
removeModelListener in interface IXtextDocument

notifyModelListeners

protected void notifyModelListeners(XtextResource res)

addXtextDocumentContentObserver

public void addXtextDocumentContentObserver(IXtextDocumentContentObserver observer)
Specified by:
addXtextDocumentContentObserver in interface IXtextDocument

removeXtextDocumentContentObserver

public void removeXtextDocumentContentObserver(IXtextDocumentContentObserver observer)
Specified by:
removeXtextDocumentContentObserver in interface IXtextDocument

updateContentBeforeRead

protected <T> void updateContentBeforeRead()

setValidationJob

public void setValidationJob(org.eclipse.core.runtime.jobs.Job validationJob)

getValidationJob

public org.eclipse.core.runtime.jobs.Job getValidationJob()

checkAndUpdateAnnotations

public void checkAndUpdateAnnotations()

getAdapter

public <T> T getAdapter(java.lang.Class<T> adapterType)
Specified by:
getAdapter in interface IXtextDocument

getPositions

public org.eclipse.jface.text.Position[] getPositions(java.lang.String category,
                                                      int offset,
                                                      int length,
                                                      boolean canStartBefore,
                                                      boolean canEndAfter)
                                               throws org.eclipse.jface.text.BadPositionCategoryException
Description copied from class: org.eclipse.jface.text.AbstractDocument
Returns all positions of the given category that are inside the given region.

Overrides:
getPositions in class org.eclipse.jface.text.AbstractDocument
Parameters:
category - the position category
offset - the start position of the region, must be >= 0
length - the length of the region, must be >= 0
canStartBefore - if true then positions are included which start before the region if they end at or after the regions start
canEndAfter - if true then positions are included which end after the region if they start at or before the regions end
Returns:
all positions inside the region of the given category
Throws:
org.eclipse.jface.text.BadPositionCategoryException - if category is undefined in this document

getPositions

public org.eclipse.jface.text.Position[] getPositions(java.lang.String category)
                                               throws org.eclipse.jface.text.BadPositionCategoryException
Description copied from interface: org.eclipse.jface.text.IDocument
Returns all positions of the given position category. The positions are ordered according to the category's order. Manipulating this list does not affect the document, but manipulating the position does affect the document.

Specified by:
getPositions in interface org.eclipse.jface.text.IDocument
Overrides:
getPositions in class org.eclipse.jface.text.AbstractDocument
Parameters:
category - the category
Returns:
the list of all positions
Throws:
org.eclipse.jface.text.BadPositionCategoryException - if category is undefined in this document

addPosition

public void addPosition(org.eclipse.jface.text.Position position)
                 throws org.eclipse.jface.text.BadLocationException
Description copied from interface: org.eclipse.jface.text.IDocument
Adds the position to the document's default position category. This is a convenience method for addPosition(DEFAULT_CATEGORY, position).

Specified by:
addPosition in interface org.eclipse.jface.text.IDocument
Overrides:
addPosition in class org.eclipse.jface.text.AbstractDocument
Parameters:
position - the position to be added
Throws:
org.eclipse.jface.text.BadLocationException - if position describes an invalid range in this document

addPosition

public void addPosition(java.lang.String category,
                        org.eclipse.jface.text.Position position)
                 throws org.eclipse.jface.text.BadLocationException,
                        org.eclipse.jface.text.BadPositionCategoryException
Description copied from interface: org.eclipse.jface.text.IDocument
Adds the position to the specified position category of the document. Positions may be added multiple times. The order of the category is maintained.

Note: The position is only updated on each change applied to the document if a IPositionUpdater has been registered that handles the given category.

Specified by:
addPosition in interface org.eclipse.jface.text.IDocument
Overrides:
addPosition in class org.eclipse.jface.text.AbstractDocument
Parameters:
category - the category to which to add
position - the position to be added
Throws:
org.eclipse.jface.text.BadLocationException - if position describes an invalid range in this document
org.eclipse.jface.text.BadPositionCategoryException - if the category is undefined in this document

removePosition

public void removePosition(org.eclipse.jface.text.Position position)
Description copied from interface: org.eclipse.jface.text.IDocument
Removes the given position from the document's default position category. This is a convenience method for removePosition(DEFAULT_CATEGORY, position).

Specified by:
removePosition in interface org.eclipse.jface.text.IDocument
Overrides:
removePosition in class org.eclipse.jface.text.AbstractDocument
Parameters:
position - the position to be removed

removePosition

public void removePosition(java.lang.String category,
                           org.eclipse.jface.text.Position position)
                    throws org.eclipse.jface.text.BadPositionCategoryException
Description copied from interface: org.eclipse.jface.text.IDocument
Removes the given position from the specified position category. If the position is not part of the specified category nothing happens. If the position has been added multiple times, only the first occurrence is deleted.

Specified by:
removePosition in interface org.eclipse.jface.text.IDocument
Overrides:
removePosition in class org.eclipse.jface.text.AbstractDocument
Parameters:
category - the category from which to delete
position - the position to be deleted
Throws:
org.eclipse.jface.text.BadPositionCategoryException - if category is undefined in this document

fireDocumentChanged

protected void fireDocumentChanged(org.eclipse.jface.text.DocumentEvent event)
Description copied from class: org.eclipse.jface.text.AbstractDocument
Updates the internal document structures and informs all document listeners if listener notification has been enabled. Otherwise it remembers the event to be sent to the listeners on resume.

Overrides:
fireDocumentChanged in class org.eclipse.jface.text.AbstractDocument
Parameters:
event - the document event to be sent out

getLastDamage

public org.eclipse.jface.text.IRegion getLastDamage()

getTokens

public java.lang.Iterable<ILexerTokenRegion> getTokens()