void (@NotNull TreeElement firstNew) { firstNew.rawRemoveUpToWithoutNotifications(null, false); CompositeElement p = getTreeParent(); TreeElement treeNext = getTreeNext(); firstNew.setTreePrev(this); setTreeNext(firstNew); while(true){ TreeElement n = firstNew.getTreeNext(); assert n != this : "Attempt to create cycle"; firstNew.setTreeParent(p); if(n == null) break; firstNew = n; } if(treeNext == null){ if(p != null){ firstNew.setTreeParent(p); p.setLastChildNode(firstNew); } } else{ firstNew.setTreeNext(treeNext); treeNext.setTreePrev(firstNew); } DebugUtil.checkTreeStructure(this); }