HighlighterIterator (int startOffset) { return new HighlighterIterator(){ private final TextAttributesKey[] myKeys = new TextAttributesKey[]{myKey}; private int index = 0; @Override public TextAttributes getTextAttributes() { return myCachedAttributes; } @Override public TextAttributesKey @NotNull [] getTextAttributesKeys() { return myKeys; } @Override public int getStart() { return 0; } @Override public int getEnd() { return myTextLength; } @Override public void advance() { index++; } @Override public void retreat(){ index--; } @Override public boolean atEnd() { return index != 0; } @Override public @NotNull Document getDocument() { return myEditor.getDocument(); } @Override public IElementType getTokenType(){ return IElementType.find(IElementType.FIRST_TOKEN_INDEX); } }; }