void (@NotNull PsiStatement replacedStatement, @Nullable PsiStatement replacingStatement) { if (replacingStatement == null) { replacedStatement.delete(); return; } if (!(replacingStatement instanceof PsiBlockStatement blockStatement)) { replacedStatement.replace(replacingStatement); return; } final PsiCodeBlock codeBlock = blockStatement.getCodeBlock(); final PsiElement[] children = codeBlock.getChildren(); if (children.length > 2) { final PsiElement receiver = replacedStatement.getParent(); for (int i = children.length - 2; i > 0; i--) { final PsiElement child = children[i]; if (child instanceof PsiWhiteSpace) { continue; } receiver.addAfter(child, replacedStatement); } replacedStatement.delete(); } }