public static void addCorrectReturnInstruction ( MethodVisitor mv , ReturnType returnType , boolean createCast ) { if ( returnType . isPrimitive ( ) ) { char ch = returnType . descriptor . charAt ( 0 ) ; switch ( ch ) { case ' ' : // void is treated as a special primitive mv . visitInsn ( RETURN ) ; break ; case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : mv . visitInsn ( IRETURN ) ; break ; case ' ' : mv . visitInsn ( FRETURN ) ; break ; case ' ' : mv . visitInsn ( DRETURN ) ; break ; case ' ' : mv . visitInsn ( LRETURN ) ; break ; default : throw new IllegalArgumentException ( "Not supported for '" + ch + "'" ) ; } } else { // either array or reference type if ( GlobalConfiguration . assertsMode ) { // Must not end with a ';' unless it starts with a '[' if ( returnType . descriptor . endsWith ( ";" ) && ! returnType . descriptor . startsWith ( "[" ) ) { throw new IllegalArgumentException ( "Invalid signature of '" + returnType . descriptor + "'" ) ; } } if ( createCast ) { mv . visitTypeInsn ( CHECKCAST , returnType . descriptor ) ; } mv . visitInsn ( ARETURN ) ; } }
Depending on the signature of the return type add the appropriate instructions to the method visitor .