void () { String barStr = "class Bar {}"; PsiFile file = addFileToProject("Foo.java", "class Foo {{" + barStr + "}}"); JBIterable<PsiClass> barQuery = SyntaxTraverser.psiTraverser(file).filter(PsiClass.class).filter(o -> "Bar".equals(o.getName())); assertNotNull(barQuery.first()); Document document = PsiDocumentManager.getInstance(getProject()).getDocument(file); int index = document.getText().indexOf(barStr); long count1 = getJavaTracker().getModificationCount(); //WriteCommandAction.runWriteCommandAction(getProject(), () -> bar.delete()); WriteCommandAction.runWriteCommandAction(getProject(), () -> document.replaceString(index, index + barStr.length(), "")); PsiDocumentManager.getInstance(getProject()).commitDocument(document); assertNull(barQuery.first()); assertFalse(count1 == getJavaTracker().getModificationCount()); }