void (PsiElementFactory factory, PsiMethod constructor, PsiField field) { final PsiExpression initializer = field.getInitializer(); PsiExpression initializerCopy = (PsiExpression)initializer.copy(); final PsiCodeBlock body = constructor.getBody(); if (body != null) { try { String fieldName = field.getName(); final PsiReferenceExpression refExpr = (PsiReferenceExpression)factory.createExpressionFromText(fieldName, body); if (refExpr.resolve() != null) fieldName = "this." + fieldName; PsiExpressionStatement statement = (PsiExpressionStatement)factory.createStatementFromText(fieldName + "= y;", null); if (initializerCopy instanceof PsiArrayInitializerExpression) { PsiType type = initializer.getType(); PsiNewExpression newExpression = (PsiNewExpression)factory.createExpressionFromText("new " + type.getCanonicalText() + "{}", body); newExpression.getArrayInitializer().replace(initializerCopy); initializerCopy = newExpression; } ((PsiAssignmentExpression)statement.getExpression()).getRExpression().replace(initializerCopy); statement = (PsiExpressionStatement)CodeStyleManager.getInstance(field.getManager().getProject()).reformat(statement); body.add(statement); initializer.delete(); } catch (IncorrectOperationException e) { LOG.error(e); } } }