use of com.intellij.openapi.editor.impl.FrozenDocument in project intellij-community by JetBrains.
the class PsiDocumentManagerBase method getLastCommittedDocument.
@NotNull
public DocumentEx getLastCommittedDocument(@NotNull Document document) {
if (document instanceof FrozenDocument)
return (DocumentEx) document;
if (document instanceof DocumentWindow) {
DocumentWindow window = (DocumentWindow) document;
Document delegate = window.getDelegate();
if (delegate instanceof FrozenDocument)
return (DocumentEx) window;
if (!window.isValid()) {
throw new AssertionError("host committed: " + isCommitted(delegate) + ", window=" + window);
}
UncommittedInfo info = myUncommittedInfos.get(delegate);
DocumentWindow answer = info == null ? null : info.myFrozenWindows.get(document);
if (answer == null)
answer = freezeWindow(window);
if (info != null)
answer = ConcurrencyUtil.cacheOrGet(info.myFrozenWindows, window, answer);
return (DocumentEx) answer;
}
assert document instanceof DocumentImpl;
UncommittedInfo info = myUncommittedInfos.get(document);
return info != null ? info.myFrozen : ((DocumentImpl) document).freeze();
}
use of com.intellij.openapi.editor.impl.FrozenDocument in project intellij-community by JetBrains.
the class MarkerCache method applyEvents.
private static UpdatedRanges applyEvents(@NotNull List<DocumentEvent> events, final UpdatedRanges struct) {
FrozenDocument frozen = struct.myResultDocument;
ManualRangeMarker[] resultMarkers = struct.myMarkers.clone();
for (DocumentEvent event : events) {
final FrozenDocument before = frozen;
final DocumentEvent corrected;
if (event instanceof RetargetRangeMarkers) {
RetargetRangeMarkers retarget = (RetargetRangeMarkers) event;
corrected = new RetargetRangeMarkers(frozen, retarget.getStartOffset(), retarget.getEndOffset(), retarget.getMoveDestinationOffset());
} else {
corrected = new DocumentEventImpl(frozen, event.getOffset(), event.getOldFragment(), event.getNewFragment(), event.getOldTimeStamp(), event.isWholeTextReplaced(), ((DocumentEventImpl) event).getInitialStartOffset(), ((DocumentEventImpl) event).getInitialOldLength());
frozen = frozen.applyEvent(event, 0);
}
int i = 0;
while (i < resultMarkers.length) {
ManualRangeMarker currentRange = resultMarkers[i];
int sameMarkersEnd = i + 1;
while (sameMarkersEnd < resultMarkers.length && resultMarkers[sameMarkersEnd] == currentRange) {
sameMarkersEnd++;
}
ManualRangeMarker updatedRange = currentRange == null ? null : currentRange.getUpdatedRange(corrected, before);
while (i < sameMarkersEnd) {
resultMarkers[i] = updatedRange;
i++;
}
}
}
return new UpdatedRanges(struct.myEventCount + events.size(), frozen, struct.mySortedInfos, resultMarkers);
}
use of com.intellij.openapi.editor.impl.FrozenDocument in project intellij-community by JetBrains.
the class SelfElementInfo method getRange.
@Override
@Nullable
public Segment getRange() {
if (hasRange()) {
Document document = getDocumentToSynchronize();
if (document != null) {
PsiDocumentManagerBase documentManager = myManager.getPsiDocumentManager();
List<DocumentEvent> events = documentManager.getEventsSinceCommit(document);
if (!events.isEmpty()) {
SmartPointerTracker tracker = myManager.getTracker(getVirtualFile());
if (tracker != null) {
return tracker.getUpdatedRange(this, (FrozenDocument) documentManager.getLastCommittedDocument(document), events);
}
}
}
}
return calcPsiRange();
}
Aggregations