RangeMarker (@NotNull VirtualFile file, int offset, int startLine, int startCol, int endLine, int endCol, boolean persistent) { int estimatedLength = RangeMarkerImpl.estimateDocumentLength(file); offset = Math.min(offset, estimatedLength); RangeMarkerImpl marker = persistent ? new PersistentRangeMarker(file, offset, offset, startLine, startCol, endLine, endCol, estimatedLength, false) : new RangeMarkerImpl(file, offset, offset, estimatedLength, false); Key<Reference<RangeMarkerTree<RangeMarkerEx>>> key = persistent ? PERSISTENT_RANGE_MARKERS_KEY : RANGE_MARKERS_KEY; RangeMarkerTree<RangeMarkerEx> tree; while (true) { Reference<RangeMarkerTree<RangeMarkerEx>> oldRef = file.getUserData(key); tree = dereference(oldRef); if (tree != null) break; tree = new RangeMarkerTree<>(); RMTreeReference reference = new RMTreeReference(tree, file); if (file.replace(key, oldRef, reference)) break; } tree.addInterval(marker, offset, offset, false, false, false, 0); return marker; }