Skip to content

Commit 0c88387

Browse files
hansonrhansonr
authored andcommitted
Transpiler fix
//BH 2020.08.03 -- 3.2.9-v1p fix for boxing boolean should be Boolean.valueOf$, not new Boolean
1 parent 083df6d commit 0c88387

File tree

2 files changed

+33
-32
lines changed

2 files changed

+33
-32
lines changed

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
@@ -31,6 +31,7 @@ public class CorePlugin extends Plugin {
3131
// j2sApplet.js and also (Bob only) update.bat, update-clean.bat
3232

3333

34+
// BH 2020.08.03 -- 3.2.9-v1p fix for boxing boolean should be Boolean.valueOf$, not new Boolean
3435
// BH 2020.08.01 -- 3.2.9-v1o fix for lambda expressions too static
3536
// BH 2020.07.08 -- 3.2.9-v1n fix for try with resources and adds option varOrLet
3637
// BH 2020.07.04 -- 3.2.9.v1m fix for X.super.y() in anonymous class

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

Lines changed: 32 additions & 32 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.08.03 -- 3.2.9-v1p fix for boxing boolean should be Boolean.valueOf$, not new Boolean
138139
//BH 2020.08.01 -- 3.2.9-v1o fix for lambda expressions too static
139140
//BH 2020.07.08 -- 3.2.9-v1n fix for try with resources and adds option varOrLet
140141
//BH 2020.07.04 -- 3.2.9-v1m fix for X.super.y() in anonymous class
@@ -4835,10 +4836,17 @@ private boolean appendBoxingNode(ASTNode element, boolean toCharCode) {
48354836
ITypeBinding typeBinding = exp.resolveTypeBinding();
48364837
if (typeBinding.isPrimitive()) {
48374838
String name = typeBinding.getName();
4838-
name = (name.equals("char") ? "Character"
4839-
: name.equals("int") ? "Integer"
4840-
: Character.toUpperCase(name.charAt(0)) + name.substring(1));
4841-
buffer.append("new " + name + "(");
4839+
String t = getJSTypeCode(name);
4840+
switch (name) {
4841+
case "char":
4842+
name = "Character";break;
4843+
case "int":
4844+
name = "Integer";break;
4845+
default:
4846+
name = Character.toUpperCase(name.charAt(0)) + name.substring(1);
4847+
break;
4848+
}
4849+
buffer.append(name + ".valueOf$" + t + "(");
48424850
element.accept(this);
48434851
buffer.append(")");
48444852
return true;
@@ -5681,48 +5689,40 @@ private String j2sGetParamCode(ITypeBinding binding) {
56815689
// as well.
56825690
// NOTE: These are the same as standard Java Spec, with the exception of
56835691
// Short, which is "H" instead of "S"
5692+
name = getJSTypeCode(name);
5693+
if (arrays != null) {
5694+
arrays = arrays.replaceAll("\\[\\]", "A");
5695+
name += arrays;
5696+
}
5697+
return name;
5698+
}
56845699

5685-
switch (name) {
5700+
private String getJSTypeCode(String className) {
5701+
switch (className) {
56865702
case "boolean":
5687-
name = "Z";
5688-
break;
5703+
return "Z";
56895704
case "byte":
5690-
name = "B";
5691-
break;
5705+
return "B";
56925706
case "char":
5693-
name = "C";
5694-
break;
5707+
return "C";
56955708
case "double":
5696-
name = "D";
5697-
break;
5709+
return "D";
56985710
case "float":
5699-
name = "F";
5700-
break;
5711+
return "F";
57015712
case "int":
5702-
name = "I";
5703-
break;
5713+
return "I";
57045714
case "long":
5705-
name = "J";
5706-
break;
5715+
return "J";
57075716
case "short":
5708-
name = "H"; // differs from Java Spec so we can use S for String
5709-
break;
5717+
return "H"; // differs from Java Spec so we can use S for String
57105718
case "java.lang.Object":
57115719
case "Object":
5712-
name = "O";
5713-
break;
5720+
return "O";
57145721
case "java.lang.String":
5715-
name = "S";
5716-
break;
5722+
return "S";
57175723
default:
5718-
name = stripJavaLang(NameMapper.checkClassReplacement(name)).replace('.', '_');
5719-
break;
5720-
}
5721-
if (arrays != null) {
5722-
arrays = arrays.replaceAll("\\[\\]", "A");
5723-
name += arrays;
5724+
return stripJavaLang(NameMapper.checkClassReplacement(className)).replace('.', '_');
57245725
}
5725-
return name;
57265726
}
57275727

57285728
/**

0 commit comments

Comments
 (0)