void (@NotNull VirtualFile f, @NotNull Key<Reference<RangeMarkerTree<RangeMarkerEx>>> key, @NotNull RangeMarkerTree<RangeMarkerEx> tree, int tabSize) { RMTreeReference freshRef = new RMTreeReference(tree, f); Reference<RangeMarkerTree<RangeMarkerEx>> oldRef; do { oldRef = f.getUserData(key); } while (!f.replace(key, oldRef, freshRef)); RangeMarkerTree<RangeMarkerEx> oldTree = dereference(oldRef); if (oldTree == null) { // no tree was saved in virtual file before (happens when a new document is created). // or the old tree got gc-ed, because no reachable markers retaining it are left alive. good riddance. return; } // Some old tree was saved in the virtual file. Have to transfer markers from there. oldTree.copyRangeMarkersTo(this, tabSize); }