void (PsiElement rBrace, AlignmentProvider alignments) { int leadingBraceCount = 0; PsiElement next; if (!isClosureContainLF(rBrace)) return; for (next = PsiUtil.getPreviousNonWhitespaceToken(rBrace); isClosureRBrace(next) && isClosureContainLF(next); next = PsiUtil.getPreviousNonWhitespaceToken(next)) { leadingBraceCount++; } PsiElement cur = rBrace; for (next = getNextNonWhitespaceToken(cur); isClosureRBrace(next); next = getNextNonWhitespaceToken(cur)) { cur = next; } for (; leadingBraceCount > 0; leadingBraceCount--) { cur = PsiUtil.getPreviousNonWhitespaceToken(cur); } PsiElement parent = cur.getParent(); LOG.assertTrue(parent instanceof GrClosableBlock); //search for start of the line cur = parent; if (cur.getParent() instanceof GrMethodCall call) { GrExpression invoked = call.getInvokedExpression(); if (invoked instanceof GrReferenceExpression && ((GrReferenceExpression)invoked).getReferenceNameElement() != null) { cur = ((GrReferenceExpression)invoked).getReferenceNameElement(); } else { cur = call; } } cur = PsiTreeUtil.getDeepestFirst(cur); while (!PsiUtil.isNewLine(next = PsiTreeUtil.prevLeaf(cur, true))) { if (next == null) break; if (next.getNode().getElementType() == TokenType.WHITE_SPACE && PsiTreeUtil.prevLeaf(next) == null) { break; //if cur is first word in the text, whitespace could be before it } cur = next; } int startOffset = cur.getTextRange().getStartOffset(); int endOffset = rBrace.getTextRange().getStartOffset(); if (rBrace.getContainingFile().getText().substring(startOffset, endOffset).indexOf('\n') < 0) { return; } while (true) { final PsiElement p = cur.getParent(); if (p != null && p.getTextOffset() == cur.getTextOffset()) { cur = p; } else { break; } } alignments.addPair(rBrace, cur, true); }