boolean (HighlighterIterator iterator) { IElementType tokenType = iterator.getTokenType(); int balance = 0; int count = 0; while(balance >= 0){ iterator.retreat(); count++; if (iterator.atEnd()) break; tokenType = iterator.getTokenType(); if (tokenType == XmlTokenType.XML_TAG_END || tokenType == XmlTokenType.XML_EMPTY_ELEMENT_END){ balance++; } else if (tokenType == XmlTokenType.XML_END_TAG_START || tokenType == XmlTokenType.XML_START_TAG_START){ balance--; } } while(count-- > 0) iterator.advance(); return tokenType == XmlTokenType.XML_END_TAG_START; }