Example #1
0
  /**
   * Returns the resolved generic exception types thrown by {@code constructor}.
   *
   * @param methodOrConstructor a method or constructor defined by this or any supertype.
   * @since 2.0
   */
  public List<TypeLiteral<?>> getExceptionTypes(Member methodOrConstructor) {
    Type[] genericExceptionTypes;

    if (methodOrConstructor instanceof Method) {
      Method method = (Method) methodOrConstructor;
      Assert.checkArgument(
          method.getDeclaringClass().isAssignableFrom(rawType),
          "%s is not defined by a supertype of %s",
          method,
          type);
      genericExceptionTypes = method.getGenericExceptionTypes();

    } else if (methodOrConstructor instanceof Constructor) {
      Constructor<?> constructor = (Constructor<?>) methodOrConstructor;
      Assert.checkArgument(
          constructor.getDeclaringClass().isAssignableFrom(rawType),
          "%s does not construct a supertype of %s",
          constructor,
          type);
      genericExceptionTypes = constructor.getGenericExceptionTypes();

    } else {
      throw new IllegalArgumentException("Not a method or a constructor: " + methodOrConstructor);
    }

    return resolveAll(genericExceptionTypes);
  }
Example #2
0
 /**
  * Returns the resolved generic return type of {@code method}.
  *
  * @param method a method defined by this or any supertype.
  * @since 2.0
  */
 public TypeLiteral<?> getReturnType(Method method) {
   Assert.checkArgument(
       method.getDeclaringClass().isAssignableFrom(rawType),
       "%s is not defined by a supertype of %s",
       method,
       type);
   return resolve(method.getGenericReturnType());
 }
Example #3
0
 /**
  * Returns the resolved generic type of {@code field}.
  *
  * @param field a field defined by this or any superclass.
  * @since 2.0
  */
 public TypeLiteral<?> getFieldType(Field field) {
   Assert.checkArgument(
       field.getDeclaringClass().isAssignableFrom(rawType),
       "%s is not defined by a supertype of %s",
       field,
       type);
   return resolve(field.getGenericType());
 }
Example #4
0
 /**
  * Returns the generic form of {@code supertype}. For example, if this is {@code
  * ArrayList<String>}, this returns {@code Iterable<String>} given the input {@code
  * Iterable.class}.
  *
  * @param supertype a superclass of, or interface implemented by, this.
  * @since 2.0
  */
 public TypeLiteral<?> getSupertype(Class<?> supertype) {
   Assert.checkArgument(
       supertype.isAssignableFrom(rawType), "%s is not a supertype of %s", supertype, this.type);
   return resolve(MoreTypes.getGenericSupertype(type, rawType, supertype));
 }