Package org.fest.reflect.exception

Examples of org.fest.reflect.exception.ReflectionError


   * Creates a new </code>{@link TypeRef}</code>.
   * @throws ReflectionError if the generic type of this reference is missing type parameter.
   */
  public TypeRef() {
    Type superclass = getClass().getGenericSuperclass();
    if (superclass instanceof Class) throw new ReflectionError("Missing type parameter.");
    Type type = ((ParameterizedType)superclass).getActualTypeArguments()[0];
    rawType = type instanceof Class<?> ? (Class<?>)type : (Class<?>) ((ParameterizedType) type).getRawType();
  }
View Full Code Here


      field = field(fieldName, target);
      if (field != null) break;
      target = target.getSuperclass();
    }
    if (field != null) return field;
    throw new ReflectionError(concat("Unable to find field ", quote(fieldName), " in ", declaringType.getName()));
  }
View Full Code Here

  private static ReflectionError incorrectFieldType(Field field, Class<?> actualType, Class<?> expectedType) {
    String fieldTypeName = field.getDeclaringClass().getName();
    String message = concat("The type of the field ", quote(field.getName()), " in ", fieldTypeName, " should be <",
        expectedType.getName(), "> but was <", actualType.getName(), ">");
    throw new ReflectionError(message);
  }
View Full Code Here

  public void set(T value) {
    try {
      setAccessible(field, true);
      field.set(target, value);
    } catch (Exception e) {
      throw new ReflectionError(concat("Unable to update the value in field ", quote(field.getName())), e);
    } finally {
      setAccessibleIgnoringExceptions(field, accessible);
    }
  }
View Full Code Here

  @SuppressWarnings("unchecked") public T get() {
    try {
      setAccessible(field, true);
      return (T) field.get(target);
    } catch (Exception e) {
      throw new ReflectionError(concat("Unable to obtain the value in field " + quote(field.getName())), e);
    } finally {
      setAccessibleIgnoringExceptions(field, accessible);
    }
  }
View Full Code Here

   */
  public Class<?> load() {
    try {
      return loadType();
    } catch (Exception e) {
      throw new ReflectionError(unableToLoadClassMessage(null), e);
    }
  }
View Full Code Here

  public <T> Class<? extends T> loadAs(Class<T> type) {
    if (type == null) throw new NullPointerException("The given type should not be null");
    try {
      return loadType().asSubclass(type);
    } catch (Exception e) {
      throw new ReflectionError(unableToLoadClassMessage(type), e);
    }
  }
View Full Code Here

      method = method(methodName, type, parameterTypes);
      if (method != null) break;
      type = type.getSuperclass();
    }
    if (method == null)
      throw new ReflectionError(concat("Unable to find method ", quote(methodName), " in ",
          targetType.getName(), " with parameter type(s) ", format(parameterTypes)));
    return method;
  }
View Full Code Here

    boolean accessible = method.isAccessible();
    try {
      makeAccessible(method);
      return (T) method.invoke(target, args);
    } catch (Exception e) {
      throw new ReflectionError(concat("Unable to invoke method ", quote(method.getName()), " with arguments ",
          format(args)), e);
    } finally {
      setAccessibleIgnoringExceptions(method, accessible);
    }
  }
View Full Code Here

  private java.lang.reflect.Constructor<T> constructor(Class<T> target, Class<?>... parameterTypes) {
    try {
      return target.getDeclaredConstructor(parameterTypes);
    } catch (Exception e) {
      throw new ReflectionError(concat("Unable to find constructor in type ", target.getName(),
          " with parameter types ", Arrays.toString(parameterTypes)), e);
    }
  }
View Full Code Here

TOP

Related Classes of org.fest.reflect.exception.ReflectionError

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.