int (int startLine) { Document document = myEditor.getDocument(); CharSequence text = document.getImmutableCharSequence(); int lineStartOffset = document.getLineStartOffset(startLine); int firstNonWsOffset = CharArrayUtil.shiftForward(text, lineStartOffset, " \t"); FileType type = PsiUtilBase.getPsiFileAtOffset(myFile, firstNonWsOffset).getFileType(); Language language = PsiUtilCore.getLanguageAtOffset(myFile, firstNonWsOffset); BraceMatcher braceMatcher = BraceMatchingUtil.getBraceMatcher(type, language); HighlighterIterator iterator = myEditor.getHighlighter().createIterator(firstNonWsOffset); if (braceMatcher.isLBraceToken(iterator, text, type)) { int codeConstructStart = braceMatcher.getCodeConstructStart(myFile, firstNonWsOffset); return document.getLineNumber(codeConstructStart); } else { return startLine; } }