void (MoveInfo info, boolean down, PsiElement statement) { try { Document document = PsiDocumentManager.getInstance(statement.getProject()).getDocument(statement.getContainingFile()); assert document != null : statement.getContainingFile(); int startOffset = document.getLineStartOffset(info.toMove.startLine); int endOffset = getLineStartSafeOffset(document, info.toMove.endLine); if (document.getText().charAt(endOffset - 1) == '\n') endOffset--; RangeMarker lineRangeMarker = document.createRangeMarker(startOffset, endOffset); PsiElementFactory factory = JavaPsiFacade.getElementFactory(statement.getProject()); PsiCodeBlock codeBlock = factory.createCodeBlock(); codeBlock.add(statement); PsiBlockStatement blockStatement = (PsiBlockStatement)factory.createStatementFromText("{}", statement); blockStatement.getCodeBlock().replace(codeBlock); PsiBlockStatement newStatement = (PsiBlockStatement)statement.replace(blockStatement); newStatement = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(newStatement); info.toMove = new LineRange(document.getLineNumber(lineRangeMarker.getStartOffset()), document.getLineNumber(lineRangeMarker.getEndOffset())+1); PsiCodeBlock newCodeBlock = newStatement.getCodeBlock(); if (down) { PsiElement blockChild = firstNonWhiteElement(newCodeBlock.getFirstBodyElement(), true); if (blockChild == null) blockChild = newCodeBlock.getRBrace(); assert blockChild != null : newCodeBlock; info.toMove2 = new LineRange(info.toMove2.startLine, document.getLineNumber(blockChild.getTextRange().getStartOffset())); } else { PsiJavaToken brace = newCodeBlock.getRBrace(); assert brace != null : newCodeBlock; int start = document.getLineNumber(brace.getTextRange().getStartOffset()); int end = info.toMove.startLine; if (start > end) end = start; info.toMove2 = new LineRange(start, end); } } catch (IncorrectOperationException e) { LOG.error(e); } }