void () { final VirtualFile file = getTempDir().createVirtualFile(".java"); final Document document = FileDocumentManager.getInstance().getDocument(file); assertNotNull(document); assertNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject()))); PsiManager psiManager = PsiManager.getInstance(getProject()); long count1 = getJavaTracker().getModificationCount(); PsiJavaFile psiFile = (PsiJavaFile)psiManager.findFile(file); WriteCommandAction.runWriteCommandAction(getProject(), () -> document.insertString(0, "class Foo {}")); assertEquals(count1, getJavaTracker().getModificationCount()); // no PSI changes yet //so the class should not exist assertNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject()))); assertSize(0, psiFile.getClasses()); assertEquals("", psiManager.findFile(file).getText()); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); assertFalse(count1 == getJavaTracker().getModificationCount()); assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject()))); assertEquals("class Foo {}", psiManager.findFile(file).getText()); assertEquals("class Foo {}", psiManager.findFile(file).getNode().getText()); assertSize(1, psiFile.getClasses()); }