static boolean isOptional(TypeMirror type) {
    if (type.getKind() != TypeKind.DECLARED) {
      return false;
    }
    DeclaredType declaredType = MoreTypes.asDeclared(type);
    TypeElement typeElement = MoreElements.asType(declaredType.asElement());
    return OPTIONAL_CLASS_NAMES.contains(typeElement.getQualifiedName().toString())
        && typeElement.getTypeParameters().size() == declaredType.getTypeArguments().size();
  }
Returns an instance wrapping the given TypeMirror, or null if it is not any kind of Optional.

@param type the TypeMirror for the original optional type, for example {@code
    Optional<String>}.
value/src/main/java/com/google/auto/value/processor/Optionalish.java