Skip to content

Commit aabb248

Browse files
committed
Transpiler/runtime fix 3.2.5-v4
// BH 2019.12.15 3.2.5-v4 fix for <? extends Byte> not getting name for boxing // BH 2019.12.15 3.2.5-v4 fix for local class within anonymous class not getting name // BH 2019.12.12 3.2.5-v3 fix for enums == null in annotations // BH 2019.12.07 3.2.5-v3 fix for lambda expression with $$ must not be cached
1 parent 1180a34 commit aabb248

File tree

11 files changed

+52
-27
lines changed

11 files changed

+52
-27
lines changed
3.01 KB
Binary file not shown.
183 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20191214114427
1+
20191215102844
3.01 KB
Binary file not shown.
183 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20191214114427
1+
20191215102844

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public class CorePlugin extends Plugin {
2525
* "net.sf.j2s.core.jar" not "net.sf.j2s.core.3.2.5"
2626
*
2727
*/
28-
public static String VERSION = "3.2.5-v3";
28+
public static String VERSION = "3.2.5-v4";
29+
// BH 2019.12.15 -- 3.2.5-v4 fix for local class within anonymous class not getting name
2930
// BH 2019.12.12 -- 3.2.5-v3 fix for enums == null in annotations
3031
// BH 2019.12.06 -- 3.2.5-v2 fix for try(resources) not closing those
3132
// BH 2019.11.12 -- 3.2.5-v0 fix for string literals with \n \nn \nnn octals, but "use strict" does not allow for this.

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

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,11 @@
167167
// HashSet as the basis for the {a:a,b:this.$finals$.b} mapping listFinalVariables.
168168
// This fixed all of the stream issues. See Test_Local, Test_java8, Test_Class.
169169

170-
// BH 2019.12.07 3.2.5-v2 fix for lambda expression with $$ must not be cached
170+
// BH 2019.12.15 3.2.5-v4 fix for <? extends Byte> not getting name for boxing
171+
// BH 2019.12.15 3.2.5-v4 fix for local class within anonymous class not getting name
172+
// BH 2019.12.12 3.2.5-v3 fix for enums == null in annotations
173+
// BH 2019.12.07 3.2.5-v3 fix for lambda expression with $$ must not be cached
174+
// BH 2019.12.06 3.2.5-v2 fix for try(resources) not closing those
171175
// BH 2019.11.18 3.2.5-v0 fix for anonymous subclass of a local class not handling finals
172176
// BH 2019.11.18 3.2.5-v0 fix for main method that throws exception not generating html test
173177
// BH 2019.11.18 3.2.5-v0 fix for lambda expressions in classes with annotations
@@ -4437,12 +4441,18 @@ private boolean appendBoxingNode(ASTNode element, boolean toCharCode) {
44374441
// expression is the site of an unboxing conversion
44384442
ITypeBinding typeBinding = exp.resolveTypeBinding();
44394443
if (!typeBinding.isPrimitive()) {
4440-
String name = getJavaClassNameQualified(typeBinding);
4441-
name = (name.indexOf("Integer") >= 0 ? "int"
4442-
: name.indexOf("Character") >= 0 ? "char" : name.replace("java.lang.", "").toLowerCase());
44434444
buffer.append("(");
44444445
element.accept(this);
4445-
buffer.append(toCharCode && name == "char" ? ")" + CHARCODEAT0 : ")." + name + "Value$()");
4446+
if (toCharCode) {
4447+
String name = getJavaClassNameQualified(typeBinding);
4448+
if (toCharCode && name.length() == 0)
4449+
name = typeBinding.getKey();
4450+
if (name.indexOf("Character") >= 0) {
4451+
buffer.append(").intValue$()");
4452+
return true;
4453+
}
4454+
}
4455+
buffer.append(").valueOf()");
44464456
return true;
44474457
}
44484458
}
@@ -4495,11 +4505,22 @@ static String getJavaClassNameQualified(ITypeBinding binding) {
44954505

44964506
if (binding == null)
44974507
return null;
4498-
String binaryName = null, bindingKey;
4499-
if ((binding.isAnonymous() || binding.isLocal()) && (binaryName = binding.getBinaryName()) == null
4508+
String name = null, bindingKey;
4509+
if ((binding.isAnonymous() || binding.isLocal()) && (name = binding.getBinaryName()) == null
45004510
&& (bindingKey = binding.getKey()) != null)
4501-
binaryName = bindingKey.substring(1, bindingKey.length() - 1).replace('/', '.');
4502-
return (binaryName == null ? binding.getQualifiedName() : binaryName);
4511+
name = bindingKey.substring(1, bindingKey.length() - 1).replace('/', '.');
4512+
if (name == null) {
4513+
name = binding.getQualifiedName();
4514+
if (name.length() == 0) {
4515+
name = binding.getBinaryName();
4516+
if (name == null) {
4517+
System.out.println(">>name null?? bn=" + binding.getBinaryName() + " qn=" + binding.getQualifiedName() + " n=" + binding.getName() + " k=" +binding.getKey()
4518+
+ " isAnon" + binding.isAnonymous() + " " + binding.isLocal());
4519+
name = ""; // <? extends Byte>
4520+
}
4521+
}
4522+
}
4523+
return name;
45034524
}
45044525

45054526
private static String getJavaClassNameSuperNoBrackets(ITypeBinding typeBinding) {
@@ -4721,25 +4742,22 @@ String getFinalJ2SClassNameQualifier(Name methodQualifier, ITypeBinding declarin
47214742
* $I$[] dynamic class loading and interfaces, (but interfaces are handled
47224743
* differently).
47234744
*
4724-
* This is a temporary will fix and will fail if the program does not adhere to
4725-
* class/package-capitalization standards.
4726-
*
47274745
* @param packageName Java package name or "_"
47284746
* @param javaClassName
47294747
* @return array listing classes that need to be loaded in order
47304748
*/
47314749
private String getFinalInnerClassList(ITypeBinding javaClass, String javaClassName) {
4732-
if (javaClassName == null)
4750+
String packageName = getPackageName(javaClass);
4751+
if (javaClassName == null) {
47334752
javaClassName = getJavaClassNameQualified(javaClass);
4734-
// called by addClassOrInterface and getFinalClazzLoadI
4753+
System.out.println(">>jcn was null! " + javaClassName);
4754+
// } else if (javaClassName.length() == 0) {
4755+
// // local inner class within an anonymous class
4756+
// javaClassName = javaClass.getBinaryName();
4757+
}
47354758
if (javaClassName.indexOf("$lambda") >= 0)
47364759
return "'" + getFinalJ2SClassName(javaClassName, FINAL_RAW) + "'";
4737-
String name = removeBracketsAndFixNullPackageName(javaClassName);
4738-
String packageName = getPackageName(javaClass);
4739-
// if (name.indexOf(packageName) != 0) {
4740-
// dumpStack("???? packageName " + packageName + " " + name);
4741-
// }
4742-
name = name.substring(packageName.length() + 1);
4760+
String name = removeBracketsAndFixNullPackageName(javaClassName).substring(packageName.length() + 1);
47434761
String[] parts = name.split("\\.");
47444762
String s = packageName + "." + parts[0];
47454763
int len = parts.length;
@@ -5780,10 +5798,12 @@ private void addDummyClassForPackageOnlyFile() {
57805798
}
57815799

57825800
public boolean visit(AnnotationTypeDeclaration node) {
5801+
System.out.println(">>AnnotationTypeDecl " + node);
57835802
return false;
57845803
}
57855804

57865805
public boolean visit(AnnotationTypeMemberDeclaration node) {
5806+
System.out.println(">>AnnotationTypeMembDecl " + node);
57875807
return false;
57885808
}
57895809

3.01 KB
Binary file not shown.

sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77

88
// Google closure compiler cannot handle Clazz.new or Clazz.super
99

10-
// BH 2019.12.14 3.2.5.v2 Clazz._4Name initialization should be full static initialization
10+
// BH 2019.12.15 3.2.5.v4 Character.prototype.valueOf() missing
11+
// BH 2019.12.14 3.2.5.v3 Clazz._4Name initialization should be full static initialization
1112

12-
`// see earlier notes at net.sf.j2s.java.core.srcjs/js/devnotes.txt
13+
// see earlier notes at net.sf.j2s.java.core.srcjs/js/devnotes.txt
1314

1415
//window["j2s.object.native"] = true; // this is not an option
1516

@@ -4507,6 +4508,7 @@ C$.prototype.$c = function(){return this.value.charCodeAt(0)};
45074508
m$(C$,["c$", "c$$C"],
45084509
function(value){
45094510
this.value=value;
4511+
this.valueOf=function(){return value};
45104512
}, 1);
45114513

45124514
m$(C$,["charValue", "charValue$"],

0 commit comments

Comments
 (0)