1 package jfun.yan; 2 3 import jfun.yan.util.ReflectionUtil; 4 5 13 final class FieldBinder implements ComponentBinder { 14 public Verifiable verify(Class type) { 15 final Class expecting = fld.getField().getDeclaringClass(); 16 if(!ReflectionUtil.isAssignableFrom( 17 expecting, type) 18 ){ 19 throw new TypeMismatchException(expecting, type, 20 "type mismatch for invocation target"); 21 } 22 return Components.fun(Functions.field(null, fld.getField())); 23 } 24 public Creator bind(Object v){ 25 return Components.fun(Functions.field(v, fld.getField())); 26 } 27 public Class bindType(Class t){ 28 return fld.getField().getType(); 29 } 30 private final jfun.util.SerializableField fld; 31 FieldBinder(final java.lang.reflect.Field fld) { 32 this.fld = new jfun.util.SerializableField(fld); 33 } 34 35 public boolean equals(Object obj) { 36 if(obj instanceof FieldBinder){ 37 final FieldBinder other = (FieldBinder)obj; 38 return fld.equals(other.fld); 39 } 40 else return false; 41 } 42 public int hashCode() { 43 return fld.hashCode(); 44 } 45 public String toString() { 46 return fld.toString(); 47 } 48 } | Popular Tags |