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

java.lang.Object
  extended by org.eclipse.xtext.ui.editor.model.DocumentPartitioner
All Implemented Interfaces:
org.eclipse.jface.text.IDocumentPartitioner, org.eclipse.jface.text.IDocumentPartitionerExtension, org.eclipse.jface.text.IDocumentPartitionerExtension2, org.eclipse.jface.text.IDocumentPartitionerExtension3

public class DocumentPartitioner
extends java.lang.Object
implements org.eclipse.jface.text.IDocumentPartitioner, org.eclipse.jface.text.IDocumentPartitionerExtension, org.eclipse.jface.text.IDocumentPartitionerExtension2, org.eclipse.jface.text.IDocumentPartitionerExtension3

Initially copied from FastPartitioner in order to be able to fix documentChanged2(DocumentEvent)

Since:
2.2
Author:
Sebastian Zarnekow - Initial contribution and API

Field Summary
protected static boolean CHECK_CACHE_CONSISTENCY
          Debug option for cache consistency checking.
protected static java.lang.String CONTENT_TYPES_CATEGORY
          The position category this partitioner uses to store the document's partitioning information.
protected  org.eclipse.jface.text.DocumentRewriteSession fActiveRewriteSession
          The active document rewrite session.
protected  org.eclipse.jface.text.Position[] fCachedPositions
          The cached positions from our document, so we don't create a new array every time someone requests partition information.
protected  int fDeleteOffset
          The offset at which a partition has been deleted
protected  org.eclipse.jface.text.IDocument fDocument
          The partitioner's document
protected  int fEndOffset
          The offset at which the last changed partition ends
protected  boolean fIsInitialized
          Flag indicating whether this partitioner has been initialized.
protected  java.lang.String[] fLegalContentTypes
          The legal content types of this partitioner
protected  java.lang.String fPositionCategory
          The position category this partitioner uses to store the document's partitioning information.
protected  org.eclipse.jface.text.DefaultPositionUpdater fPositionUpdater
          The position updater used to for the default updating of partitions
protected  org.eclipse.jface.text.rules.IPartitionTokenScanner fScanner
          The partitioner's scanner
protected  int fStartOffset
          The offset at which the first changed partition starts
 
Constructor Summary
DocumentPartitioner(org.eclipse.jface.text.rules.IPartitionTokenScanner scanner, ITokenTypeToPartitionTypeMapper mapper)
           
DocumentPartitioner(org.eclipse.jface.text.rules.IPartitionTokenScanner scanner, java.lang.String[] legalContentTypes)
          Creates a new partitioner that uses the given scanner and may return partitions of the given legal content types.
 
Method Summary
protected  void checkInitialization()
          Calls initialize() if the receiver is not yet initialized.
protected  void clearPositionCache()
          Clears the position cache.
 org.eclipse.jface.text.ITypedRegion[] computePartitioning(int offset, int length)
           
 org.eclipse.jface.text.ITypedRegion[] computePartitioning(int offset, int length, boolean includeZeroLengthPartitions)
          
 void connect(org.eclipse.jface.text.IDocument document)
           
 void connect(org.eclipse.jface.text.IDocument document, boolean delayInitialization)
          
 void disconnect()
          
 void documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent e)
          
 boolean documentChanged(org.eclipse.jface.text.DocumentEvent e)
           
 org.eclipse.jface.text.IRegion documentChanged2(org.eclipse.jface.text.DocumentEvent e)
          
protected  org.eclipse.jface.text.TypedPosition findClosestPosition(int offset)
          Returns the position in the partitoner's position category which is close to the given offset.
protected  void flushRewriteSession()
          Flushes the active rewrite session.
 org.eclipse.jface.text.DocumentRewriteSession getActiveRewriteSession()
          
 java.lang.String getContentType(int offset)
          
 java.lang.String getContentType(int offset, boolean preferOpenPartitions)
          
 java.lang.String[] getLegalContentTypes()
          
 java.lang.String[] getManagingPositionCategories()
           
 org.eclipse.jface.text.ITypedRegion getPartition(int offset)
          
 org.eclipse.jface.text.ITypedRegion getPartition(int offset, boolean preferOpenPartitions)
          
protected  org.eclipse.jface.text.Position[] getPositions()
          Returns the partitioners positions.
protected  java.lang.String getTokenContentType(org.eclipse.jface.text.rules.IToken token)
          Returns a content type encoded in the given token.
protected  void initialize()
          Performs the initial partitioning of the partitioner's document.
protected  boolean isSupportedContentType(java.lang.String contentType)
          Returns whether the given type is one of the legal content types.
 void startRewriteSession(org.eclipse.jface.text.DocumentRewriteSession session)
           
 void stopRewriteSession(org.eclipse.jface.text.DocumentRewriteSession session)
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTENT_TYPES_CATEGORY

protected static final java.lang.String CONTENT_TYPES_CATEGORY
The position category this partitioner uses to store the document's partitioning information.

Since:
2.2
See Also:
Constant Field Values

fScanner

protected final org.eclipse.jface.text.rules.IPartitionTokenScanner fScanner
The partitioner's scanner

Since:
2.2

fLegalContentTypes

protected final java.lang.String[] fLegalContentTypes
The legal content types of this partitioner

Since:
2.2

fDocument

protected org.eclipse.jface.text.IDocument fDocument
The partitioner's document

Since:
2.2

fPositionUpdater

protected final org.eclipse.jface.text.DefaultPositionUpdater fPositionUpdater
The position updater used to for the default updating of partitions

Since:
2.2

fStartOffset

protected int fStartOffset
The offset at which the first changed partition starts

Since:
2.2

fEndOffset

protected int fEndOffset
The offset at which the last changed partition ends

Since:
2.2

fDeleteOffset

protected int fDeleteOffset
The offset at which a partition has been deleted

Since:
2.2

fPositionCategory

protected final java.lang.String fPositionCategory
The position category this partitioner uses to store the document's partitioning information.

Since:
2.2

fActiveRewriteSession

protected org.eclipse.jface.text.DocumentRewriteSession fActiveRewriteSession
The active document rewrite session.

Since:
2.2

fIsInitialized

protected boolean fIsInitialized
Flag indicating whether this partitioner has been initialized.

Since:
2.2

fCachedPositions

protected org.eclipse.jface.text.Position[] fCachedPositions
The cached positions from our document, so we don't create a new array every time someone requests partition information.

Since:
2.2

CHECK_CACHE_CONSISTENCY

protected static final boolean CHECK_CACHE_CONSISTENCY
Debug option for cache consistency checking.

Since:
2.2
Constructor Detail

DocumentPartitioner

public DocumentPartitioner(org.eclipse.jface.text.rules.IPartitionTokenScanner scanner,
                           java.lang.String[] legalContentTypes)
Creates a new partitioner that uses the given scanner and may return partitions of the given legal content types.

Parameters:
scanner - the scanner this partitioner is supposed to use
legalContentTypes - the legal content types of this partitioner
Since:
2.2

DocumentPartitioner

@Inject
public DocumentPartitioner(org.eclipse.jface.text.rules.IPartitionTokenScanner scanner,
                                  ITokenTypeToPartitionTypeMapper mapper)
Method Detail

getManagingPositionCategories

public java.lang.String[] getManagingPositionCategories()
Specified by:
getManagingPositionCategories in interface org.eclipse.jface.text.IDocumentPartitionerExtension2
Since:
2.2

connect

public final void connect(org.eclipse.jface.text.IDocument document)
Specified by:
connect in interface org.eclipse.jface.text.IDocumentPartitioner
Since:
2.2

connect

public void connect(org.eclipse.jface.text.IDocument document,
                    boolean delayInitialization)

May be extended by subclasses.

Specified by:
connect in interface org.eclipse.jface.text.IDocumentPartitionerExtension3
Since:
2.2

checkInitialization

protected final void checkInitialization()
Calls initialize() if the receiver is not yet initialized.

Since:
2.2

initialize

protected void initialize()
Performs the initial partitioning of the partitioner's document.

May be extended by subclasses.

Since:
2.2

disconnect

public void disconnect()

May be extended by subclasses.

Specified by:
disconnect in interface org.eclipse.jface.text.IDocumentPartitioner
Since:
2.2

documentAboutToBeChanged

public void documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent e)

May be extended by subclasses.

Specified by:
documentAboutToBeChanged in interface org.eclipse.jface.text.IDocumentPartitioner
Since:
2.2

documentChanged

public final boolean documentChanged(org.eclipse.jface.text.DocumentEvent e)
Specified by:
documentChanged in interface org.eclipse.jface.text.IDocumentPartitioner
Since:
2.2

documentChanged2

public org.eclipse.jface.text.IRegion documentChanged2(org.eclipse.jface.text.DocumentEvent e)

May be extended by subclasses.

Specified by:
documentChanged2 in interface org.eclipse.jface.text.IDocumentPartitionerExtension
Since:
2.2

findClosestPosition

protected org.eclipse.jface.text.TypedPosition findClosestPosition(int offset)
Returns the position in the partitoner's position category which is close to the given offset. This is, the position has either an offset which is the same as the given offset or an offset which is smaller than the given offset. This method profits from the knowledge that a partitioning is a ordered set of disjoint position.

May be extended or replaced by subclasses.

Parameters:
offset - the offset for which to search the closest position
Returns:
the closest position in the partitioner's category
Since:
2.2

getContentType

public java.lang.String getContentType(int offset)

May be replaced or extended by subclasses.

Specified by:
getContentType in interface org.eclipse.jface.text.IDocumentPartitioner
Since:
2.2

getPartition

public org.eclipse.jface.text.ITypedRegion getPartition(int offset)

May be replaced or extended by subclasses.

Specified by:
getPartition in interface org.eclipse.jface.text.IDocumentPartitioner
Since:
2.2

computePartitioning

public final org.eclipse.jface.text.ITypedRegion[] computePartitioning(int offset,
                                                                       int length)
Specified by:
computePartitioning in interface org.eclipse.jface.text.IDocumentPartitioner
Since:
2.2

getLegalContentTypes

public java.lang.String[] getLegalContentTypes()

May be replaced or extended by subclasses.

Specified by:
getLegalContentTypes in interface org.eclipse.jface.text.IDocumentPartitioner
Since:
2.2

isSupportedContentType

protected boolean isSupportedContentType(java.lang.String contentType)
Returns whether the given type is one of the legal content types.

May be extended by subclasses.

Parameters:
contentType - the content type to check
Returns:
true if the content type is a legal content type
Since:
2.2

getTokenContentType

protected java.lang.String getTokenContentType(org.eclipse.jface.text.rules.IToken token)
Returns a content type encoded in the given token. If the token's data is not null and a string it is assumed that it is the encoded content type.

May be replaced or extended by subclasses.

Parameters:
token - the token whose content type is to be determined
Returns:
the token's content type
Since:
2.2

getContentType

public java.lang.String getContentType(int offset,
                                       boolean preferOpenPartitions)

May be replaced or extended by subclasses.

Specified by:
getContentType in interface org.eclipse.jface.text.IDocumentPartitionerExtension2
Since:
2.2

getPartition

public org.eclipse.jface.text.ITypedRegion getPartition(int offset,
                                                        boolean preferOpenPartitions)

May be replaced or extended by subclasses.

Specified by:
getPartition in interface org.eclipse.jface.text.IDocumentPartitionerExtension2
Since:
2.2

computePartitioning

public org.eclipse.jface.text.ITypedRegion[] computePartitioning(int offset,
                                                                 int length,
                                                                 boolean includeZeroLengthPartitions)

May be replaced or extended by subclasses.

Specified by:
computePartitioning in interface org.eclipse.jface.text.IDocumentPartitionerExtension2
Since:
2.2

startRewriteSession

public void startRewriteSession(org.eclipse.jface.text.DocumentRewriteSession session)
                         throws java.lang.IllegalStateException
Specified by:
startRewriteSession in interface org.eclipse.jface.text.IDocumentPartitionerExtension3
Throws:
java.lang.IllegalStateException
Since:
2.2

stopRewriteSession

public void stopRewriteSession(org.eclipse.jface.text.DocumentRewriteSession session)

May be extended by subclasses.

Specified by:
stopRewriteSession in interface org.eclipse.jface.text.IDocumentPartitionerExtension3
Since:
2.2

getActiveRewriteSession

public org.eclipse.jface.text.DocumentRewriteSession getActiveRewriteSession()

May be extended by subclasses.

Specified by:
getActiveRewriteSession in interface org.eclipse.jface.text.IDocumentPartitionerExtension3
Since:
2.2

flushRewriteSession

protected final void flushRewriteSession()
Flushes the active rewrite session.

Since:
2.2

clearPositionCache

protected final void clearPositionCache()
Clears the position cache. Needs to be called whenever the positions have been updated.

Since:
2.2

getPositions

protected final org.eclipse.jface.text.Position[] getPositions()
                                                        throws org.eclipse.jface.text.BadPositionCategoryException
Returns the partitioners positions.

Returns:
the partitioners positions
Throws:
org.eclipse.jface.text.BadPositionCategoryException - if getting the positions from the document fails
Since:
2.2