void () { String text = "class A{{ return(Object)new String(); }}"; VirtualFile vFile = myFixture.addFileToProject("Test.java", text).getVirtualFile(); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); PsiJavaFile file = (PsiJavaFile)getPsiManager().findFile(vFile); PsiClass aClass = file.getClasses()[0]; PsiClassInitializer initializer = aClass.getInitializers()[0]; PsiStatement statement = initializer.getBody().getStatements()[0]; PsiTypeCastExpression typeCast = (PsiTypeCastExpression)((PsiReturnStatement)statement).getReturnValue(); typeCast.replace(typeCast.getOperand()); String textAfter = file.getText(); String expectedText = "class A{{ return new String(); }}"; assertEquals(expectedText, textAfter); }