public Object getArrayItem(Object array,int index){ return null != accessor ? accessor.getArrayItem(array, index) : Array.get(array, index); }
public int getArrayLength(Object array){ return null != accessor ? accessor.getArrayLength(array) : Array.getLength(array); }
@SuppressWarnings("unchecked") public <T> T[] newArray(int length){ return null != accessor ? (T[])accessor.newArray(length) : (T[])Array.newInstance(this.clazz, length); }
public Object getValue(Object instance,boolean useGetter) { try { if(useGetter && null != getter){ if(getterAccessorIndex != -1){ return accessor.invokeMethod(instance, getterAccessorIndex, Arrays2.EMPTY_OBJECT_ARRAY); }else{ return getter.invoke(instance, Arrays2.EMPTY_OBJECT_ARRAY); } }else{ if(fieldAccessorIndex != -1){ return accessor.getFieldValue(instance, fieldAccessorIndex); }else { return field.get(instance); } } } catch (Throwable e) { if(e instanceof InvocationTargetException){ e = e.getCause(); } if(e instanceof RuntimeException){ throw (RuntimeException)e; } throw new ReflectException(Strings.format("Error getting value of field '{0}'",getName()),e); } }
@SuppressWarnings("unchecked") public <T> T newInstance() throws ReflectException{ if(null == defaultConstructor){ throw new ReflectException(Strings.format("there is no default constructor available in class '{0}'",getName())); } if(defaultConstructorInner){ return (T)defaultConstructor.newInstance(Reflection.newInstance(clazz.getEnclosingClass())); }else{ if(null != accessor && accessor.canNewInstance()){ return (T)accessor.newInstance(); }else{ return (T)defaultConstructor.newInstance((Object[])null); } } }
protected ReflectField(ReflectClass reflectiveClass, Field field){ super(reflectiveClass,field); this.field = field; this.type = field.getType(); this.setter = findSetter(); this.getter = findGetter(); this.accessor = reflectiveClass.getAccessor(); if(null != setter){ setter.setSetterOf(this); } if(null != getter){ getter.setGetterOf(this); } this.fieldAccessorIndex = null == accessor ? -1 : accessor.getFieldIndex(field); this.setterAccessorIndex = null == setter || null == accessor ? -1 : accessor.getMethodIndex(setter.getReflectedMethod()); this.getterAccessorIndex = null == getter || null == accessor ? -1 : accessor.getMethodIndex(getter.getReflectedMethod()); this.initialize(); }
public void setValue(Object instance, Object value, boolean useSetter) { try { if(field.isSynthetic() || isFinal()){ field.set(instance, safeValue(value)); }else{ if(useSetter && null != setter){ if(setterAccessorIndex != -1){ accessor.invokeMethod(instance, setterAccessorIndex, safeValue(value)); }else{ setter.invoke(instance, safeValue(value)); } }else{ if(fieldAccessorIndex != -1){ accessor.setFieldValue(instance, fieldAccessorIndex, safeValue(value)); }else{ field.set(instance, safeValue(value)); } } } } catch (Exception e) { throw new ReflectException(Strings.format("Error setting value '{0}' to field '{1}'",value,getName()),e); } }
public void setArrayItem(Object array,int index,Object value){ if(null != accessor) { accessor.setArrayItem(array, index, value); }else{ Array.set(array, index, value); } }
protected ReflectMethod(ReflectClass reflectClass,Method method) { super(reflectClass,method); this.accessor = reflectClass.getAccessor(); this.reflectedMethod = method; this.accessorIndex = accessor == null ? -1 : accessor.getMethodIndex(method); this.initialize(); }
return reflectClass.getAccessor().invokeMethod(instance, accessorIndex, args);