public static InsnList cast(final Type from,final Type to){
  InsnList list=new InsnList();
  if (from != to) {
    if (from == Type.DOUBLE_TYPE) {
      if (to == Type.FLOAT_TYPE) {
        list.add(new InsnNode(Opcodes.D2F));
      }
 else       if (to == Type.LONG_TYPE) {
        list.add(new InsnNode(Opcodes.D2L));
      }
 else {
        list.add(new InsnNode(Opcodes.D2I));
        list.add(cast(Type.INT_TYPE,to));
      }
    }
 else     if (from == Type.FLOAT_TYPE) {
      if (to == Type.DOUBLE_TYPE) {
        list.add(new InsnNode(Opcodes.F2D));
      }
 else       if (to == Type.LONG_TYPE) {
        list.add(new InsnNode(Opcodes.F2L));
      }
 else {
        list.add(new InsnNode(Opcodes.F2I));
        list.add(cast(Type.INT_TYPE,to));
      }
    }
 else     if (from == Type.LONG_TYPE) {
      if (to == Type.DOUBLE_TYPE) {
        list.add(new InsnNode(Opcodes.L2D));
      }
 else       if (to == Type.FLOAT_TYPE) {
        list.add(new InsnNode(Opcodes.L2F));
      }
 else {
        list.add(new InsnNode(Opcodes.L2I));
        list.add(cast(Type.INT_TYPE,to));
      }
    }
 else {
      if (to == Type.BYTE_TYPE) {
        list.add(new InsnNode(Opcodes.I2B));
      }
 else       if (to == Type.CHAR_TYPE) {
        list.add(new InsnNode(Opcodes.I2C));
      }
 else       if (to == Type.DOUBLE_TYPE) {
        list.add(new InsnNode(Opcodes.I2D));
      }
 else       if (to == Type.FLOAT_TYPE) {
        list.add(new InsnNode(Opcodes.I2F));
      }
 else       if (to == Type.LONG_TYPE) {
        list.add(new InsnNode(Opcodes.I2L));
      }
 else       if (to == Type.SHORT_TYPE) {
        list.add(new InsnNode(Opcodes.I2S));
      }
    }
  }
  return list;
}

public static InsnList cast ( final Type from , final Type to ) { InsnList list = new InsnList ( ) ; if ( from != to ) { if ( from == Type . DOUBLE_TYPE ) { if ( to == Type . FLOAT_TYPE ) { list . add ( new InsnNode ( Opcodes . D2F ) ) ; } else if ( to == Type . LONG_TYPE ) { list . add ( new InsnNode ( Opcodes . D2L ) ) ; } else { list . add ( new InsnNode ( Opcodes . D2I ) ) ; list . add ( cast ( Type . INT_TYPE , to ) ) ; } } else if ( from == Type . FLOAT_TYPE ) { if ( to == Type . DOUBLE_TYPE ) { list . add ( new InsnNode ( Opcodes . F2D ) ) ; } else if ( to == Type . LONG_TYPE ) { list . add ( new InsnNode ( Opcodes . F2L ) ) ; } else { list . add ( new InsnNode ( Opcodes . F2I ) ) ; list . add ( cast ( Type . INT_TYPE , to ) ) ; } } else if ( from == Type . LONG_TYPE ) { if ( to == Type . DOUBLE_TYPE ) { list . add ( new InsnNode ( Opcodes . L2D ) ) ; } else if ( to == Type . FLOAT_TYPE ) { list . add ( new InsnNode ( Opcodes . L2F ) ) ; } else { list . add ( new InsnNode ( Opcodes . L2I ) ) ; list . add ( cast ( Type . INT_TYPE , to ) ) ; } } else { if ( to == Type . BYTE_TYPE ) { list . add ( new InsnNode ( Opcodes . I2B ) ) ; } else if ( to == Type . CHAR_TYPE ) { list . add ( new InsnNode ( Opcodes . I2C ) ) ; } else if ( to == Type . DOUBLE_TYPE ) { list . add ( new InsnNode ( Opcodes . I2D ) ) ; } else if ( to == Type . FLOAT_TYPE ) { list . add ( new InsnNode ( Opcodes . I2F ) ) ; } else if ( to == Type . LONG_TYPE ) { list . add ( new InsnNode ( Opcodes . I2L ) ) ; } else if ( to == Type . SHORT_TYPE ) { list . add ( new InsnNode ( Opcodes . I2S ) ) ; } } } return list ; }
generates the instructions to cast a numerical value from one type to another .
