void (final List<? extends T> toDelete) { Set<PsiFile> files = new HashSet<>(); for (final T t : toDelete) { final XmlElement element = t.getXmlElement(); if (element != null) { ContainerUtil.addIfNotNull(files, element.getContainingFile()); } } WriteCommandAction.writeCommandAction(getProject(), PsiUtilCore.toPsiFileArray(files)).run(() -> { for (final T t : toDelete) { if (t.isValid()) { t.undefine(); } } }); }