From 5f292c415c076374d5068e3e73358ccc16047118 Mon Sep 17 00:00:00 2001 From: Dmitry Cherniachenko Date: Thu, 20 Apr 2017 22:49:24 +0200 Subject: [PATCH] Removed 'Integer.valueOf()' boxing of literals --- .../decompiler/exps/InvocationExprent.java | 9 + testData/classes/pkg/TestPrimitives.class | Bin 3197 -> 2832 bytes testData/results/TestClassLambda.dec | 2 +- testData/results/TestPrimitives.dec | 231 ++++++++++-------- testData/src/pkg/TestPrimitives.java | 1 + 5 files changed, 134 insertions(+), 109 deletions(-) diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java index 8d53711..19f913e 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java @@ -409,6 +409,15 @@ public class InvocationExprent extends Exprent { // special handling for ambiguous types 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 (classname.equals("java/lang/Character")) { return true; diff --git a/testData/classes/pkg/TestPrimitives.class b/testData/classes/pkg/TestPrimitives.class index be15ee5f11867ff023c89f26814bcbc4985d2194..022c8c1860db9321f95c8d604faa47ffb5727aa3 100644 GIT binary patch literal 2832 zcmaKuTXz#x6vzLQq?vRW+B8W^QLrFHLM$zys90{j5Nxf02Ei6@({$PnB$=8{i+~rr z-!F)FL4ANX7i;N5%yKRL0KWSH{0u($=JJ2eOed3;(6ut>oPGB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`|Ic}rWx!pUxNiK zhF~gKV)|(n8DyE1Q?U&ela^Jy1e-}KDjeihtm2G{mvJ_Pb0N0KD|j`8*Hm1H}uZbPh=f#&%3ekO!?fLqfxtnKQ=o*;&IruFq!3(l}BL(kDF zu^G0QG)tcu2{rEMS%=nK!VE6sYT0nm_5bqw49VGu}5-zWQ32HG%`|xjaj(` z<}}KOC<1A;1RTy-I(Hl9WAijNETNV!He}^_wsLHU56;oxP>DIXsN0M=$cNH2G)T+^ z!}0T?8d5q6Gx20dr#wQWds&cyg0Ch651mwsxQ;J9uG_YC#-J5z(^hW9vGZxiqV<%t zm0i|tUYbFM584J5p)Td<>C?ybWp69gl$E#B#<0mYt7-jS>|WAWbq(7Q(~!g-4UeE( z!((_{!+!K?ID|e80~pjWjH4Px@uY(HHGF^%CDeD#COW(3N*@Vf21{o2+(L3G(3%zf=f)ftl>DGQSd2Kt|<6S!{_)y!Iv7o!c_@@F6x9p z*PMc{*^FyUnOE=)Q?4tx!M?v`#(zV(V= zm%(zlOGT&&d5dP~=r-Sl&CY|c9q!p{qO&Kg$&BlZ;hn>1Y*?Jft?TnE9m-}plmgK; z`yunaU`JF>JFIeTbWVlY{zxyj(486KH*o|KI~DZYL3)zDCHk(4--h%v2?50ES z>?B!pCm?}cq)FKAI~ToqOL4h?Ks1A zwaD>C@9pS@;$UXS>BDPe3?<9Dl0{jV#a5%kte7F$#gMPPctpHCF zd`|`V7>;o`y{9~Qg6nj`gFjK_#dF@x8SXg`_$P#3YM$pV&odZa+vwUOxCVV!dJB54 zyFFJqvWAVm2LxZ)_obKS9m~cyy7mjM5!{`b}eFxevO~N8YOy>QoV{9UWQILRj&+` pG~BMN#U+}tmr8Mx_z7&P>6iXNNa~kJP%Hn}_Or|N6!`@3-2apXB8mV2 diff --git a/testData/results/TestClassLambda.dec b/testData/results/TestClassLambda.dec index 609928c..7133344 100644 --- a/testData/results/TestClassLambda.dec +++ b/testData/results/TestClassLambda.dec @@ -15,7 +15,7 @@ public class TestClassLambda { public int field = 0; 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 var1.forEach((var2x) -> {// 32 int var3 = 2 * var2x.intValue();// 33 diff --git a/testData/results/TestPrimitives.dec b/testData/results/TestPrimitives.dec index eae376a..1cc23bc 100644 --- a/testData/results/TestPrimitives.dec +++ b/testData/results/TestPrimitives.dec @@ -10,55 +10,56 @@ public class TestPrimitives { this.printFloat(1.23F);// 11 this.printDouble(1.23D);// 12 this.printChar('Z');// 13 - System.out.println(String.format("%b, %d, %d, %d", this.getBoolean(), this.getByte(), this.getShort(), this.getInt()));// 15 - }// 16 + String.format("%b, %d, %d, %d, %c", new Object[]{true, 1, 213, 40000, 'c', 42L});// 15 + System.out.println(String.format("%b, %d, %d, %d", this.getBoolean(), this.getByte(), this.getShort(), this.getInt()));// 16 + }// 17 public void printBoolean(boolean b) { - System.out.println(String.format("%b", b));// 19 - }// 20 + System.out.println(String.format("%b", b));// 20 + }// 21 public void printByte(byte b) { - System.out.println(String.format("%d", b));// 23 - }// 24 + System.out.println(String.format("%d", b));// 24 + }// 25 public void printShort(short s) { - System.out.println(String.format("%d", s));// 27 - }// 28 + System.out.println(String.format("%d", s));// 28 + }// 29 public void printInt(int i) { - System.out.println(String.format("%d", i));// 31 - }// 32 + System.out.println(String.format("%d", i));// 32 + }// 33 public void printLong(long l) { - System.out.println(String.format("%d", l));// 35 - }// 36 + System.out.println(String.format("%d", l));// 36 + }// 37 public void printFloat(float f) { - System.out.println(String.format("%f", f));// 39 - }// 40 + System.out.println(String.format("%f", f));// 40 + }// 41 public void printDouble(double d) { - System.out.println(String.format("%f", d));// 43 - }// 44 + System.out.println(String.format("%f", d));// 44 + }// 45 public void printChar(char c) { - System.out.println(String.format("%c", c));// 47 - }// 48 + System.out.println(String.format("%c", c));// 48 + }// 49 public boolean getBoolean() { - return false;// 52 + return false;// 53 } public byte getByte() { - return -128;// 56 + return -128;// 57 } public short getShort() { - return -32768;// 60 + return -32768;// 61 } public int getInt() { - return 42;// 64 + return 42;// 65 } public void printNarrowed() { @@ -107,120 +108,134 @@ class 'pkg/TestPrimitives' { 2d 11 2f 11 32 12 - 35 12 - 3e 12 - 41 12 - 48 12 - 4b 12 + 3b 12 + 3c 12 + 42 12 + 43 12 + 49 12 + 4c 12 52 12 - 55 12 + 54 12 + 5a 12 5c 12 - 5f 12 - 63 12 - 66 12 - 69 13 + 62 12 + 65 12 + 69 12 + 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' { - 0 16 - 3 16 - c 16 - 10 16 - 13 16 - 16 17 + 0 17 + 3 17 + c 17 + 10 17 + 13 17 + 16 18 } method 'printByte (B)V' { - 0 20 - 3 20 - c 20 - 10 20 - 13 20 - 16 21 + 0 21 + 3 21 + c 21 + 10 21 + 13 21 + 16 22 } method 'printShort (S)V' { - 0 24 - 3 24 - c 24 - 10 24 - 13 24 - 16 25 + 0 25 + 3 25 + c 25 + 10 25 + 13 25 + 16 26 } method 'printInt (I)V' { - 0 28 - 3 28 - c 28 - 10 28 - 13 28 - 16 29 + 0 29 + 3 29 + c 29 + 10 29 + 13 29 + 16 30 } method 'printLong (J)V' { - 0 32 - 3 32 - c 32 - 10 32 - 13 32 - 16 33 + 0 33 + 3 33 + c 33 + 10 33 + 13 33 + 16 34 } method 'printFloat (F)V' { - 0 36 - 3 36 - c 36 - 10 36 - 13 36 - 16 37 + 0 37 + 3 37 + c 37 + 10 37 + 13 37 + 16 38 } method 'printDouble (D)V' { - 0 40 - 3 40 - c 40 - 10 40 - 13 40 - 16 41 + 0 41 + 3 41 + c 41 + 10 41 + 13 41 + 16 42 } method 'printChar (C)V' { - 0 44 - 3 44 - c 44 - 10 44 - 13 44 - 16 45 + 0 45 + 3 45 + c 45 + 10 45 + 13 45 + 16 46 } method 'getBoolean ()Z' { - 0 48 - 1 48 + 0 49 + 1 49 } method 'getByte ()B' { - 0 52 - 2 52 + 0 53 + 2 53 } method 'getShort ()S' { - 0 56 - 3 56 + 0 57 + 3 57 } method 'getInt ()I' { - 0 60 - 2 60 + 0 61 + 2 61 } method 'printNarrowed ()V' { - 2 64 - 5 64 - 6 64 - b 65 - e 65 - f 65 - 12 66 + 2 65 + 5 65 + 6 65 + b 66 + e 66 + f 66 + 12 67 } method 'constructor ()V' { @@ -282,27 +297,27 @@ Lines mapping: 13 <-> 12 15 <-> 13 16 <-> 14 -19 <-> 17 +17 <-> 15 20 <-> 18 -23 <-> 21 +21 <-> 19 24 <-> 22 -27 <-> 25 +25 <-> 23 28 <-> 26 -31 <-> 29 +29 <-> 27 32 <-> 30 -35 <-> 33 +33 <-> 31 36 <-> 34 -39 <-> 37 +37 <-> 35 40 <-> 38 -43 <-> 41 +41 <-> 39 44 <-> 42 -47 <-> 45 +45 <-> 43 48 <-> 46 -52 <-> 49 -56 <-> 53 -60 <-> 57 -64 <-> 61 -68 <-> 65 +49 <-> 47 +53 <-> 50 +57 <-> 54 +61 <-> 58 +65 <-> 62 69 <-> 66 70 <-> 67 73 <-> 70 diff --git a/testData/src/pkg/TestPrimitives.java b/testData/src/pkg/TestPrimitives.java index 39041ef..484eb84 100644 --- a/testData/src/pkg/TestPrimitives.java +++ b/testData/src/pkg/TestPrimitives.java @@ -12,6 +12,7 @@ public class TestPrimitives { printDouble(1.23); 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())); }