void () { try { PsiElement first = null; PsiElement last = null; for (PsiElement element : elements) { if (!element.isValid()) continue; if (first == null) { first = last = element; } else if (last.getNextSibling() == element) { last = element; } else { delete(first, last); first = last = element; } } if (first != null) { delete(first, last); } } finally { elements.clear(); } }