[Fernflower] autoboxing primitives should not always be ignored

master
Alexandru-Constantin Bledea 7 years ago committed by Egor.Ushakov
parent 39db41ee8b
commit 893450cdb3
  1. 13
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java
  2. BIN
      testData/classes/pkg/TestPrimitives.class
  3. 12
      testData/results/TestPrimitives.dec
  4. 5
      testData/src/pkg/TestPrimitives.java

@ -61,6 +61,7 @@ public class InvocationExprent extends Exprent {
private String name;
private String classname;
private boolean isStatic;
private boolean canIgnoreBoxing = true;
private int functype = TYP_GENERAL;
private Exprent instance;
private MethodDescriptor descriptor;
@ -84,7 +85,6 @@ public class InvocationExprent extends Exprent {
name = cn.elementname;
classname = cn.classname;
this.bootstrapArguments = bootstrapArguments;
switch (opcode) {
case CodeConstants.opc_invokestatic:
invocationTyp = INVOKE_STATIC;
@ -155,6 +155,7 @@ public class InvocationExprent extends Exprent {
name = expr.getName();
classname = expr.getClassname();
isStatic = expr.isStatic();
canIgnoreBoxing = expr.canIgnoreBoxing;
functype = expr.getFunctype();
instance = expr.getInstance();
if (instance != null) {
@ -217,8 +218,12 @@ public class InvocationExprent extends Exprent {
tracer.addMapping(bytecode);
if (instance instanceof InvocationExprent) {
((InvocationExprent) instance).markUsingBoxingResult();
}
if (isStatic) {
if (isBoxingCall()) {
if (isBoxingCall() && canIgnoreBoxing) {
// process general "boxing" calls, e.g. 'Object[] data = { true }' or 'Byte b = 123'
// here 'byte' and 'short' values do not need an explicit narrowing type cast
ExprProcessor.getCastedExprent(lstParameters.get(0), descriptor.params[0], buf, indent, false, false, false, tracer);
@ -441,6 +446,10 @@ public class InvocationExprent extends Exprent {
return false;
}
public void markUsingBoxingResult() {
canIgnoreBoxing = false;
}
// TODO: move to CodeConstants ???
private static String getClassNameForPrimitiveType(int type) {
switch (type) {

@ -157,6 +157,10 @@ public class TestPrimitives {
res = c > 255;// 166
return res;// 167
}
void testAutoBoxingCallRequired(boolean value) {
Boolean.valueOf(value).hashCode();// 171
}// 172
}
class 'pkg/TestPrimitives' {
@ -530,6 +534,12 @@ class 'pkg/TestPrimitives' {
98 156
9a 157
}
method 'testAutoBoxingCallRequired (Z)V' {
1 161
4 161
8 162
}
}
Lines mapping:
@ -628,6 +638,8 @@ Lines mapping:
165 <-> 156
166 <-> 157
167 <-> 158
171 <-> 162
172 <-> 163
Not mapped:
46
50

@ -166,4 +166,9 @@ public class TestPrimitives {
res = (c > 255);
return res;
}
void testAutoBoxingCallRequired(boolean value) {
Boolean.valueOf(value).hashCode();
}
}

Loading…
Cancel
Save