public class FastPartitioner
extends java.lang.Object
IPartitionTokenScanner to scan the document and to determine the
document's partitioning. The tokens returned by the scanner must return the
partition type as their data. The partitioner remembers the document's
partitions in the document itself rather than maintaining its own data
structure.
To reduce array creations in IDocument#getPositions(String), the
positions get cached. The cache is cleared after updating the positions in
documentChanged2(DocumentEvent). Subclasses need to call
clearPositionCache() after modifying the partitioner's positions.
The cached positions may be accessed through getPositions().
IPartitionTokenScanner| Modifier and Type | Field and Description |
|---|---|
protected int |
fDeleteOffset
The offset at which a partition has been deleted
|
protected IDocument |
fDocument
The partitioner's document
|
protected int |
fEndOffset
The offset at which the last changed partition ends
|
protected java.lang.String[] |
fLegalContentTypes
The legal content types of this partitioner
|
protected DefaultPositionUpdater |
fPositionUpdater
The position updater used to for the default updating of partitions
|
protected int |
fPreviousDocumentLength
The document length before a document change occurred
|
protected IPartitionTokenScanner |
fScanner
The partitioner's scanner
|
protected int |
fStartOffset
The offset at which the first changed partition starts
|
| Constructor and Description |
|---|
FastPartitioner(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.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
checkInitialization()
Calls
initialize() if the receiver is not yet initialized. |
protected void |
clearPositionCache()
Clears the position cache.
|
ITypedRegion[] |
computePartitioning(int offset,
int length) |
ITypedRegion[] |
computePartitioning(int offset,
int length,
boolean includeZeroLengthPartitions)
May be replaced or extended by subclasses.
|
void |
connect(IDocument document) |
void |
connect(IDocument document,
boolean delayInitialization)
May be extended by subclasses.
|
void |
disconnect()
May be extended by subclasses.
|
void |
documentAboutToBeChanged(DocumentEvent e)
May be extended by subclasses.
|
boolean |
documentChanged(DocumentEvent e) |
IRegion |
documentChanged2(DocumentEvent e)
May be extended by subclasses.
|
protected 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.
|
DocumentRewriteSession |
getActiveRewriteSession()
May be extended by subclasses.
|
java.lang.String |
getContentType(int offset)
May be replaced or extended by subclasses.
|
java.lang.String |
getContentType(int offset,
boolean preferOpenPartitions)
May be replaced or extended by subclasses.
|
java.lang.String[] |
getLegalContentTypes()
May be replaced or extended by subclasses.
|
java.lang.String[] |
getManagingPositionCategories() |
ITypedRegion |
getPartition(int offset)
May be replaced or extended by subclasses.
|
ITypedRegion |
getPartition(int offset,
boolean preferOpenPartitions)
May be replaced or extended by subclasses.
|
protected Position[] |
getPositions()
Returns the partitioners positions.
|
protected java.lang.String |
getTokenContentType(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(DocumentRewriteSession session) |
void |
stopRewriteSession(DocumentRewriteSession session)
May be extended by subclasses.
|
protected final IPartitionTokenScanner fScanner
protected final java.lang.String[] fLegalContentTypes
protected IDocument fDocument
protected int fPreviousDocumentLength
protected final DefaultPositionUpdater fPositionUpdater
protected int fStartOffset
protected int fEndOffset
protected int fDeleteOffset
public FastPartitioner(IPartitionTokenScanner scanner, java.lang.String[] legalContentTypes)
scanner - the scanner this partitioner is supposed to uselegalContentTypes - the legal content types of this partitionerpublic java.lang.String[] getManagingPositionCategories()
public final void connect(IDocument document)
public void connect(IDocument document,
boolean delayInitialization)
May be extended by subclasses.
protected final void checkInitialization()
initialize() if the receiver is not yet initialized.protected void initialize()
May be extended by subclasses.
public void disconnect()
May be extended by subclasses.
public void documentAboutToBeChanged(DocumentEvent e)
May be extended by subclasses.
public final boolean documentChanged(DocumentEvent e)
public IRegion documentChanged2(DocumentEvent e)
May be extended by subclasses.
protected TypedPosition findClosestPosition(int offset)
May be extended or replaced by subclasses.
offset - the offset for which to search the closest positionpublic java.lang.String getContentType(int offset)
May be replaced or extended by subclasses.
public ITypedRegion getPartition(int offset)
May be replaced or extended by subclasses.
public final ITypedRegion[] computePartitioning(int offset,
int length)
public java.lang.String[] getLegalContentTypes()
May be replaced or extended by subclasses.
protected boolean isSupportedContentType(java.lang.String contentType)
May be extended by subclasses.
contentType - the content type to checktrue if the content type is a legal content typeprotected java.lang.String getTokenContentType(IToken token)
null and a string it is assumed that
it is the encoded content type.
May be replaced or extended by subclasses.
token - the token whose content type is to be determinedpublic java.lang.String getContentType(int offset,
boolean preferOpenPartitions)
May be replaced or extended by subclasses.
public ITypedRegion getPartition(int offset,
boolean preferOpenPartitions)
May be replaced or extended by subclasses.
public ITypedRegion[] computePartitioning(int offset,
int length,
boolean includeZeroLengthPartitions)
May be replaced or extended by subclasses.
public void startRewriteSession(DocumentRewriteSession session)
throws java.lang.IllegalStateException
java.lang.IllegalStateExceptionpublic void stopRewriteSession(DocumentRewriteSession session)
May be extended by subclasses.
public DocumentRewriteSession getActiveRewriteSession()
May be extended by subclasses.
protected final void flushRewriteSession()
protected final void clearPositionCache()
protected final Position[] getPositions()
throws BadPositionCategoryException
BadPositionCategoryException - if getting the positions from the
document fails