[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 name;
private String classname; private String classname;
private boolean isStatic; private boolean isStatic;
private boolean canIgnoreBoxing = true;
private int functype = TYP_GENERAL; private int functype = TYP_GENERAL;
private Exprent instance; private Exprent instance;
private MethodDescriptor descriptor; private MethodDescriptor descriptor;
@ -84,7 +85,6 @@ public class InvocationExprent extends Exprent {
name = cn.elementname; name = cn.elementname;
classname = cn.classname; classname = cn.classname;
this.bootstrapArguments = bootstrapArguments; this.bootstrapArguments = bootstrapArguments;
switch (opcode) { switch (opcode) {
case CodeConstants.opc_invokestatic: case CodeConstants.opc_invokestatic:
invocationTyp = INVOKE_STATIC; invocationTyp = INVOKE_STATIC;
@ -155,6 +155,7 @@ public class InvocationExprent extends Exprent {
name = expr.getName(); name = expr.getName();
classname = expr.getClassname(); classname = expr.getClassname();
isStatic = expr.isStatic(); isStatic = expr.isStatic();
canIgnoreBoxing = expr.canIgnoreBoxing;
functype = expr.getFunctype(); functype = expr.getFunctype();
instance = expr.getInstance(); instance = expr.getInstance();
if (instance != null) { if (instance != null) {
@ -217,8 +218,12 @@ public class InvocationExprent extends Exprent {
tracer.addMapping(bytecode); tracer.addMapping(bytecode);
if (instance instanceof InvocationExprent) {
((InvocationExprent) instance).markUsingBoxingResult();
}
if (isStatic) { if (isStatic) {
if (isBoxingCall()) { if (isBoxingCall() && canIgnoreBoxing) {
// process general "boxing" calls, e.g. 'Object[] data = { true }' or 'Byte b = 123' // 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 // 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); 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; return false;
} }
public void markUsingBoxingResult() {
canIgnoreBoxing = false;
}
// TODO: move to CodeConstants ??? // TODO: move to CodeConstants ???
private static String getClassNameForPrimitiveType(int type) { private static String getClassNameForPrimitiveType(int type) {
switch (type) { switch (type) {

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

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

Loading…
Cancel
Save