IDEA-127533 int field is displayed as char - show only reasonable ascii as chars

master
Egor.Ushakov 8 years ago
parent 1c0cad79c6
commit 844177d33e
  1. 11
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/ConstExprent.java
  2. BIN
      testData/classes/pkg/TestPrimitives.class
  3. 43
      testData/results/TestPrimitives.dec
  4. 11
      testData/src/pkg/TestPrimitives.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;
}

@ -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

@ -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;
}
}

Loading…
Cancel
Save