boolean (@NotNull CharSequence text, @NotNull Lexer lexer, @NotNull IElementType leftBrace, @NotNull IElementType rightBrace) { lexer.start(text); if (lexer.getTokenType() != leftBrace) return false; lexer.advance(); int balance = 1; while (true) { ProgressManager.checkCanceled(); IElementType type = lexer.getTokenType(); if (type == null) { //eof: checking balance return balance == 0; } if (balance == 0) { //the last brace is not the last token return false; } if (type == leftBrace) { balance++; } else if (type == rightBrace) { balance--; } lexer.advance(); } }