Proxy box method to use valueOf.

This commit is contained in:
Jack Conradson 2016-05-20 11:22:18 -07:00
parent 0e24ed49e6
commit b156438957
2 changed files with 11 additions and 13 deletions

View File

@ -159,11 +159,11 @@ public final class MethodWriter extends GeneratorAdapter {
writeCast(from, to);
unbox(to.type);
} else if (cast.boxFrom) {
valueOf(from.type);
box(from.type);
writeCast(from, to);
} else if (cast.boxTo) {
writeCast(from, to);
valueOf(to.type);
box(to.type);
} else {
writeCast(from, to);
}
@ -184,6 +184,14 @@ public final class MethodWriter extends GeneratorAdapter {
}
}
/**
* Proxy the box method to use valueOf instead to ensure that the modern boxing methods are used.
*/
@Override
public void box(org.objectweb.asm.Type type) {
valueOf(type);
}
public void writeBranch(final Label tru, final Label fals) {
if (tru != null) {
visitJumpInsn(Opcodes.IFNE, tru);

View File

@ -135,17 +135,7 @@ public final class WriterConstants {
public final static Method STRINGBUILDER_APPEND_OBJECT = getAsmMethod(StringBuilder.class, "append", Object.class);
public final static Method STRINGBUILDER_TOSTRING = getAsmMethod(String.class, "toString");
public final static Method CHECKEQUALS =
getAsmMethod(boolean.class, "checkEquals", Object.class, Object.class);
public final static Type BOOLEAN_OBJECT = Type.getType(Boolean.class);
public final static Type BYTE_OBJECT = Type.getType(Byte.class);
public final static Type SHORT_OBJECT = Type.getType(Short.class);
public final static Type CHARACTER_OBJECT = Type.getType(Character.class);
public final static Type INTEGER_OBJECT = Type.getType(Integer.class);
public final static Type LONG_OBJECT = Type.getType(Long.class);
public final static Type FLOAT_OBJECT = Type.getType(Float.class);
public final static Type DOUBLE_OBJECT = Type.getType(Double.class);
public final static Method CHECKEQUALS = getAsmMethod(boolean.class, "checkEquals", Object.class, Object.class);
private static Method getAsmMethod(final Class<?> rtype, final String name, final Class<?>... ptypes) {
return new Method(name, MethodType.methodType(rtype, ptypes).toMethodDescriptorString());