PsiExpression (PsiExpression expression) { final Project project = expression.getProject(); final Nullability nullability = NullabilityUtil.getExpressionNullability(expression, true); String methodName = nullability == Nullability.NOT_NULL ? "of" : "ofNullable"; final String newExpressionText = CommonClassNames.JAVA_UTIL_OPTIONAL + "." + methodName + "(" + expression.getText() + ")"; return JavaPsiFacade.getElementFactory(project).createExpressionFromText(newExpressionText, expression); }