diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/ConstExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/ConstExprent.java index 612fd37..e77b680 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/ConstExprent.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/ConstExprent.java @@ -369,16 +369,16 @@ public class ConstExprent extends Exprent { public void adjustConstType(VarType expectedType) { // BYTECHAR and SHORTCHAR => CHAR in the CHAR context - if (expectedType.equals(VarType.VARTYPE_CHAR) && + if ((expectedType.equals(VarType.VARTYPE_CHAR) || expectedType.equals(VarType.VARTYPE_CHARACTER)) && (constType.equals(VarType.VARTYPE_BYTECHAR) || constType.equals(VarType.VARTYPE_SHORTCHAR))) { int intValue = getIntValue(); if (isPrintableAscii(intValue) || CHAR_ESCAPES.containsKey(intValue)) { setConstType(VarType.VARTYPE_CHAR); } } - // CHAR => INT in the INT context - else if (expectedType.equals(VarType.VARTYPE_INT) && - constType.equals(VarType.VARTYPE_CHAR)) { + // BYTE, BYTECHAR, SHORTCHAR, SHORT, CHAR => INT in the INT context + else if ((expectedType.equals(VarType.VARTYPE_INT) || expectedType.equals(VarType.VARTYPE_INTEGER)) && + constType.typeFamily == CodeConstants.TYPE_FAMILY_INTEGER) { setConstType(VarType.VARTYPE_INT); } } 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 19f913e..e5ff698 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java @@ -410,10 +410,10 @@ 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 + // 'Integer.valueOf(40_000)' has '40_000' type detected as TYPE_CHAR + // so we check the type family instead 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; } } diff --git a/src/org/jetbrains/java/decompiler/struct/gen/VarType.java b/src/org/jetbrains/java/decompiler/struct/gen/VarType.java index 1eb177f..410cf09 100644 --- a/src/org/jetbrains/java/decompiler/struct/gen/VarType.java +++ b/src/org/jetbrains/java/decompiler/struct/gen/VarType.java @@ -38,6 +38,8 @@ public class VarType { // TODO: optimize switch public static final VarType VARTYPE_STRING = new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/String"); public static final VarType VARTYPE_CLASS = new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/Class"); public static final VarType VARTYPE_OBJECT = new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/Object"); + public static final VarType VARTYPE_INTEGER = new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/Integer"); + public static final VarType VARTYPE_CHARACTER = new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/Character"); public static final VarType VARTYPE_VOID = new VarType(CodeConstants.TYPE_VOID); public final int type; diff --git a/testData/classes/pkg/TestPrimitives.class b/testData/classes/pkg/TestPrimitives.class index fb4d81f..2af9d83 100644 Binary files a/testData/classes/pkg/TestPrimitives.class and b/testData/classes/pkg/TestPrimitives.class differ diff --git a/testData/results/TestPrimitives.dec b/testData/results/TestPrimitives.dec index 78922f4..4456671 100644 --- a/testData/results/TestPrimitives.dec +++ b/testData/results/TestPrimitives.dec @@ -10,82 +10,87 @@ public class TestPrimitives { this.printFloat(1.23F);// 11 this.printDouble(1.23D);// 12 this.printChar('Z');// 13 - String.format("%b, %d, %d, %d, %c", 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 + this.printIntBoxed(40000);// 15 + String.format("%b, %d, %d, %d, %c, %d", true, 1, 213, 40000, 'c', 42L);// 17 + System.out.println(String.format("%b, %d, %d, %d", this.getBoolean(), this.getByte(), this.getShort(), this.getInt()));// 18 + }// 19 public void printBoolean(boolean b) { - System.out.println(String.format("%b", b));// 20 - }// 21 + System.out.println(String.format("%b", b));// 22 + }// 23 public void printByte(byte b) { - System.out.println(String.format("%d", b));// 24 - }// 25 + System.out.println(String.format("%d", b));// 26 + }// 27 public void printShort(short s) { - System.out.println(String.format("%d", s));// 28 - }// 29 + System.out.println(String.format("%d", s));// 30 + }// 31 public void printInt(int i) { - System.out.println(String.format("%d", i));// 32 - }// 33 + System.out.println(String.format("%d", i));// 34 + }// 35 public void printLong(long l) { - System.out.println(String.format("%d", l));// 36 - }// 37 + System.out.println(String.format("%d", l));// 38 + }// 39 public void printFloat(float f) { - System.out.println(String.format("%f", f));// 40 - }// 41 + System.out.println(String.format("%f", f));// 42 + }// 43 public void printDouble(double d) { - System.out.println(String.format("%f", d));// 44 - }// 45 + System.out.println(String.format("%f", d));// 46 + }// 47 public void printChar(char c) { - System.out.println(String.format("%c", c));// 48 - }// 49 + System.out.println(String.format("%c", c));// 50 + }// 51 + + public void printIntBoxed(Integer i) { + System.out.println(String.format("%d", i));// 55 + }// 56 public boolean getBoolean() { - return false;// 53 + return false;// 60 } public byte getByte() { - return -128;// 57 + return -128;// 64 } public short getShort() { - return -32768;// 61 + return -32768;// 68 } public int getInt() { - return 42;// 65 + return 42;// 72 } public void printNarrowed() { - this.printByte((byte)this.getInt());// 69 - this.printShort((short)this.getInt());// 70 - }// 71 + this.printByte((byte)this.getInt());// 76 + this.printShort((short)this.getInt());// 77 + }// 78 public void constructor() { - new Byte((byte)1);// 74 - }// 75 + new Byte((byte)1);// 81 + }// 82 private boolean compare(char c) { - boolean res = c > -1;// 78 - res = c > 0;// 79 - res = c > 1;// 80 - res = c > '\b';// 81 - res = c > '\t';// 82 - res = c > '\n';// 83 - res = c > '\f';// 84 - res = c > '\r';// 85 - res = c > ' ';// 86 - res = c > 'a';// 87 - res = c > 'Z';// 88 - res = c > 127;// 89 - res = c > 255;// 90 - return res;// 91 + boolean res = c > -1;// 85 + res = c > 0;// 86 + res = c > 1;// 87 + res = c > '\b';// 88 + res = c > '\t';// 89 + res = c > '\n';// 90 + res = c > '\f';// 91 + res = c > '\r';// 92 + res = c > ' ';// 93 + res = c > 'a';// 94 + res = c > 'Z';// 95 + res = c > 127;// 96 + res = c > 255;// 97 + return res;// 98 } } @@ -107,182 +112,192 @@ class 'pkg/TestPrimitives' { 29 10 2d 11 2f 11 - 32 12 - 3b 12 - 3c 12 - 42 12 - 43 12 - 49 12 - 4c 12 - 52 12 - 54 12 - 5a 12 - 5c 12 - 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 + 33 12 + 38 12 + 3b 13 + 44 13 + 45 13 + 4b 13 + 4c 13 + 52 13 + 55 13 + 5b 13 + 5d 13 + 63 13 + 65 13 + 6b 13 + 6e 13 + 72 13 + 76 14 + 79 14 + 82 14 + 85 14 + 8c 14 + 8f 14 + 96 14 + 99 14 + a0 14 + a3 14 + a7 14 + aa 14 + ad 15 } method 'printBoolean (Z)V' { - 0 17 - 3 17 - c 17 - 10 17 - 13 17 - 16 18 + 0 18 + 3 18 + c 18 + 10 18 + 13 18 + 16 19 } method 'printByte (B)V' { - 0 21 - 3 21 - c 21 - 10 21 - 13 21 - 16 22 + 0 22 + 3 22 + c 22 + 10 22 + 13 22 + 16 23 } method 'printShort (S)V' { - 0 25 - 3 25 - c 25 - 10 25 - 13 25 - 16 26 + 0 26 + 3 26 + c 26 + 10 26 + 13 26 + 16 27 } method 'printInt (I)V' { - 0 29 - 3 29 - c 29 - 10 29 - 13 29 - 16 30 + 0 30 + 3 30 + c 30 + 10 30 + 13 30 + 16 31 } method 'printLong (J)V' { - 0 33 - 3 33 - c 33 - 10 33 - 13 33 - 16 34 + 0 34 + 3 34 + c 34 + 10 34 + 13 34 + 16 35 } method 'printFloat (F)V' { - 0 37 - 3 37 - c 37 - 10 37 - 13 37 - 16 38 + 0 38 + 3 38 + c 38 + 10 38 + 13 38 + 16 39 } method 'printDouble (D)V' { - 0 41 - 3 41 - c 41 - 10 41 - 13 41 - 16 42 + 0 42 + 3 42 + c 42 + 10 42 + 13 42 + 16 43 } method 'printChar (C)V' { - 0 45 - 3 45 - c 45 - 10 45 - 13 45 - 16 46 + 0 46 + 3 46 + c 46 + 10 46 + 13 46 + 16 47 + } + + method 'printIntBoxed (Ljava/lang/Integer;)V' { + 0 50 + 3 50 + d 50 + 10 50 + 13 51 } method 'getBoolean ()Z' { - 0 49 - 1 49 + 0 54 + 1 54 } method 'getByte ()B' { - 0 53 - 2 53 + 0 58 + 2 58 } method 'getShort ()S' { - 0 57 - 3 57 + 0 62 + 3 62 } method 'getInt ()I' { - 0 61 - 2 61 + 0 66 + 2 66 } method 'printNarrowed ()V' { - 2 65 - 5 65 - 6 65 - b 66 - e 66 - f 66 - 12 67 + 2 70 + 5 70 + 6 70 + b 71 + e 71 + f 71 + 12 72 } method 'constructor ()V' { - 4 70 - 9 71 + 4 75 + 9 76 } method 'compare (C)Z' { - 1 74 - 2 74 - a 74 - c 75 - 14 75 - 16 76 - 17 76 - 1f 76 - 21 77 - 23 77 - 2b 77 - 2d 78 - 2f 78 - 37 78 - 39 79 - 3b 79 - 43 79 - 45 80 - 47 80 - 4f 80 - 51 81 - 53 81 - 5b 81 - 5d 82 - 5f 82 - 67 82 - 69 83 - 6b 83 - 73 83 - 75 84 - 77 84 - 7f 84 - 81 85 - 83 85 - 8b 85 - 8d 86 - 90 86 - 98 86 - 9a 87 + 1 79 + 2 79 + a 79 + c 80 + 14 80 + 16 81 + 17 81 + 1f 81 + 21 82 + 23 82 + 2b 82 + 2d 83 + 2f 83 + 37 83 + 39 84 + 3b 84 + 43 84 + 45 85 + 47 85 + 4f 85 + 51 86 + 53 86 + 5b 86 + 5d 87 + 5f 87 + 67 87 + 69 88 + 6b 88 + 73 88 + 75 89 + 77 89 + 7f 89 + 81 90 + 83 90 + 8b 90 + 8d 91 + 90 91 + 98 91 + 9a 92 } } @@ -296,44 +311,47 @@ Lines mapping: 12 <-> 11 13 <-> 12 15 <-> 13 -16 <-> 14 -17 <-> 15 -20 <-> 18 -21 <-> 19 -24 <-> 22 -25 <-> 23 -28 <-> 26 -29 <-> 27 -32 <-> 30 -33 <-> 31 -36 <-> 34 -37 <-> 35 -40 <-> 38 -41 <-> 39 -44 <-> 42 -45 <-> 43 -48 <-> 46 -49 <-> 47 -53 <-> 50 -57 <-> 54 -61 <-> 58 -65 <-> 62 -69 <-> 66 -70 <-> 67 -71 <-> 68 -74 <-> 71 -75 <-> 72 -78 <-> 75 -79 <-> 76 -80 <-> 77 -81 <-> 78 -82 <-> 79 -83 <-> 80 -84 <-> 81 -85 <-> 82 -86 <-> 83 -87 <-> 84 -88 <-> 85 -89 <-> 86 -90 <-> 87 -91 <-> 88 +17 <-> 14 +18 <-> 15 +19 <-> 16 +22 <-> 19 +23 <-> 20 +26 <-> 23 +27 <-> 24 +30 <-> 27 +31 <-> 28 +34 <-> 31 +35 <-> 32 +38 <-> 35 +39 <-> 36 +42 <-> 39 +43 <-> 40 +46 <-> 43 +47 <-> 44 +50 <-> 47 +51 <-> 48 +55 <-> 51 +56 <-> 52 +60 <-> 55 +64 <-> 59 +68 <-> 63 +72 <-> 67 +76 <-> 71 +77 <-> 72 +78 <-> 73 +81 <-> 76 +82 <-> 77 +85 <-> 80 +86 <-> 81 +87 <-> 82 +88 <-> 83 +89 <-> 84 +90 <-> 85 +91 <-> 86 +92 <-> 87 +93 <-> 88 +94 <-> 89 +95 <-> 90 +96 <-> 91 +97 <-> 92 +98 <-> 93 diff --git a/testData/src/pkg/TestPrimitives.java b/testData/src/pkg/TestPrimitives.java index 484eb84..9448e4d 100644 --- a/testData/src/pkg/TestPrimitives.java +++ b/testData/src/pkg/TestPrimitives.java @@ -12,7 +12,9 @@ public class TestPrimitives { printDouble(1.23); printChar('Z'); - String.format("%b, %d, %d, %d, %c", true, 1, 213, 40_000, 'c', 42L); + printIntBoxed(40_000); + + String.format("%b, %d, %d, %d, %c, %d", true, 1, 213, 40_000, 'c', 42L); System.out.println(String.format("%b, %d, %d, %d", getBoolean(), getByte(), getShort(), getInt())); } @@ -49,6 +51,11 @@ public class TestPrimitives { } + public void printIntBoxed(Integer i) { + System.out.println(String.format("%d", i)); + } + + public boolean getBoolean() { return false; }