private static <T> T valueOfType(AnnotationValue annotationValue, Class<T> type) {
    Object value = annotationValue.getValue();
    if (!type.isInstance(value)) {
      throw new IllegalArgumentException(
          "Expected " + type.getSimpleName() + ", got instead: " + value);
    }
    return type.cast(value);
  }
Returns the value as a VariableElement.

@throws IllegalArgumentException if the value is not an enum.
common/src/main/java/com/google/auto/common/AnnotationValues.java