Skip to content

Commit ce385c6

Browse files
authored
Merge pull request #187 from BobHanson/hanson1
Hanson1
2 parents 8388836 + 8085808 commit ce385c6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2968
-1036
lines changed
437 KB
Binary file not shown.
336 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20201206115202
1+
20201219080050
437 KB
Binary file not shown.
336 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20201206115202
1+
20201219080050

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class CorePlugin extends Plugin {
3030
// if you change the x.x.x number, be sure to also indicate that in
3131
// j2sApplet.js and also (Bob only) update.bat, update-clean.bat
3232

33+
// BH 2020.12.14 -- 3.2.9-v1s fix for Boolean |= boolean and related boxing
3334
// BH 2020.12.06 -- 3.2.9-v1r fix for (long) double using |0
3435
// BH 2020.11.20 -- 3.2.9-v1q fix for new ImmutableCollections.ListN<>(E...) should use Object[]
3536
// BH 2020.08.03 -- 3.2.9-v1p fix for boxing boolean should be Boolean.valueOf$, not new Boolean

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

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135

136136
// TODO: superclass inheritance for JAXB XmlAccessorType
137137

138+
//BH 2020.12.14 -- 3.2.9-v1s fix for Boolean |= boolean and related boxing
138139
//BH 2020.12.06 -- 3.2.9-v1r fix for (long) double using |0
139140
//BH 2020.11.20 -- 3.2.9-v1q fix for new ImmutableCollections.ListN<>(E...) should use Object[]
140141
//BH 2020.08.03 -- 3.2.9-v1p fix for boxing boolean should be Boolean.valueOf$, not new Boolean
@@ -3189,6 +3190,7 @@ public boolean visit(Assignment node) {
31893190
IVariableBinding toBinding = getLeftVariableBinding(left, leftTypeBinding);
31903191
String op = node.getOperator().toString();
31913192
String opType = (op.length() == 1 ? null : op.substring(0, op.length() - 1));
3193+
31923194
boolean needNewStaticParenthesis = false;
31933195
boolean isParenthesized = (right instanceof ParenthesizedExpression);
31943196
// boolean haveDocRight = (getJ2sJavadoc(right, DOC_CHECK_ONLY) != null);
@@ -3206,12 +3208,14 @@ public boolean visit(Assignment node) {
32063208
if ("boolean".equals(leftName) && "boolean".equals(rightName)) {
32073209
if (("^=".equals(op))) {
32083210
opType = "!=";
3209-
} else {
3211+
} else if (opType == null) {
32103212
// all boolean should be OK -- no automatic here
32113213
left.accept(this);
3212-
buffer.append((opType == null ? "=" : op));
3214+
buffer.append("=");
32133215
right.accept(this);
32143216
leftName = null;
3217+
} else {
3218+
// a&=b -> !!(a&(b)) because both must execute
32153219
}
32163220
} else if (opType == null) {
32173221
// = operator is no problem
@@ -3234,11 +3238,13 @@ public boolean visit(Assignment node) {
32343238
else
32353239
left.accept(this);
32363240
int ptArray2 = (temp_processingArrayIndex ? buffer.length() : -1);
3241+
boolean leftIsString = leftName.equals("String");
3242+
boolean mustBoxAll = !(leftIsString || leftTypeBinding != null && leftTypeBinding.isPrimitive());
32373243
if (!"char".equals(leftName)) {
3238-
if (isIntegerType(leftName) || "boolean".equals(leftName)) {
3244+
if (isIntegerType(leftName) || "boolean".equals(leftName) || mustBoxAll) {
32393245
// can't just use a |= b because that ends up as 1 or 0, not true or false.
32403246
// byte|short|int|long += ...
3241-
if (!addPrimitiveTypedExpression(left, toBinding, leftName, opType, right, rightName, null, true))
3247+
if (!addPrimitiveTypedExpression(left, toBinding, leftName, opType, right, rightName, null, true, mustBoxAll ? leftTypeBinding : null))
32423248
ptArray = -1;
32433249
} else {
32443250
ptArray = -1;
@@ -3249,7 +3255,6 @@ public boolean visit(Assignment node) {
32493255
buffer.append(' ');
32503256
buffer.append(op);
32513257
buffer.append(' ');
3252-
boolean leftIsString = leftName.equals("String");
32533258
if ("char".equals(rightName)) {
32543259
if (right instanceof CharacterLiteral) {
32553260
// ... = 'c'
@@ -3443,7 +3448,7 @@ public boolean visit(CastExpression node) {
34433448
String nameFROM = expBinding.getName();
34443449
String nameTO = ((PrimitiveType) typeTO).getPrimitiveTypeCode().toString();
34453450
if (!nameTO.equals(nameFROM)) {
3446-
addPrimitiveTypedExpression(null, null, nameTO, null, expression, nameFROM, null, false);
3451+
addPrimitiveTypedExpression(null, null, nameTO, null, expression, nameFROM, null, false, null);
34473452
return false;
34483453
}
34493454
}
@@ -3600,7 +3605,7 @@ public boolean visit(InfixExpression node) {
36003605
if ("/".equals(operator) && leftIsInt && rightIsInt) {
36013606
// left and right are one of byte, short, int, or long
36023607
// division must take care of this.
3603-
addPrimitiveTypedExpression(left, null, leftName, operator, right, rightName, extendedOperands, false);
3608+
addPrimitiveTypedExpression(left, null, leftName, operator, right, rightName, extendedOperands, false, null);
36043609
return false;
36053610
}
36063611

@@ -4329,7 +4334,7 @@ private void addExpressionAsTargetType(Expression exp, Object targetType, String
43294334
if ((isNumeric || paramName.equals("char")) && !isBoxTyped(exp)) {
43304335
// using operator "m" to limit int application of $i$
43314336

4332-
addPrimitiveTypedExpression(null, null, paramName, op, exp, rightName, extendedOperands, false);
4337+
addPrimitiveTypedExpression(null, null, paramName, op, exp, rightName, extendedOperands, false, null);
43334338
} else {
43344339
// char f() { return Character }
43354340
// Character f() { return char }
@@ -4575,11 +4580,11 @@ private void addOperand(Expression exp, boolean isToString) {
45754580
* @param rightName
45764581
* @param extendedOperands
45774582
* @param isAssignment (+=, &=, etc)
4578-
* @param return true if is an assignment and a = (a op b) was
4579-
* used
4583+
* @param mustBoxAll Integer != b
4584+
* @return true if is an assignment and a = (a op b) was used
45804585
*/
45814586
private boolean addPrimitiveTypedExpression(Expression left, IVariableBinding assignmentBinding, String leftName,
4582-
String op, Expression right, String rightName, List<?> extendedOperands, boolean isAssignment) {
4587+
String op, Expression right, String rightName, List<?> extendedOperands, boolean isAssignment, ITypeBinding allBinding) {
45834588
// byte|short|int|long /= ...
45844589
// convert to proper number of bits
45854590

@@ -4589,6 +4594,9 @@ private boolean addPrimitiveTypedExpression(Expression left, IVariableBinding as
45894594

45904595
// a = ($b$[0] = a | right, $b$[0])
45914596

4597+
4598+
4599+
// also boolean |= boolean op will be !!|
45924600
String classIntArray = null;
45934601
String more = null, less = null;
45944602

@@ -4598,7 +4606,16 @@ private boolean addPrimitiveTypedExpression(Expression left, IVariableBinding as
45984606
boolean addParens = (op != "r" || fromChar || right instanceof ParenthesizedExpression);
45994607
boolean isDiv = "/".equals(op);
46004608
boolean toChar = false;
4609+
boolean isBoolean = false;
46014610
switch (leftName) {
4611+
case "Boolean":
4612+
isBoolean = true;
4613+
break;
4614+
case "boolean":
4615+
less = "!!(";
4616+
more = ")";
4617+
addParens = true;
4618+
break;
46024619
case "char":
46034620
if (!fromChar) {
46044621
prefix += "String.fromCharCode(";
@@ -4608,7 +4625,7 @@ private boolean addPrimitiveTypedExpression(Expression left, IVariableBinding as
46084625
toChar = true;
46094626
break;
46104627
default:
4611-
// double, float
4628+
// double, float, boxed
46124629
break;
46134630
case "long":
46144631
if (isDiv || !fromIntType) {
@@ -4655,6 +4672,8 @@ private boolean addPrimitiveTypedExpression(Expression left, IVariableBinding as
46554672
}
46564673
boolean wasArray = temp_processingArrayIndex;
46574674

4675+
4676+
46584677
if (isAssignment && left == null) {
46594678
buffer.append(op);
46604679
}
@@ -4670,11 +4689,23 @@ private boolean addPrimitiveTypedExpression(Expression left, IVariableBinding as
46704689
buffer.append("(");
46714690
}
46724691
if (left != null) {
4692+
46734693
// a += b
4694+
4695+
4696+
if (allBinding != null) {
4697+
// Boolean.from(!!(a | (b))
4698+
buffer.append(leftName + ".valueOf$" + getJSTypeCode(leftName.toLowerCase()))
4699+
.append(isBoolean ? "(!!(" : "(");
4700+
}
4701+
46744702
addFieldName(left, assignmentBinding);
46754703
buffer.append(op);
4676-
if (isAssignment)
4704+
4705+
if (isAssignment) {
46774706
buffer.append("(");
4707+
}
4708+
46784709
}
46794710
if (!appendBoxingNode(right, fromChar) && fromChar && !toChar) {
46804711
buffer.append(CHARCODEAT0);
@@ -4685,6 +4716,10 @@ private boolean addPrimitiveTypedExpression(Expression left, IVariableBinding as
46854716
if (left != null && isAssignment) {
46864717
buffer.append(")");
46874718
}
4719+
4720+
if (allBinding != null)
4721+
buffer.append(isBoolean ? "))" : ")");
4722+
46884723
if (classIntArray != null) {
46894724
// this is necessary because in JavaScript,
46904725
// a = new Int8Array(1)
@@ -5719,13 +5754,15 @@ private String getJSTypeCode(String className) {
57195754
return "Z";
57205755
case "byte":
57215756
return "B";
5757+
case "character":
57225758
case "char":
57235759
return "C";
57245760
case "double":
57255761
return "D";
57265762
case "float":
57275763
return "F";
5728-
case "int":
5764+
case "integer":
5765+
case "int":
57295766
return "I";
57305767
case "long":
57315768
return "J";

sources/net.sf.j2s.java.core/build-core-applet.xml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@
99
<echo>Deleting the site directory.</echo>
1010
<delete quiet="true" dir="site" />
1111
-->
12-
12+
13+
14+
<!-- non-Java resources to copy to site/swingjs/j2s -->
15+
<property name="resource.dir" value="resources" />
16+
17+
<!-- non-Java resources to copy to site/ -->
18+
<property name="site-resource.dir" value="site-resources" />
19+
1320
<echo>creating swingjs2.js</echo>
1421
<concat destfile="srcjs/swingjs2.js">
1522
<filelist dir="srcjs/js" files="jquery.js,j2sJQueryExt.js,j2sApplet.js,j2sClazz.js,SwingJSApplet.js" />
@@ -20,6 +27,26 @@
2027
<fileset dir="srcjs"/>
2128
</copy>
2229

30+
31+
<property name="site.dir" value="site" />
32+
<property name="j2s.dir" value="${site.dir}/swingjs/j2s" />
33+
34+
<!-- transfer resources -->
35+
36+
<echo> Copying ${resource.dir} files into ${j2s.dir} </echo>
37+
<copy todir="${j2s.dir}">
38+
<fileset dir="${resource.dir}" erroronmissingdir="false" >
39+
<include name="**/*"/>
40+
</fileset>
41+
</copy>
42+
43+
<echo> Copying ${site-resource.dir} files into ${site.dir} </echo>
44+
<copy todir="${site.dir}">
45+
<fileset dir="${site-resource.dir}" erroronmissingdir="false" >
46+
<include name="**/*"/>
47+
</fileset>
48+
</copy>
49+
2350
<!-- make core files -->
2451

2552
<echo>creating and compressing core files - warnings are OK; "does not exist" is trouble</echo>

sources/net.sf.j2s.java.core/build-site.xml

Lines changed: 0 additions & 93 deletions
This file was deleted.

0 commit comments

Comments
 (0)