Omit unnecessary unboxing calls in decompiled code

This commit is contained in:
Dmitry Cherniachenko
2017-06-23 23:22:32 +02:00
committed by Egor.Ushakov
parent aa78b7df28
commit 39db41ee8b
7 changed files with 467 additions and 316 deletions

View File

@@ -267,6 +267,12 @@ public class InvocationExprent extends Exprent {
else if (instance != null) {
TextBuffer res = instance.toJava(indent, tracer);
if (isUnboxingCall()) {
// we don't print the unboxing call - no need to bother with the instance wrapping / casting
buf.append(res);
return buf;
}
VarType rightType = instance.getExprType();
VarType leftType = new VarType(CodeConstants.TYPE_OBJECT, 0, classname);
@@ -460,6 +466,24 @@ public class InvocationExprent extends Exprent {
return null;
}
private static final Map<String, String> UNBOXING_METHODS;
static {
UNBOXING_METHODS = new HashMap<>();
UNBOXING_METHODS.put("booleanValue", "java/lang/Boolean");
UNBOXING_METHODS.put("byteValue", "java/lang/Byte");
UNBOXING_METHODS.put("shortValue", "java/lang/Short");
UNBOXING_METHODS.put("intValue", "java/lang/Integer");
UNBOXING_METHODS.put("longValue", "java/lang/Long");
UNBOXING_METHODS.put("floatValue", "java/lang/Float");
UNBOXING_METHODS.put("doubleValue", "java/lang/Double");
UNBOXING_METHODS.put("charValue", "java/lang/Character");
}
private boolean isUnboxingCall() {
return !isStatic && lstParameters.size() == 0 && classname.equals(UNBOXING_METHODS.get(name));
}
private BitSet getAmbiguousParameters() {
StructClass cl = DecompilerContext.getStructContext().getClass(classname);
if (cl == null) return EMPTY_BIT_SET;