void () { HighlightingMarkupGrave.runInEnabled(() -> { MyStoppableAnnotator annotator = new MyStoppableAnnotator(); DaemonRespondToChangesTest.useAnnotatorsIn(JavaFileType.INSTANCE.getLanguage(), new MyStoppableAnnotator[]{annotator}, () -> { @Language("JAVA") String text = """ class X { //XXX }"""; configureByText(JavaFileType.INSTANCE, text); assertEquals(MyStoppableAnnotator.SWEARING, assertOneElement(highlightErrors()).getDescription()); assertEquals("//XXX", assertOneElement(highlightErrors()).highlighter.getTextRange().substring(getFile().getText())); VirtualFile virtualFile = getFile().getVirtualFile(); closeEditorAndEnsureTheDocumentMarkupIsGced(virtualFile); annotator.allowToRun.set(false); // reload file editor, and check the stored highlighters are reloaded back and applied, before the highlighting (MyStoppableAnnotator in particular) is run try { TextEditor textEditor = openTextEditorForDaemonTest(myProject, virtualFile); assertNotNull(textEditor); Document document = textEditor.getEditor().getDocument(); MarkupModel markupModel = DocumentMarkupModel.forDocument(document, getProject(), true); CoroutineKt.executeSomeCoroutineTasksAndDispatchAllInvocationEvents(myProject); RangeHighlighter errorHighlighter = ContainerUtil.find(markupModel.getAllHighlighters(), h -> CodeInsightColors.ERRORS_ATTRIBUTES.equals(h.getTextAttributesKey())); assertNotNull(errorHighlighter); assertEquals("//XXX", errorHighlighter.getTextRange().substring(document.getText())); assertTrue(HighlightingMarkupGrave.isZombieMarkup(errorHighlighter)); } finally { annotator.allowToRun.set(true); } }); }); }