int (@NotNull final ScopeRange toMove2, @NotNull final MyLineRange toMove) { final PsiElement anchor = toMove2.getAnchor(); final PsiElement anchorCopy = anchor.copy(); PsiElement startToMove = toMove.myStartElement; final PsiElement endToMove = toMove.myEndElement; final PsiElement parent = anchor.getParent(); PsiElement tmp = startToMove.getNextSibling(); if (startToMove != endToMove && tmp != null) { parent.addRangeAfter(tmp, endToMove, anchor); } PsiElement startCopy = startToMove.copy(); startToMove.replace(anchorCopy); final PsiElement addedElement = anchor.replace(startCopy); if (startToMove != endToMove && tmp != null) { parent.deleteChildRange(tmp, endToMove); } return addedElement.getTextRange().getStartOffset(); }