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 9e89f6c..0f0e141 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/ConstExprent.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/ConstExprent.java @@ -133,7 +133,7 @@ public class ConstExprent extends Exprent { String ret = CHAR_ESCAPES.get(val); if (ret == null) { char c = (char)val.intValue(); - if (c >= 32 && c < 127 || !ascii && TextUtil.isPrintableUnicode(c)) { + if (isPrintableAscii(c) || !ascii && TextUtil.isPrintableUnicode(c)) { ret = String.valueOf(c); } else { @@ -278,7 +278,7 @@ public class ConstExprent extends Exprent { // buffer.append("\\\'"); // break; default: - if (c >= 32 && c < 127 || !ascii && TextUtil.isPrintableUnicode(c)) { + if (isPrintableAscii(c) || !ascii && TextUtil.isPrintableUnicode(c)) { buffer.append(c); } else { @@ -371,7 +371,7 @@ public class ConstExprent extends Exprent { // BYTECHAR and SHORTCHAR => CHAR in the CHAR context if (expectedType.equals(VarType.VARTYPE_CHAR) && (constType.equals(VarType.VARTYPE_BYTECHAR) || constType.equals(VarType.VARTYPE_SHORTCHAR))) { - if (getIntValue() != 0) { + if (isPrintableAscii(getIntValue())) { setConstType(VarType.VARTYPE_CHAR); } } @@ -382,6 +382,11 @@ public class ConstExprent extends Exprent { } } + private static boolean isPrintableAscii(int c) { + return c >= 32 && c < 127; + } + + public Object getValue() { return value; } diff --git a/testData/classes/pkg/TestPrimitives.class b/testData/classes/pkg/TestPrimitives.class index 74260de..8ed2ef7 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 03026fa..d6fcbc4 100644 --- a/testData/results/TestPrimitives.dec +++ b/testData/results/TestPrimitives.dec @@ -69,6 +69,17 @@ public class TestPrimitives { public void constructor() { new Byte((byte)1);// 73 }// 74 + + private boolean compare(char c) { + boolean res = c > -1;// 77 + res = c > 0;// 78 + res = c > 1;// 79 + res = c > 'a';// 80 + res = c > 'Z';// 81 + res = c > 127;// 82 + res = c > 255;// 83 + return res;// 84 + } } class 'pkg/TestPrimitives' { @@ -210,6 +221,30 @@ class 'pkg/TestPrimitives' { 4 69 9 70 } + + method 'compare (C)Z' { + 1 73 + 2 73 + a 73 + c 74 + 14 74 + 16 75 + 17 75 + 1f 75 + 21 76 + 23 76 + 2b 76 + 2d 77 + 2f 77 + 37 77 + 39 78 + 3b 78 + 43 78 + 45 79 + 48 79 + 50 79 + 52 80 + } } Lines mapping: @@ -248,3 +283,11 @@ Lines mapping: 70 <-> 67 73 <-> 70 74 <-> 71 +77 <-> 74 +78 <-> 75 +79 <-> 76 +80 <-> 77 +81 <-> 78 +82 <-> 79 +83 <-> 80 +84 <-> 81 diff --git a/testData/src/pkg/TestPrimitives.java b/testData/src/pkg/TestPrimitives.java index 68b6c44..b4aa878 100644 --- a/testData/src/pkg/TestPrimitives.java +++ b/testData/src/pkg/TestPrimitives.java @@ -72,4 +72,15 @@ public class TestPrimitives { public void constructor() { new Byte((byte)1); } + + private boolean compare(char c) { + boolean res = (c > -1); + res = (c > 0); + res = (c > 1); + res = (c > 'a'); + res = (c > 'Z'); + res = (c > 127); + res = (c > 255); + return res; + } }