public static void createLoadsBasedOnDescriptor ( MethodVisitor mv , String descriptor , int startindex ) { int slot = startindex ; int descriptorpos = 1 ; // start after the '(' char ch ; while ( ( ch = descriptor . charAt ( descriptorpos ) ) != ' ' ) { switch ( ch ) { case ' ' : mv . visitVarInsn ( ALOAD , slot ) ; slot ++ ; // jump to end of array, could be [[[[I while ( descriptor . charAt ( ++ descriptorpos ) == ' ' ) { } if ( descriptor . charAt ( descriptorpos ) == ' ' ) { descriptorpos = descriptor . indexOf ( ' ' , descriptorpos ) + 1 ; } else { // Just a primitive array descriptorpos ++ ; } break ; case ' ' : mv . visitVarInsn ( ALOAD , slot ) ; slot ++ ; // jump to end of 'L' signature descriptorpos = descriptor . indexOf ( ' ' , descriptorpos ) + 1 ; break ; case ' ' : mv . visitVarInsn ( LLOAD , slot ) ; slot += 2 ; // double slotter descriptorpos ++ ; break ; case ' ' : mv . visitVarInsn ( DLOAD , slot ) ; slot += 2 ; // double slotter descriptorpos ++ ; break ; case ' ' : mv . visitVarInsn ( FLOAD , slot ) ; descriptorpos ++ ; slot ++ ; break ; case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : mv . visitVarInsn ( ILOAD , slot ) ; descriptorpos ++ ; slot ++ ; break ; default : throw new IllegalStateException ( "Unexpected type in descriptor: " + ch ) ; } } }
Create the set of LOAD instructions to load the method parameters . Take into account the size and type .