@@ -142,14 +142,27 @@ private static String noMethodReport(String methodName, Class contextClass, Obje
142142 + (contextClass != null ? " for " + contextClass : "" );
143143}
144144
145- private static Method matchMethod (List methods , Object [] args ) {
145+ private static Method matchMethod (List methods , Object [] args ) {
146+ return matchMethod (methods , args , null );
147+ }
148+ private static Method matchMethod (List methods , Object [] args , Class [] argTypes ) {
146149 Method foundm = null ;
147150 for (Iterator i = methods .iterator (); i .hasNext ();) {
148151 Method m = (Method ) i .next ();
152+ System .err .println ("Trying method: " + m );
149153 Class [] params = m .getParameterTypes ();
150- if (isCongruent (params , args ) && (foundm == null || Compiler .subsumes (params , foundm .getParameterTypes ())))
154+ System .err .print ("param classes: " );
155+ for (int p = 0 ; p < params .length ; p ++) {
156+ System .err .print (params [p ].toString ());
157+ }
158+ System .err .println ();
159+ System .err .println ("isCongruent: " + isCongruent (params , args ));
160+ if (foundm != null )
161+ System .err .println ("subsumes: " + Compiler .subsumes (params , foundm .getParameterTypes ()));
162+ if (isCongruent (params , args , argTypes ) && (foundm == null || Compiler .subsumes (params , foundm .getParameterTypes ())))
151163 foundm = m ;
152164 }
165+ System .err .println ("found method: " + foundm );
153166 return foundm ;
154167}
155168
@@ -175,7 +188,12 @@ public static Object invokeMatchingMethod(String methodName, List methods, Objec
175188 return invokeMatchingMethod (methodName , methods , target != null ? target .getClass () : null , target , args );
176189}
177190
178- static Object invokeMatchingMethod (String methodName , List methods , Class contextClass , Object target , Object [] args )
191+ static Object invokeMatchingMethod (String methodName , List methods , Class contextClass , Object target , Object [] args ) {
192+ return invokeMatchingMethod (methodName , methods , contextClass , target , args , null );
193+ }
194+
195+ /* PATCH: made public, added argTypes */
196+ public static Object invokeMatchingMethod (String methodName , List methods , Class contextClass , Object target , Object [] args , Class [] argTypes )
179197 {
180198 Method m = null ;
181199 if (methods .isEmpty ())
@@ -192,7 +210,7 @@ else if(methods.size() == 1)
192210 if (m == null ) // widen boxed args and re-try matchMethod
193211 {
194212 args = widenBoxedArgs (args );
195- m = matchMethod (methods , args );
213+ m = matchMethod (methods , args , argTypes );
196214 }
197215 }
198216 if (m == null )
@@ -209,6 +227,10 @@ else if(methods.size() == 1)
209227 }
210228 try
211229 {
230+ System .err .println ("retTYpe: " + m .getReturnType ());
231+ System .err .println ("ctxClass: " + contextClass );
232+ System .err .println ("meth: " + m );
233+ System .err .println ("boxedArgs " + boxArgs (m .getParameterTypes (), args ));
212234 return prepRet (m .getReturnType (), m .invoke (target , boxArgs (m .getParameterTypes (), args )));
213235 }
214236 catch (Exception e )
@@ -690,7 +712,11 @@ else if(paramType == boolean.class)
690712 return false ;
691713}
692714
693- static boolean isCongruent (Class [] params , Object [] args ){
715+ static boolean isCongruent (Class [] params , Object [] args ) {
716+ return isCongruent (params , args , null );
717+ }
718+
719+ static boolean isCongruent (Class [] params , Object [] args , Class [] argTypes ){
694720 boolean ret = false ;
695721 if (args == null )
696722 return params .length == 0 ;
@@ -699,8 +725,18 @@ static boolean isCongruent(Class[] params, Object[] args){
699725 ret = true ;
700726 for (int i = 0 ; ret && i < params .length ; i ++)
701727 {
702- Object arg = args [i ];
703- Class argType = (arg == null ) ? null : arg .getClass ();
728+ Class argType = null ;
729+ Object arg = args [i ];
730+ if (argTypes != null ) {
731+ Object t = argTypes [i ];
732+ if (t == null && arg != null ) {
733+ argType = arg .getClass ();
734+ } else {
735+ argType = argTypes [i ];
736+ }
737+ } else {
738+ argType = (arg == null ) ? null : arg .getClass ();
739+ }
704740 Class paramType = params [i ];
705741 ret = paramArgTypeMatch (paramType , argType );
706742 }
0 commit comments