void () { PsiJavaFile file = (PsiJavaFile)myFixture.addFileToProject("A.java", "class A{\nA(){}\n}"); PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(getProject()); Document document = psiDocumentManager.getDocument(file); document.insertString(document.getTextLength(), " "); // insert a trailing space to strip psiDocumentManager.commitAllDocuments(); PsiClass aClass = file.getClasses()[0]; aClass.setName("B"); }