public TypeDescriptor get(TypeToken<?> typeToken) { try { return cache.get(typeToken, () -> new TypeDescriptor(this, typeToken)); } catch (Exception e) { throw new ReflectionException(Objects.toString(typeToken), e); } }
public Object newInstance(Object... args) { try { return constructor.newInstance(args); } catch (InstantiationException | InvocationTargetException | IllegalAccessException e) { throw new ReflectionException(toString(), e); } }
public Object get(Object obj) { try { return field.get(obj); } catch (IllegalAccessException e) { throw new ReflectionException(toString(), e); } }
public void set(Object obj, Object value) { try { field.set(obj, value); } catch (IllegalArgumentException | IllegalAccessException e) { throw new ReflectionException(toString(), e); } }
public Object invoke(Object object, Object... args) { try { return method.invoke(object, args); } catch (IllegalAccessException | InvocationTargetException e) { throw new ReflectionException(toString(), e); } }
public Object newInstance() { Constructor<?> constructor; try { constructor = getRawType().getDeclaredConstructor(); constructor.setAccessible(true); return constructor.newInstance(); } catch (Exception e) { throw new ReflectionException(toString(), e); } }
public Map<String, BeanProperty> getProperties() { try { ImmutableMap.Builder<String, BeanProperty> properties = ImmutableMap.builder(); BeanInfo beanInfo = Introspector.getBeanInfo(getRawType(), Object.class); for (PropertyDescriptor propertyDescriptor : beanInfo.getPropertyDescriptors()) { MethodDescriptor readMethod = getMethodDescriptor(propertyDescriptor.getReadMethod()); MethodDescriptor writeMethod = getMethodDescriptor(propertyDescriptor.getWriteMethod()); if (readMethod != null || writeMethod != null) { BeanProperty property = new BeanProperty(propertyDescriptor.getName(), readMethod, writeMethod); properties.put(property.getName(), property); } } return properties.build(); } catch (Exception e) { throw new ReflectionException(toString(), e); } }