From 844177d33eca9995d492f76b57c022880c4624cb Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Thu, 4 May 2017 12:52:28 +0300 Subject: [PATCH] IDEA-127533 int field is displayed as char - show only reasonable ascii as chars --- .../modules/decompiler/exps/ConstExprent.java | 11 +++-- testData/classes/pkg/TestPrimitives.class | Bin 2825 -> 3083 bytes testData/results/TestPrimitives.dec | 43 ++++++++++++++++++ testData/src/pkg/TestPrimitives.java | 11 +++++ 4 files changed, 62 insertions(+), 3 deletions(-) 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 74260de28c361a904942339b0eedadf93023d8b4..8ed2ef7df9feb5797be2caf784f8d49e36c09577 100644 GIT binary patch delta 615 zcmYk2T}xC^6o#LD&KdV{dy)n!BD;{t$Si~?>Lwg2sEe$0Cd#qWGvm?HQO9wzw2$e# z%*tx|F6~R`CX5ie=%ODG^dtHW-A1(+k-FKu`+3(|d+)^>Uoo+=^zHYTufP`G8sZ!` ztfNDuQzR70#B5&HS#epfX(~S>)K$^+b9UL-k3F;EB9ZP&dN|>8QqwEG&yb^EXuz>5 z%o{~@Z#WV*=E8xV#+{?ZXs*rO>ZthKWNau_ayUX8ih4WU?>M;jOx8FvXzx9qyQ5}$ zp1g(N(r^){7jbEUugu-v)7cpxR*4WZLjS%x{B(`g!+ZA63T-4zpE0;)*iJL4#)li@+fc( delta 357 zcmWlV%PvDf7=XWXs5zaS2#JUXz{a8*V%fyTwr+_#M{iVBOWj(u?&?n6sSWEU(xeLu z58wgpJ%hdIKZ|d^Z|2V|=C~=>nECqq_ypQ{(bO}nX=Ow(Di{-tyDImx(oz%E-a`CM zY_i7tTWm=EbQh%@!IT?60gIp_BpudFGb0w!G&3s})yxqSo7coUNoW>W)FfH5ShiTv ztg>d2(xh3}Y_MsO(PY_DY|Aq{irx3}tC7!|zM4IoeGc;9W?SaaCdZMDj~=mOn_l`9 zClaSN{R}A1B+eBVHkVu}@;2Ap7?>?nf`H;yChjCcihGF%#iQ&`a_Cn)OB4)hBhIqp fi8`^cr)w=4EM==YOrx$;b|qYHgTcy=nGF2{ir7e+ 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; + } }