PsiConditionalExpression (@NotNull Project project, @NotNull String condition, @NotNull PsiExpression expression, @NotNull String defaultValue) { final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); final PsiElement parent = expression.getParent(); final PsiConditionalExpression conditionalExpression = (PsiConditionalExpression)factory.createExpressionFromText( condition + " ? " + expression.getText() + " : " + defaultValue, parent ); final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project); return (PsiConditionalExpression)expression.replace( codeStyleManager.reformat(conditionalExpression)); }