public class DocumentImpl extends UserDataHolderBase implements DocumentEx
EMPTY_ARRAY, PROP_WRITABLE
Constructor and Description |
---|
DocumentImpl(java.lang.CharSequence chars) |
DocumentImpl(java.lang.CharSequence chars,
boolean forUseInNonAWTThread)
NOTE: if client sets forUseInNonAWTThread to true it's supposed that client will completely control document and its listeners.
|
DocumentImpl(java.lang.CharSequence chars,
boolean acceptSlashR,
boolean forUseInNonAWTThread) |
DocumentImpl(java.lang.String text) |
Modifier and Type | Method and Description |
---|---|
boolean |
acceptsSlashR() |
void |
addDocumentListener(DocumentListener listener)
Adds a listener for receiving notifications about changes in the document content.
|
void |
addDocumentListener(DocumentListener listener,
Disposable parentDisposable) |
void |
addEditReadOnlyListener(EditReadOnlyListener listener) |
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a listener for receiving notifications about changes in the properties of the document
(for example, its read-only state).
|
static boolean |
areRangeMarkersRetainedFor(VirtualFile f) |
void |
assertNotInBulkUpdate() |
void |
clearLineModificationFlags() |
void |
clearLineModificationFlags(int startLine,
int endLine) |
RangeMarker |
createGuardedBlock(int startOffset,
int endOffset)
Marks a range of text in the document as read-only (attempts to modify text in the
range cause
ReadOnlyFragmentModificationException to be thrown). |
LineIterator |
createLineIterator() |
RangeMarker |
createRangeMarker(int startOffset,
int endOffset,
boolean surviveOnExternalChange)
Creates a range marker which points to the specified range of text in the document and
is automatically adjusted when the document text is changed.
|
void |
deleteString(int startOffset,
int endOffset)
Deletes the specified range of text from the document.
|
void |
deleteString(int startOffset,
int endOffset,
int moveDstOffset) |
void |
documentCreatedFrom(VirtualFile f) |
void |
fireReadOnlyModificationAttempt()
Fires a notification that the user would like to remove the read-only state
from the document (the read-only state can be removed by checking the file out
from the version control system, or by clearing the read-only attribute on the file).
|
FrozenDocument |
freeze() |
java.lang.CharSequence |
getCharsSequence()
Use this method instead of
Document.getText() if you do not need to create a copy of the content. |
java.util.List<RangeMarker> |
getGuardedBlocks() |
java.lang.CharSequence |
getImmutableCharSequence() |
int |
getLineCount()
Returns the number of lines in the document.
|
int |
getLineEndOffset(int line)
Returns the end offset for the line with the specified number.
|
int |
getLineNumber(int offset)
Returns the line number (0-based) corresponding to the specified offset in the document.
|
int |
getLineSeparatorLength(int line) |
int |
getLineStartOffset(int line)
Returns the start offset for the line with the specified number.
|
int |
getModificationSequence() |
long |
getModificationStamp()
Gets the modification stamp value.
|
RangeMarker |
getOffsetGuard(int offset)
Returns the read-only marker covering the specified offset in the document.
|
RangeMarker |
getRangeGuard(int start,
int end)
Returns the read-only marker covering the specified range in the document.
|
java.lang.String |
getText()
Retrieves a copy of the document content.
|
java.lang.String |
getText(TextRange range) |
int |
getTextLength()
Returns the length of the document text.
|
void |
insertString(int offset,
java.lang.CharSequence s)
Inserts the specified text at the specified offset in the document.
|
boolean |
isInBulkUpdate() |
boolean |
isInEventsHandling() |
boolean |
isLineModified(int line) |
boolean |
isWritable()
Checks if the document text is read-only.
|
void |
moveText(int srcStart,
int srcEnd,
int dstOffset)
Moves text from the
[srcStart; srcEnd) range to the dstOffset offset. |
boolean |
processRangeMarkers(Processor<? super RangeMarker> processor)
Get all range markers
and hand them to the
processor in their RangeMarker.getStartOffset() order |
boolean |
processRangeMarkersOverlappingWith(int start,
int end,
Processor<? super RangeMarker> processor)
Get range markers which
TextRange.intersects(int, int) the specified range
and hand them to the processor in their RangeMarker.getStartOffset() order |
void |
registerRangeMarker(RangeMarkerEx rangeMarker,
int start,
int end,
boolean greedyToLeft,
boolean greedyToRight,
int layer) |
void |
removeDocumentListener(DocumentListener listener)
Removes a listener for receiving notifications about changes in the document content, previously added via
Document.addDocumentListener(DocumentListener) . |
void |
removeEditReadOnlyListener(EditReadOnlyListener listener) |
void |
removeGuardedBlock(RangeMarker block)
Removes a marker marking a range of text in the document as read-only.
|
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a listener for receiving notifications about changes in the properties of the document
(for example, its read-only state).
|
boolean |
removeRangeMarker(RangeMarkerEx rangeMarker) |
void |
replaceString(int startOffset,
int endOffset,
java.lang.CharSequence s)
Replaces the specified range of text in the document with the specified string.
|
void |
replaceString(int startOffset,
int endOffset,
java.lang.CharSequence s,
long newModificationStamp,
boolean wholeTextReplaced) |
void |
replaceText(java.lang.CharSequence chars,
long newModificationStamp) |
boolean |
setAcceptSlashR(boolean accept) |
void |
setCyclicBufferSize(int bufferSize)
Sets the maximum size of the cyclic buffer used for the document.
|
void |
setInBulkUpdate(boolean value)
Enters or exits 'bulk' mode for processing of document changes.
|
void |
setModificationStamp(long modificationStamp) |
void |
setReadOnly(boolean isReadOnly)
Marks the document as read-only or read/write.
|
void |
setStripTrailingSpacesEnabled(boolean isEnabled) |
void |
setText(java.lang.CharSequence text) |
void |
startGuardedBlockChecking()
Enables checking for read-only markers when the document is modified.
|
void |
stopGuardedBlockChecking()
Disables checking for read-only markers when the document is modified.
|
boolean |
stripTrailingSpaces(Project project) |
boolean |
stripTrailingSpaces(Project project,
boolean inChangedLinesOnly) |
void |
suppressGuardedExceptions() |
java.lang.String |
toString() |
void |
unSuppressGuardedExceptions() |
changeUserMap, clearUserData, clone, copyCopyableDataTo, copyUserDataTo, getCopyableUserData, getUserData, getUserDataString, getUserMap, isUserDataEmpty, putCopyableUserData, putUserData, putUserDataIfAbsent, replace, setUserMap
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
createRangeMarker, createRangeMarker, getChars
getUserData, putUserData
public DocumentImpl(java.lang.String text)
public DocumentImpl(java.lang.CharSequence chars)
public DocumentImpl(java.lang.CharSequence chars, boolean forUseInNonAWTThread)
public DocumentImpl(java.lang.CharSequence chars, boolean acceptSlashR, boolean forUseInNonAWTThread)
public void documentCreatedFrom(VirtualFile f)
public static boolean areRangeMarkersRetainedFor(VirtualFile f)
public boolean setAcceptSlashR(boolean accept)
public boolean acceptsSlashR()
public void setStripTrailingSpacesEnabled(boolean isEnabled)
setStripTrailingSpacesEnabled
in interface DocumentEx
public boolean stripTrailingSpaces(Project project)
public boolean stripTrailingSpaces(Project project, boolean inChangedLinesOnly)
public boolean isLineModified(int line)
isLineModified
in interface Document
public void setReadOnly(boolean isReadOnly)
Document
setReadOnly
in interface Document
isReadOnly
- the new value of the read-only flag.Document.isWritable()
,
Document.fireReadOnlyModificationAttempt()
public boolean isWritable()
Document
isWritable
in interface Document
true
if the document text is writable, false
if it is read-only.Document.fireReadOnlyModificationAttempt()
public boolean removeRangeMarker(RangeMarkerEx rangeMarker)
removeRangeMarker
in interface DocumentEx
public void registerRangeMarker(RangeMarkerEx rangeMarker, int start, int end, boolean greedyToLeft, boolean greedyToRight, int layer)
registerRangeMarker
in interface DocumentEx
public RangeMarker createGuardedBlock(int startOffset, int endOffset)
Document
ReadOnlyFragmentModificationException
to be thrown).createGuardedBlock
in interface Document
startOffset
- the start offset of the text range to mark as read-only.endOffset
- the end offset of the text range to mark as read-only.Document.removeGuardedBlock(RangeMarker)
,
Document.startGuardedBlockChecking()
,
EditorActionManager.setReadonlyFragmentModificationHandler(com.intellij.openapi.editor.actionSystem.ReadonlyFragmentModificationHandler)
public void removeGuardedBlock(RangeMarker block)
Document
removeGuardedBlock
in interface Document
block
- the marker to remove.Document.createGuardedBlock(int, int)
public java.util.List<RangeMarker> getGuardedBlocks()
getGuardedBlocks
in interface DocumentEx
public RangeMarker getOffsetGuard(int offset)
Document
getOffsetGuard
in interface Document
offset
- the offset for which the marker is requested.null
if the specified offset is not covered by a read-only marker.public RangeMarker getRangeGuard(int start, int end)
Document
getRangeGuard
in interface Document
start
- the start offset of the range for which the marker is requested.end
- the end offset of the range for which the marker is requested.null
if the specified range is not covered by a read-only marker.public void startGuardedBlockChecking()
Document
startGuardedBlockChecking
in interface Document
Document.createGuardedBlock(int, int)
,
Document.stopGuardedBlockChecking()
public void stopGuardedBlockChecking()
Document
stopGuardedBlockChecking
in interface Document
Document.createGuardedBlock(int, int)
,
Document.startGuardedBlockChecking()
public RangeMarker createRangeMarker(int startOffset, int endOffset, boolean surviveOnExternalChange)
Document
createRangeMarker
in interface Document
startOffset
- the start offset for the range of text covered by the marker.endOffset
- the end offset for the range of text covered by the marker.surviveOnExternalChange
- if true, the marker is not invalidated by external changes.public long getModificationStamp()
Document
getModificationStamp
in interface Document
PsiFile.getModificationStamp()
,
VirtualFile.getModificationStamp()
public void setModificationStamp(long modificationStamp)
setModificationStamp
in interface DocumentEx
public void replaceText(java.lang.CharSequence chars, long newModificationStamp)
replaceText
in interface DocumentEx
public void insertString(int offset, java.lang.CharSequence s)
Document
insertString
in interface Document
offset
- the offset to insert the text at.s
- the text to insert.public void deleteString(int startOffset, int endOffset)
Document
deleteString
in interface Document
startOffset
- the start offset of the range to delete.endOffset
- the end offset of the range to delete.public void deleteString(int startOffset, int endOffset, int moveDstOffset)
public void moveText(int srcStart, int srcEnd, int dstOffset)
DocumentEx
[srcStart; srcEnd)
range to the dstOffset
offset.
The benefit to use this method over usual Document.deleteString(int, int)
and Document.replaceString(int, int, CharSequence)
is that range markers
from the [srcStart; srcEnd)
range have
a chance to be preserved. Default implementation doesn't preserve range markers, but has the same effect in terms of resulting
text content.moveText
in interface DocumentEx
srcStart
- start offset of the text to move (inclusive)srcEnd
- end offset of the text to move (exclusive)dstOffset
- the offset to insert the text to. Must be outside of the (srcStart, srcEnd) range.public void replaceString(int startOffset, int endOffset, java.lang.CharSequence s)
Document
replaceString
in interface Document
startOffset
- the start offset of the range to replace.endOffset
- the end offset of the range to replace.s
- the text to replace with.public void replaceString(int startOffset, int endOffset, java.lang.CharSequence s, long newModificationStamp, boolean wholeTextReplaced)
public void suppressGuardedExceptions()
suppressGuardedExceptions
in interface DocumentEx
public void unSuppressGuardedExceptions()
unSuppressGuardedExceptions
in interface DocumentEx
public boolean isInEventsHandling()
isInEventsHandling
in interface DocumentEx
public void clearLineModificationFlags()
clearLineModificationFlags
in interface DocumentEx
public void clearLineModificationFlags(int startLine, int endLine)
public int getModificationSequence()
getModificationSequence
in interface DocumentEx
Document.getModificationStamp()
which can change arbitrarily.public java.lang.String getText()
Document
Document.getCharsSequence()
whenever it's possible.public java.lang.String getText(TextRange range)
public int getTextLength()
Document
getTextLength
in interface Document
Document.getCharsSequence()
public java.lang.CharSequence getCharsSequence()
Document
Document.getText()
if you do not need to create a copy of the content.
Content represented by returned CharSequence is subject to change whenever document is modified via delete/replace/insertString method
calls. It is necessary to obtain Application.runWriteAction() to modify content of the document though so threading issues won't
arise.getCharsSequence
in interface Document
Document.getTextLength()
public java.lang.CharSequence getImmutableCharSequence()
getImmutableCharSequence
in interface Document
ImmutableCharSequence
public void addDocumentListener(DocumentListener listener)
Document
addDocumentListener
in interface Document
listener
- the listener instance.public void addDocumentListener(DocumentListener listener, Disposable parentDisposable)
addDocumentListener
in interface Document
public void removeDocumentListener(DocumentListener listener)
Document
Document.addDocumentListener(DocumentListener)
.
Don't call this method for listeners added via Document.addDocumentListener(DocumentListener, Disposable)
, as that might cause memory leaks.removeDocumentListener
in interface Document
listener
- the listener instance.public int getLineNumber(int offset)
Document
getLineNumber
in interface Document
offset
- the offset to get the line number for (must be in the range from 0 to
getTextLength()-1)public LineIterator createLineIterator()
createLineIterator
in interface DocumentEx
public final int getLineStartOffset(int line)
Document
getLineStartOffset
in interface Document
line
- the line number (from 0 to getLineCount()-1)public final int getLineEndOffset(int line)
Document
getLineEndOffset
in interface Document
line
- the line number (from 0 to getLineCount()-1)public final int getLineSeparatorLength(int line)
getLineSeparatorLength
in interface Document
public final int getLineCount()
Document
getLineCount
in interface Document
public void fireReadOnlyModificationAttempt()
Document
fireReadOnlyModificationAttempt
in interface Document
public void addEditReadOnlyListener(EditReadOnlyListener listener)
addEditReadOnlyListener
in interface DocumentEx
public void removeEditReadOnlyListener(EditReadOnlyListener listener)
removeEditReadOnlyListener
in interface DocumentEx
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Document
addPropertyChangeListener
in interface Document
listener
- the listener instance.public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Document
removePropertyChangeListener
in interface Document
listener
- the listener instance.public void setCyclicBufferSize(int bufferSize)
Document
setCyclicBufferSize
in interface Document
bufferSize
- the cyclic buffer size, or 0 if the document should not use a cyclic buffer.public void setText(java.lang.CharSequence text)
public final boolean isInBulkUpdate()
isInBulkUpdate
in interface Document
Document.setInBulkUpdate(boolean)
public final void setInBulkUpdate(boolean value)
Document
As the reconciliation after exiting bulk mode implies some additional overhead, bulk mode shouldn't be used if the number of document changes to be performed is relatively small. The number of changes which justifies switching to bulk mode is usually determined empirically, but typically it's around hundred(s) of changes.
In bulk mode editor(s) associated with the document will stop updating internal caches on each document change. As a result, certain operations with editor can return invalid results or lead to exception, if they are preformed in bulk mode. They include: querying or updating folding or soft wrap data, editor position recalculation functions (offset to logical position, logical to visual position, etc), querying or updating caret position or selection state.
Bulk mode shouldn't span more than one thread or EDT event. Typically it should turned on/off in a try/finally statement.
setInBulkUpdate
in interface Document
DocumentUtil.executeInBulk(Document, boolean, Runnable)
,
BulkAwareDocumentListener
public boolean processRangeMarkers(Processor<? super RangeMarker> processor)
DocumentEx
processor
in their RangeMarker.getStartOffset()
orderprocessRangeMarkers
in interface DocumentEx
public boolean processRangeMarkersOverlappingWith(int start, int end, Processor<? super RangeMarker> processor)
DocumentEx
TextRange.intersects(int, int)
the specified range
and hand them to the processor
in their RangeMarker.getStartOffset()
orderprocessRangeMarkersOverlappingWith
in interface DocumentEx
public java.lang.String toString()
toString
in class java.lang.Object
public FrozenDocument freeze()
public void assertNotInBulkUpdate()