int (@NotNull Editor editor, @NotNull PsiFile file) { final EditorHighlighter highlighter = BraceHighlightingHandler.getLazyParsableHighlighterIfAny(file.getProject(), editor, file); final CharSequence text = editor.getDocument().getCharsSequence(); final HighlighterIterator iterator = highlighter.createIterator(editor.getCaretModel().getOffset()); final FileType fileType = iterator.atEnd() ? null : PsiUtilBase.getPsiFileAtOffset(file, iterator.getStart()).getFileType(); if (fileType == null) { return -1; } int unopenedBraces = 0; while (true) { if (BraceMatchingUtil.isRBraceToken(iterator, text, fileType)) { unopenedBraces++; } else if (BraceMatchingUtil.isLBraceToken(iterator, text, fileType)) { unopenedBraces--; } if (unopenedBraces < 0) { return iterator.getStart(); } if (iterator.getStart() == 0) { return -1; } iterator.retreat(); } }