Removed 'Integer.valueOf()' boxing of literals

master
Dmitry Cherniachenko 8 years ago committed by Egor.Ushakov
parent 40c4d82996
commit 5f292c415c
  1. 9
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java
  2. BIN
      testData/classes/pkg/TestPrimitives.class
  3. 2
      testData/results/TestClassLambda.dec
  4. 231
      testData/results/TestPrimitives.dec
  5. 1
      testData/src/pkg/TestPrimitives.java

@ -409,6 +409,15 @@ public class InvocationExprent extends Exprent {
// special handling for ambiguous types // special handling for ambiguous types
if (lstParameters.get(0).type == Exprent.EXPRENT_CONST) { if (lstParameters.get(0).type == Exprent.EXPRENT_CONST) {
// 'Integer.valueOf(1)' has '1' type detected as TYPE_BYTECHAR
if (lstParameters.get(0).getExprType().typeFamily == CodeConstants.TYPE_FAMILY_INTEGER) {
if (classname.equals("java/lang/Integer")) {
// 'Integer.valueOf(40_000)' will change to '40_000' and that will be interpreted as 'char' type
((ConstExprent) lstParameters.get(0)).setConstType(VarType.VARTYPE_INT);
return true;
}
}
if (paramType == CodeConstants.TYPE_BYTECHAR || paramType == CodeConstants.TYPE_SHORTCHAR) { if (paramType == CodeConstants.TYPE_BYTECHAR || paramType == CodeConstants.TYPE_SHORTCHAR) {
if (classname.equals("java/lang/Character")) { if (classname.equals("java/lang/Character")) {
return true; return true;

@ -15,7 +15,7 @@ public class TestClassLambda {
public int field = 0; public int field = 0;
public void testLambda() { public void testLambda() {
List var1 = Arrays.asList(Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3), Integer.valueOf(4), Integer.valueOf(5), Integer.valueOf(6), Integer.valueOf(7));// 29 List var1 = Arrays.asList(new Integer[]{1, 2, 3, 4, 5, 6, 7});// 29
int var2 = (int)Math.random();// 30 int var2 = (int)Math.random();// 30
var1.forEach((var2x) -> {// 32 var1.forEach((var2x) -> {// 32
int var3 = 2 * var2x.intValue();// 33 int var3 = 2 * var2x.intValue();// 33

@ -10,55 +10,56 @@ public class TestPrimitives {
this.printFloat(1.23F);// 11 this.printFloat(1.23F);// 11
this.printDouble(1.23D);// 12 this.printDouble(1.23D);// 12
this.printChar('Z');// 13 this.printChar('Z');// 13
System.out.println(String.format("%b, %d, %d, %d", this.getBoolean(), this.getByte(), this.getShort(), this.getInt()));// 15 String.format("%b, %d, %d, %d, %c", new Object[]{true, 1, 213, 40000, 'c', 42L});// 15
}// 16 System.out.println(String.format("%b, %d, %d, %d", this.getBoolean(), this.getByte(), this.getShort(), this.getInt()));// 16
}// 17
public void printBoolean(boolean b) { public void printBoolean(boolean b) {
System.out.println(String.format("%b", b));// 19 System.out.println(String.format("%b", b));// 20
}// 20 }// 21
public void printByte(byte b) { public void printByte(byte b) {
System.out.println(String.format("%d", b));// 23 System.out.println(String.format("%d", b));// 24
}// 24 }// 25
public void printShort(short s) { public void printShort(short s) {
System.out.println(String.format("%d", s));// 27 System.out.println(String.format("%d", s));// 28
}// 28 }// 29
public void printInt(int i) { public void printInt(int i) {
System.out.println(String.format("%d", i));// 31 System.out.println(String.format("%d", i));// 32
}// 32 }// 33
public void printLong(long l) { public void printLong(long l) {
System.out.println(String.format("%d", l));// 35 System.out.println(String.format("%d", l));// 36
}// 36 }// 37
public void printFloat(float f) { public void printFloat(float f) {
System.out.println(String.format("%f", f));// 39 System.out.println(String.format("%f", f));// 40
}// 40 }// 41
public void printDouble(double d) { public void printDouble(double d) {
System.out.println(String.format("%f", d));// 43 System.out.println(String.format("%f", d));// 44
}// 44 }// 45
public void printChar(char c) { public void printChar(char c) {
System.out.println(String.format("%c", c));// 47 System.out.println(String.format("%c", c));// 48
}// 48 }// 49
public boolean getBoolean() { public boolean getBoolean() {
return false;// 52 return false;// 53
} }
public byte getByte() { public byte getByte() {
return -128;// 56 return -128;// 57
} }
public short getShort() { public short getShort() {
return -32768;// 60 return -32768;// 61
} }
public int getInt() { public int getInt() {
return 42;// 64 return 42;// 65
} }
public void printNarrowed() { public void printNarrowed() {
@ -107,120 +108,134 @@ class 'pkg/TestPrimitives' {
2d 11 2d 11
2f 11 2f 11
32 12 32 12
35 12 3b 12
3e 12 3c 12
41 12 42 12
48 12 43 12
4b 12 49 12
4c 12
52 12 52 12
55 12 54 12
5a 12
5c 12 5c 12
5f 12 62 12
63 12 65 12
66 12 69 12
69 13 6d 13
70 13
79 13
7c 13
83 13
86 13
8d 13
90 13
97 13
9a 13
9e 13
a1 13
a4 14
} }
method 'printBoolean (Z)V' { method 'printBoolean (Z)V' {
0 16 0 17
3 16 3 17
c 16 c 17
10 16 10 17
13 16 13 17
16 17 16 18
} }
method 'printByte (B)V' { method 'printByte (B)V' {
0 20 0 21
3 20 3 21
c 20 c 21
10 20 10 21
13 20 13 21
16 21 16 22
} }
method 'printShort (S)V' { method 'printShort (S)V' {
0 24 0 25
3 24 3 25
c 24 c 25
10 24 10 25
13 24 13 25
16 25 16 26
} }
method 'printInt (I)V' { method 'printInt (I)V' {
0 28 0 29
3 28 3 29
c 28 c 29
10 28 10 29
13 28 13 29
16 29 16 30
} }
method 'printLong (J)V' { method 'printLong (J)V' {
0 32 0 33
3 32 3 33
c 32 c 33
10 32 10 33
13 32 13 33
16 33 16 34
} }
method 'printFloat (F)V' { method 'printFloat (F)V' {
0 36 0 37
3 36 3 37
c 36 c 37
10 36 10 37
13 36 13 37
16 37 16 38
} }
method 'printDouble (D)V' { method 'printDouble (D)V' {
0 40 0 41
3 40 3 41
c 40 c 41
10 40 10 41
13 40 13 41
16 41 16 42
} }
method 'printChar (C)V' { method 'printChar (C)V' {
0 44 0 45
3 44 3 45
c 44 c 45
10 44 10 45
13 44 13 45
16 45 16 46
} }
method 'getBoolean ()Z' { method 'getBoolean ()Z' {
0 48 0 49
1 48 1 49
} }
method 'getByte ()B' { method 'getByte ()B' {
0 52 0 53
2 52 2 53
} }
method 'getShort ()S' { method 'getShort ()S' {
0 56 0 57
3 56 3 57
} }
method 'getInt ()I' { method 'getInt ()I' {
0 60 0 61
2 60 2 61
} }
method 'printNarrowed ()V' { method 'printNarrowed ()V' {
2 64 2 65
5 64 5 65
6 64 6 65
b 65 b 66
e 65 e 66
f 65 f 66
12 66 12 67
} }
method 'constructor ()V' { method 'constructor ()V' {
@ -282,27 +297,27 @@ Lines mapping:
13 <-> 12 13 <-> 12
15 <-> 13 15 <-> 13
16 <-> 14 16 <-> 14
19 <-> 17 17 <-> 15
20 <-> 18 20 <-> 18
23 <-> 21 21 <-> 19
24 <-> 22 24 <-> 22
27 <-> 25 25 <-> 23
28 <-> 26 28 <-> 26
31 <-> 29 29 <-> 27
32 <-> 30 32 <-> 30
35 <-> 33 33 <-> 31
36 <-> 34 36 <-> 34
39 <-> 37 37 <-> 35
40 <-> 38 40 <-> 38
43 <-> 41 41 <-> 39
44 <-> 42 44 <-> 42
47 <-> 45 45 <-> 43
48 <-> 46 48 <-> 46
52 <-> 49 49 <-> 47
56 <-> 53 53 <-> 50
60 <-> 57 57 <-> 54
64 <-> 61 61 <-> 58
68 <-> 65 65 <-> 62
69 <-> 66 69 <-> 66
70 <-> 67 70 <-> 67
73 <-> 70 73 <-> 70

@ -12,6 +12,7 @@ public class TestPrimitives {
printDouble(1.23); printDouble(1.23);
printChar('Z'); printChar('Z');
String.format("%b, %d, %d, %d, %c", true, 1, 213, 40_000, 'c', 42L);
System.out.println(String.format("%b, %d, %d, %d", getBoolean(), getByte(), getShort(), getInt())); System.out.println(String.format("%b, %d, %d, %d", getBoolean(), getByte(), getShort(), getInt()));
} }

Loading…
Cancel
Save