ByteCodeUtils { public static void unbox(GeneratorAdapter mv, Type type) { if (type.equals(Type.SHORT_TYPE)) { mv.checkCast(NUMBER_TYPE); mv.invokeVirtual(NUMBER_TYPE, SHORT_VALUE); } else if (type.equals(Type.BYTE_TYPE)) { mv.checkCast(NUMBER_TYPE); mv.invokeVirtual(NUMBER_TYPE, BYTE_VALUE); } else { mv.unbox(type); } }  static void unbox(GeneratorAdapter mv, Type type); static String textify(@NonNull MethodNode method); @NonNull static String toInternalName(@NonNull String className); @NonNull static String getClassName(@NonNull String memberName); @NonNull static Optional<String> getPackageName(@NonNull String internalName); static final String CONSTRUCTOR; static final String CLASS_INITIALIZER; }
@Test public void testShortUnbox() { ByteCodeUtils.unbox(generator, Type.SHORT_TYPE); verify(generator, times(1)).checkCast(Type.getObjectType("java/lang/Number")); verify(generator, times(1)).invokeVirtual(Type.getObjectType("java/lang/Number"), Method.getMethod("short shortValue()")); }
@Test public void testByteUnbox() { ByteCodeUtils.unbox(generator, Type.BYTE_TYPE); verify(generator, times(1)).checkCast(Type.getObjectType("java/lang/Number")); verify(generator, times(1)).invokeVirtual(Type.getObjectType("java/lang/Number"), Method.getMethod("byte byteValue()")); }
@Test public void testIntUnbox() { ByteCodeUtils.unbox(generator, Type.INT_TYPE); verify(generator, times(1)).unbox(Type.INT_TYPE); }
@Test public void testObjectUnbox() { ByteCodeUtils.unbox(generator, Type.getType(String.class)); verify(generator, times(1)).unbox(Type.getType(String.class)); }