PsiStatement (PsiField field, PsiExpression initializerExpr, PsiElement context, final PsiClass parentClass) { try { @NonNls String pattern = "x=0;"; PsiManager psiManager = parentClass.getManager(); PsiElementFactory factory = JavaPsiFacade.getElementFactory(psiManager.getProject()); PsiExpressionStatement statement = (PsiExpressionStatement)factory.createStatementFromText(pattern, null); statement = (PsiExpressionStatement)CodeStyleManager.getInstance(psiManager.getProject()).reformat(statement); PsiAssignmentExpression expr = (PsiAssignmentExpression)statement.getExpression(); final PsiExpression rExpression = expr.getRExpression(); LOG.assertTrue(rExpression != null); rExpression.replace(initializerExpr); final PsiReferenceExpression fieldReference = RenameJavaMemberProcessor.createMemberReference(field, context); expr.getLExpression().replace(fieldReference); return statement; } catch (IncorrectOperationException e) { LOG.error(e); return null; } }