Package org.fest.reflect.exception

Examples of org.fest.reflect.exception.ReflectionError


    try {
      makeAccessible(constructor);
      T newInstance = constructor.newInstance(args);
      return newInstance;
    } catch (Exception e) {
      throw new ReflectionError("Unable to create a new object from the enclosed constructor", e);
    } finally {
      setAccessibleIgnoringExceptions(constructor, accessible);
    }
  }
View Full Code Here


    Class<?> targetType = target.getClass();
    try {
      beanInfo = Introspector.getBeanInfo(targetType);
    } catch (Throwable t) {
      String format = "Failed to get BeanInfo for type %s";
      throw new ReflectionError(String.format(format, targetType.getName()), t);
    }
    PropertyDescriptor found = null;
    for (PropertyDescriptor descriptor : beanInfo.getPropertyDescriptors()) {
      if (propertyName.equals(descriptor.getName())) {
        found = descriptor;
        break;
      }
    }
    if (found != null) {
      Class<?> actualType = found.getPropertyType();
      if (!propertyType.isAssignableFrom(actualType)) {
        String format = "Expecting type of property '%s' in %s to be <%s> but was <%s>";
        String msg =
            String.format(format, propertyName, targetType.getName(), propertyType.getName(), actualType.getName());
        throw new ReflectionError(msg);
      }
      return found;
    }
    String msg = String.format("Failed to find property '%s' in %s", propertyName, targetType.getName());
    throw new ReflectionError(msg);
  }
View Full Code Here

    try {
      descriptor.getWriteMethod().invoke(target, value);
    } catch (Exception e) {
      String format = "Failed to set value %s in property '%s'";
      String msg = String.format(format, String.valueOf(value), descriptor.getName());
      throw new ReflectionError(msg, e);
    }
  }
View Full Code Here

    try {
      Object value = descriptor.getReadMethod().invoke(target);
      return castSafely(value, propertyType);
    } catch (Throwable t) {
      String msg = String.format("Failed to get the value of property '%s'", descriptor.getName());
      throw new ReflectionError(msg, t);
    }
  }
View Full Code Here

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

      Throwable cause = targetOf(t);
      if (cause instanceof RuntimeException) {
        throw (RuntimeException) cause;
      }
      String format = "Unable to invoke method %s with arguments %s";
      throw new ReflectionError(String.format(format, quote(method.getName()), format(args)), cause);
    } finally {
      setAccessibleIgnoringExceptions(method, accessible);
    }
  }
View Full Code Here

        Class<?> actualType = field.getType();
        if (!fieldType.isAssignableFrom(actualType)) {
          String format = "Expecting type of field '%s' in %s to be <%s> but was <%s>";
          String msg =
              String.format(format, fieldName, originalType.getName(), fieldType.getName(), actualType.getName());
          throw new ReflectionError(msg);
        }
      } finally {
        setAccessibleIgnoringExceptions(field, isAccessible);
      }
      return field;
    }
    String format = "Failed to find field '%s' in %s";
    String msg = String.format(format, fieldName, originalType.getName());
    throw new ReflectionError(msg);
  }
View Full Code Here

      setAccessible(f, true);
      f.set(target, value);
    } catch (Throwable t) {
      String format = "Failed to set value %s in field '%s'";
      String msg = String.format(format, String.valueOf(value), f.getName());
      throw new ReflectionError(msg, t);
    } finally {
      setAccessibleIgnoringExceptions(f, accessible);
    }
  }
View Full Code Here

      setAccessible(f, true);
      Object value = f.get(target);
      return castSafely(value, checkNotNull(fieldType));
    } catch (Throwable t) {
      String msg = String.format("Failed to get the value of field '%s'", f.getName());
      throw new ReflectionError(msg, t);
    } finally {
      setAccessibleIgnoringExceptions(f, accessible);
    }
  }
View Full Code Here

   */
  @SuppressWarnings("unchecked")
  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<T>) type : (Class<T>) ((ParameterizedType) type).getRawType();
    checkNotNull(rawType);
  }
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.