void (Project project, Editor editor) { if (!(editor instanceof EditorImpl)) return; HighlighterIterator editorIterator = editor.getHighlighter().createIterator(0); EditorHighlighter freshHighlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter( project, editor.getVirtualFile()); freshHighlighter.setEditor((EditorImpl)editor); freshHighlighter.setText(editor.getDocument().getImmutableCharSequence()); HighlighterIterator freshIterator = freshHighlighter.createIterator(0); while (!editorIterator.atEnd() || !freshIterator.atEnd()) { if (editorIterator.atEnd() || freshIterator.atEnd() || editorIterator.getTokenType() != freshIterator.getTokenType() || editorIterator.getStart() != freshIterator.getStart() || editorIterator.getEnd() != freshIterator.getEnd()) { throw new IllegalStateException("Editor highlighter failed to update incrementally:\nFresh: " + dumpHighlighter(freshHighlighter) + "\nEditor: " + dumpHighlighter(editor.getHighlighter())); } editorIterator.advance(); freshIterator.advance(); } }