boolean (PsiFile file, Editor editor, LineRange range, MoveInfo info, boolean down) { int destLine = getDestLineForAnonymous(editor, range, down); int startLine = down ? range.endLine : range.startLine - 1; if (destLine < 0 || startLine < 0) return false; while (true) { int offset = editor.logicalPositionToOffset(new LogicalPosition(destLine, 0)); PsiElement element = firstNonWhiteElement(offset, file, true); while (element != null && !(element instanceof PsiFile)) { TextRange elementTextRange = element.getTextRange(); if (elementTextRange.isEmpty() || !elementTextRange.grown(-1).shiftRight(1).contains(offset)) { PsiElement elementToSurround = null; boolean found = false; if ((element instanceof PsiStatement || element instanceof PsiComment) && statementCanBePlacedAlong(element)) { found = true; if (!(statementsCanBeMovedWithin(element.getParent()))) { elementToSurround = element; } } else if (PsiUtil.isJavaToken(element, JavaTokenType.RBRACE) && statementsCanBeMovedWithin(element.getParent())) { // before code block closing brace found = true; } if (found) { STATEMENT_TO_SURROUND_WITH_CODE_BLOCK_KEY.set(info, elementToSurround); info.toMove = range; int endLine = destLine; if (startLine > endLine) { int tmp = endLine; endLine = startLine; startLine = tmp; } info.toMove2 = down ? new LineRange(startLine, endLine) : new LineRange(startLine, endLine + 1); return true; } } element = element.getParent(); } destLine += down ? 1 : -1; if (destLine < 0 || destLine >= editor.getDocument().getLineCount()) { return false; } } }