void (@NotNull PsiElement element, @NotNull ActionContext context, @NotNull ModPsiUpdater updater) { if (PsiImplUtil.isWhiteSpaceOrNls(element)) { element = PsiTreeUtil.prevLeaf(element); } LOG.assertTrue(GeeseUtil.isClosureRBrace(element)); PsiFile file = element.getContainingFile(); Document document = file.getViewProvider().getDocument(); PsiElement first = null; PsiElement last = null; for (PsiElement cur = element; GeeseUtil.isClosureRBrace(cur); cur = getNext(cur)) { last = cur; } for (PsiElement cur = element; GeeseUtil.isClosureRBrace(cur); cur = getPrev(cur)) { first = cur; } LOG.assertTrue(first != null); LOG.assertTrue(last != null); RangeMarker rangeMarker = document.createRangeMarker(first.getTextRange().getStartOffset(), last.getTextRange().getEndOffset()); String text = document.getText(); for (PsiElement cur = getPrev(last); GeeseUtil.isClosureRBrace(cur); cur = getPrev(cur)) { int offset = last.getTextRange().getStartOffset(); if (!StringUtil.contains(text, cur.getTextRange().getEndOffset(), offset, '\n')) { document.insertString(offset, "\n"); } last = cur; } CodeStyleManager.getInstance(context.project()).reformatText(file, rangeMarker.getStartOffset(), rangeMarker.getEndOffset()); }