1 8 9 15 package jfun.yan; 16 17 import jfun.yan.util.ReflectionUtil; 18 19 27 final class MethodBinder implements ComponentBinder { 28 public Verifiable verify(Class type) { 29 final Class expecting = mtd.getMethod().getDeclaringClass(); 30 if(!ReflectionUtil.isAssignableFrom( 31 expecting, type) 32 ){ 33 throw new TypeMismatchException(expecting, type, 34 "type mismatch for invocation target"); 35 } 36 return Components.fun(Functions.method(null, mtd.getMethod())); 37 } 38 public Creator bind(Object v){ 39 return Components.fun(Functions.method(v, mtd.getMethod())); 40 } 41 public Class bindType(Class t){ 42 return mtd.getMethod().getReturnType(); 43 } 44 private final jfun.util.SerializableMethod mtd; 45 MethodBinder(final java.lang.reflect.Method mtd) { 46 this.mtd = new jfun.util.SerializableMethod(mtd); 47 } 48 49 public boolean equals(Object obj) { 50 if(obj instanceof MethodBinder){ 51 final MethodBinder other = (MethodBinder)obj; 52 return mtd.equals(other.mtd); 53 } 54 else return false; 55 } 56 public int hashCode() { 57 return mtd.hashCode(); 58 } 59 public String toString() { 60 return mtd.toString(); 61 } 62 } 63 | Popular Tags |