int (Document document, EditorHighlighter highlighter, int rangeStart, int rangeEnd) { LOG.assertTrue(0 <= rangeStart); LOG.assertTrue(rangeStart <= rangeEnd); LOG.assertTrue(rangeEnd <= document.getTextLength()); HighlighterIterator iterator = highlighter.createIterator(rangeStart); int balance = 0; while(!iterator.atEnd() && iterator.getStart() < rangeEnd){ IElementType tokenType = iterator.getTokenType(); if (tokenType == JavaTokenType.LPARENTH){ balance++; } else if (tokenType == JavaTokenType.RPARENTH){ balance--; } iterator.advance(); } return balance; }