private static boolean isOptionalTypeParameter(@Nullable PsiType type) {
      PsiClassType classType = tryCast(type, PsiClassType.class);
      if (classType == null) return false;
      if (classType.getParameterCount() != 1) return false;
      PsiType typeParameter = classType.getParameters()[0];
      PsiClass parameterClass = PsiUtil.resolveClassInClassTypeOnly(typeParameter);
      if (parameterClass == null) return false;
      return JAVA_UTIL_OPTIONAL.equals(parameterClass.getQualifiedName());
    }
private static boolean isOptionalTypeParameter(@Nullable PsiType type)