1 package jfun.yan.xml.nut; 2 3 import java.lang.reflect.Method ; 4 import java.util.Arrays ; 5 import java.util.List ; 6 7 8 import jfun.util.Misc; 9 import jfun.util.typing.TypedSuite; 10 11 12 19 final class MethodSuite extends TypedSuite implements java.io.Serializable { 20 protected Object ambiguity(Object arg, Object candidate1, Object candidate2) { 21 final Method1 result = (Method1)candidate1; 22 final Method1 dup = (Method1)candidate2; 23 throw new IllegalArgumentException ("Ambiguous method: " 24 + result.getMethod().toString() + " and " 25 + dup.getMethod().toString()); 26 } 27 28 protected Class getType(Object candidate) { 29 return ((Method1)candidate).getParameterType(); 30 } 31 32 protected Object not_found(Object arg) { 33 throw new IllegalArgumentException ("Method " + name + " with parameter type " 34 + (arg==null?null:Misc.getTypeName(arg.getClass())) 35 +" cannot be found."); 36 } 37 public Method getMethod(Object arg){ 38 final Method1 result = (Method1)super.getCandidate(arg); 39 return result.getMethod(); 40 } 41 private final Method1[] methods; 42 145 protected List getCandidates(){ 146 return Arrays.asList(methods); 147 } 148 MethodSuite(final String name, Method1[] methods) { 149 this.methods = methods; 150 this.name = name; 151 } 152 private final String name; 153 } 154 | Popular Tags |