void (@NotNull Map<com.intellij.lang.Language, MyRecordingAnnotator @NotNull []> annotatorsByLanguage, @NotNull Runnable runnable) { MyRecordingAnnotator.clearAll(); for (Map.Entry<com.intellij.lang.Language, MyRecordingAnnotator[]> entry : annotatorsByLanguage.entrySet()) { com.intellij.lang.Language language = entry.getKey(); MyRecordingAnnotator[] annotators = entry.getValue(); for (Annotator annotator : annotators) { LanguageAnnotators.INSTANCE.addExplicitExtension(language, annotator); } } try { for (Map.Entry<com.intellij.lang.Language, MyRecordingAnnotator[]> entry : annotatorsByLanguage.entrySet()) { com.intellij.lang.Language language = entry.getKey(); MyRecordingAnnotator[] annotators = entry.getValue(); List<Annotator> list = LanguageAnnotators.INSTANCE.allForLanguage(language); assertTrue(list.toString(), list.containsAll(Arrays.asList(annotators))); } runnable.run(); for (Map.Entry<com.intellij.lang.Language, MyRecordingAnnotator[]> entry : annotatorsByLanguage.entrySet()) { MyRecordingAnnotator[] annotators = entry.getValue(); for (MyRecordingAnnotator annotator : annotators) { assertTrue(annotator + " must have done something but didn't", annotator.didIDoIt()); } } } finally { for (Map.Entry<com.intellij.lang.Language, MyRecordingAnnotator[]> entry : annotatorsByLanguage.entrySet()) { com.intellij.lang.Language language = entry.getKey(); MyRecordingAnnotator[] annotators = entry.getValue(); for (int i = annotators.length - 1; i >= 0; i--) { Annotator annotator = annotators[i]; LanguageAnnotators.INSTANCE.removeExplicitExtension(language, annotator); } } } for (Map.Entry<com.intellij.lang.Language, MyRecordingAnnotator[]> entry : annotatorsByLanguage.entrySet()) { com.intellij.lang.Language language = entry.getKey(); MyRecordingAnnotator[] annotators = entry.getValue(); List<Annotator> list = LanguageAnnotators.INSTANCE.allForLanguage(language); for (Annotator annotator : annotators) { assertFalse(list.toString(), list.contains(annotator)); } } }