예제 #1
0
  /**
   * Establishes the type bound:
   *
   * <ol>
   *   <li>{@code<? extends Number>}, returns Number
   *   <li>{@code<? super Number>}, returns Number
   *   <li>{@code<?>}, returns Object
   *   <li>{@code<T extends Number>, returns Number}
   * </ol>
   *
   * @param typeMirror the type to return the bound for
   * @return the bound for this parameter
   */
  public TypeMirror getTypeBound(TypeMirror typeMirror) {
    if (typeMirror.getKind() == TypeKind.WILDCARD) {
      WildcardType wildCardType = (WildcardType) typeMirror;
      if (wildCardType.getExtendsBound() != null) {
        return wildCardType.getExtendsBound();
      }

      if (wildCardType.getSuperBound() != null) {
        return wildCardType.getSuperBound();
      }

      String wildCardName = wildCardType.toString();
      if ("?".equals(wildCardName)) {
        return elementUtils.getTypeElement(Object.class.getCanonicalName()).asType();
      }
    } else if (typeMirror.getKind() == TypeKind.TYPEVAR) {
      TypeVariable typeVariableType = (TypeVariable) typeMirror;
      if (typeVariableType.getUpperBound() != null) {
        return typeVariableType.getUpperBound();
      }
      // Lowerbounds intentionally left out: Type variables otherwise have a lower bound of
      // NullType.
    }

    return typeMirror;
  }
예제 #2
0
 @Override
 public JsonType visitWildcard(WildcardType wildcardType, Void o) {
   throw new UnsupportedOperationException(wildcardType.toString());
 }