Skip to content

Commit 16f4314

Browse files
hansonrhansonr
authored andcommitted
fixes 'c' | 'c'
1 parent 9d5ebbe commit 16f4314

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
import org.eclipse.jdt.core.dom.WhileStatement;
123123
import org.eclipse.jdt.core.dom.WildcardType;
124124

125+
// BH 7/5/2018 -- fixes int | char
125126
// BH 7/3/2018 -- adds tryWithResource
126127
// BH 7/3/2018 -- adds effectively final -- FINAL keyword no longer necessary
127128
// BH 6/27/2018 -- fix for a[Integer] not becoming a[Integer.valueOf]
@@ -2526,16 +2527,17 @@ public boolean visit(InfixExpression node) {
25262527
return false;
25272528
String leftName = leftTypeBinding.getName();
25282529
String rightName = rightTypeBinding.getName();
2529-
if ("/".equals(operator) && leftTypeBinding.isPrimitive() && isIntegerType(leftName)
2530-
&& isIntegerType(rightName)) {
2530+
boolean leftIsInt = leftTypeBinding.isPrimitive() && isIntegerType(leftName);
2531+
boolean rightIsInt = rightTypeBinding.isPrimitive() && isIntegerType(rightName);
2532+
if ("/".equals(operator) && leftIsInt && rightIsInt) {
25312533
// left and right are one of byte, short, int, or long
25322534
// division must take care of this.
25332535
addPrimitiveTypedExpression(left, null, leftName, operator, right, rightName, extendedOperands, false);
25342536
return false;
25352537
}
25362538

25372539
boolean toBoolean = "boolean".equals(expTypeName);
2538-
2540+
25392541
char pre = ' ';
25402542
char post = ' ';
25412543
if (isBitwise && toBoolean) {
@@ -2544,7 +2546,7 @@ && isIntegerType(rightName)) {
25442546
buffer.append("!!(");
25452547
}
25462548

2547-
boolean isDirect = isBitwise && !toBoolean;
2549+
boolean isDirect = isBitwise && !toBoolean && leftIsInt && rightIsInt;
25482550
if (isDirect || isComparison) {
25492551

25502552
// we do not have to do a full conversion
@@ -2585,8 +2587,14 @@ && isIntegerType(rightName)) {
25852587
}
25862588
}
25872589

2590+
boolean isToStringLeft = isToString && !isBitwise;
2591+
boolean isToStringRight = isToString && !isBitwise;
2592+
2593+
//String s = "e";
2594+
//s += 'c' | 'd';
2595+
25882596
// left
2589-
addOperand(left, isToString);
2597+
addOperand(left, isToString && !isBitwise);
25902598
buffer.append(' ');
25912599
// op
25922600
buffer.append(operator);
@@ -2596,7 +2604,7 @@ && isIntegerType(rightName)) {
25962604
}
25972605
buffer.append(' ');
25982606
// right
2599-
addOperand(right, isToString);
2607+
addOperand(right, isToString && !isBitwise);
26002608

26012609
// The extended operands is the preferred way of representing deeply
26022610
// nested expressions of the form L op R op R2 op R3... where the same

0 commit comments

Comments
 (0)