Skip to content

Commit 943b0b1

Browse files
hansonrhansonr
authored andcommitted
transpiler fix for - negative constant
1 parent 02e3c28 commit 943b0b1

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

sources/net.sf.j2s.core/src/net/sf/j2s/core/Java2ScriptVisitor.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5230,16 +5230,19 @@ private boolean getConstantValue(Expression node, boolean andWrite) {
52305230
return false;
52315231
Object constValue = getConstant(node);
52325232
StringBuffer sb = null;
5233-
if (constValue != null
5234-
&& (constValue instanceof Number || constValue instanceof Character || constValue instanceof Boolean)) {
5233+
if (constValue instanceof Number) {
52355234
sb = new StringBuffer();
5236-
if (constValue instanceof Character) {
5235+
String s = constValue.toString();
5236+
if (s.startsWith("-") && buffer.charAt(buffer.length() - 1) == '-')
5237+
sb.append(' ');
5238+
sb.append(s);
5239+
} else if (constValue instanceof Character || constValue instanceof Boolean) {
5240+
sb = new StringBuffer();
5241+
if (constValue instanceof Character) {
52375242
sb.append('"');
52385243
addChar(((Character) constValue).charValue(), sb);
52395244
sb.append('"');
52405245
} else {
5241-
// Number or Boolean
5242-
52435246
sb.append(constValue);
52445247
}
52455248
} else if (constValue instanceof String) {

0 commit comments

Comments
 (0)