public static MethodParameterPair getMethodParameterPairIgnoreCase ( Class objectClass , String methodName , Object [ ] parameters ) throws NoSuchMethodException { // set all values if ( parameters == null ) parameters = new Object [ 0 ] ; // set parameter classes Class [ ] parameterClasses = new Class [ parameters . length ] ; for ( int i = 0 ; i < parameters . length ; i ++ ) { parameterClasses [ i ] = parameters [ i ] . getClass ( ) ; } // search right method Method [ ] methods = null ; if ( lastClass != null && lastClass . equals ( objectClass ) ) { methods = lastMethods ; } else { methods = objectClass . getDeclaredMethods ( ) ; } lastClass = objectClass ; lastMethods = methods ; // Method[] methods=objectClass.getMethods(); // Method[] methods=objectClass.getDeclaredMethods(); // methods=objectClass.getDeclaredMethods(); for ( int mode = 0 ; mode < 2 ; mode ++ ) { outer : for ( int i = 0 ; i < methods . length ; i ++ ) { Method method = methods [ i ] ; // Same Name if ( method . getName ( ) . equalsIgnoreCase ( methodName ) ) { Class [ ] paramTrg = method . getParameterTypes ( ) ; // Same Parameter count if ( parameterClasses . length == paramTrg . length ) { // if(parameterClasses.length==0)return m; for ( int y = 0 ; y < parameterClasses . length ; y ++ ) { if ( mode == 0 && parameterClasses [ y ] != primitiveToWrapperType ( paramTrg [ y ] ) ) { continue outer ; } else if ( mode == 1 ) { Object o = compareClasses ( parameters [ y ] , paramTrg [ y ] ) ; if ( o == null ) { continue outer ; } parameters [ y ] = o ; parameterClasses [ y ] = o . getClass ( ) ; } // if(parameterClasses.length-1==y) return m; } return new MethodParameterPair ( method , parameters ) ; } } } } // Exeception String parameter = "" ; for ( int i = 0 ; i < parameterClasses . length ; i ++ ) { if ( i != 0 ) parameter += ", " ; parameter += parameterClasses [ i ] . getName ( ) ; } throw new NoSuchMethodException ( "method " + methodName + "(" + parameter + ") doesn't exist in class " + objectClass . getName ( ) ) ; }
search the matching method to defined Method Name also translate parameters for matching