ModCommand (@NotNull List<PsiModifierListOwner> listOwners, @NotNull List<String> annotationFQNs, @NotNull Processor<? super XmlTag> annotationTagProcessor) { if (listOwners.isEmpty()) return ModCommand.nop(); return ModCommand.psiUpdate(listOwners.get(0), (lo, updater) -> { List<XmlTag> tags = StreamEx.of(listOwners) .mapToEntry(this::findExternalAnnotationsXmlFiles) .removeValues(f -> f == null || f.isEmpty()) .flatMapKeyValue((owner, fileList) -> StreamEx.of(fileList) .cross(annotationFQNs) .flatMapKeyValue((file, annotationFQN) -> getTagsToProcess(file, owner, annotationFQN).stream())) .map(updater::getWritable) .toList(); Set<XmlFile> files = StreamEx.of(tags).map(t -> (XmlFile)t.getContainingFile()).toSet(); for (XmlTag tag : tags) { if (tag.isValid()) { annotationTagProcessor.process(tag); } } if (!IntentionPreviewUtils.isIntentionPreviewActive()) { // Avoid too big preview changes for (XmlFile file : files) { sortItems(file); } } }); }