void (@NotNull Document document, @NotNull Object reason) { PsiFile psiFile = getCachedPsiFile(document); if (psiFile != null) { psiFile.accept(new PsiRecursiveElementWalkingVisitor() { @Override public void visitElement(@NotNull PsiElement element) { if (!element.isValid()) { throw new AssertionError("Commit to '" + psiFile.getVirtualFile() + "' has led to invalid element: " + element + "; Reason: '" + reason + "'"); } } }); } }