diff --git a/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip b/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip index 70bf2283c..aee5d3835 100644 Binary files a/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip and b/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip differ diff --git a/sources/net.sf.j2s.java.core/src/test/Test_Error.java b/sources/net.sf.j2s.java.core/src/test/Test_Error.java index d9225edac..6322a0290 100644 --- a/sources/net.sf.j2s.java.core/src/test/Test_Error.java +++ b/sources/net.sf.j2s.java.core/src/test/Test_Error.java @@ -16,6 +16,23 @@ public static void main(String[] args) { boolean b = (e instanceof Error); System.out.println(b); } + + Throwable error = null; + /** @j2sNative error = new Error(); */ + assert error instanceof Throwable; + + Error x = new java.lang.Error(); + System.out.println(x.getMessage() + "??"); + + + Throwable typeError = null; + /** @j2sNative + * + * typeError = new TypeError(); */ + assert error instanceof Throwable; // pass + assert typeError instanceof Throwable; // fail + System.out.println(typeError.getStackTrace()); + System.out.println("Test_Error OK"); } diff --git a/sources/net.sf.j2s.java.core/src/test/Test_Inner.java b/sources/net.sf.j2s.java.core/src/test/Test_Inner.java index b49860805..bd5ebde92 100644 --- a/sources/net.sf.j2s.java.core/src/test/Test_Inner.java +++ b/sources/net.sf.j2s.java.core/src/test/Test_Inner.java @@ -78,6 +78,16 @@ public void testDollar(Test_Abstract_a abs) { } public static void main(String[] args) { + try { + Class t = Class.forName("test.Test_InnerAo$AiStat"); + System.out.println(t.getName() + " loaded"); + System.out.println(t.newInstance()); + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + assert(false); + } + Test_Inner inner = new Test_Inner(6) {}; try { System.out.println(inner.getClass().getMethod("testDollar", new Class[] {Test_Abstract_a.class}).getName()); diff --git a/sources/net.sf.j2s.java.core/src/test/Test_InnerAo.java b/sources/net.sf.j2s.java.core/src/test/Test_InnerAo.java index c3e021887..d2ce47f7c 100644 --- a/sources/net.sf.j2s.java.core/src/test/Test_InnerAo.java +++ b/sources/net.sf.j2s.java.core/src/test/Test_InnerAo.java @@ -28,7 +28,14 @@ public void run() { x.run(); } - class Ai { + + public static class AiStat { + public AiStat() { + System.out.println("loaded " + getClass().getName()); + } + } + + class Ai { public String atesti = "Ai"; diff --git a/sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js b/sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js index 006d39c76..d73eefe0a 100644 --- a/sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js +++ b/sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js @@ -1,5 +1,5 @@ // j2sClazz.js -// NOTE: updates to this file should be copies to j2sjmol.js +// NOTE: updates to this file should be copied to j2sjmol.js // latest author: Bob Hanson, St. Olaf College, hansonr@stolaf.edu @@ -7,6 +7,8 @@ // Google closure compiler cannot handle Clazz.new or Clazz.super +// BH 2022.09.20 fix for Class.forName not loading static inner classes directly +// BH 2022.09.20 fix for default toString for classes using "." name not "$" name for inner classes // BH 2022.09.15 fix for new Error() failing; just letting java.lang.Error subclass Throwable // BH 2022.09.08 Fix new Test_Inner().getClass().getMethod("testDollar", new Class[] {Test_Abstract_a.class}).getName() // BH 2022.04.19 TypeError and ResourceError gain printStackTrace$() methods @@ -1493,7 +1495,7 @@ var _jsid = 0; addProto(proto, "notifyAll$", function () {}); addProto(proto, "wait$", function () {alert("Object.wait was called!" + arguments.callee.caller.toString())}); addProto(proto, "toString$", Object.prototype.toString); - addProto(proto, "toString", function () { return (this.__CLASS_NAME__ ? "[" + this.__CLASS_NAME__ + " object]" : this.toString$.apply(this, arguments)); }); + addProto(proto, "toString", function () { return (this.__CLASS_NAME__ ? "[" + (this.__CLASS_NAME$__ || this.__CLASS_NAME__) + " object]" : this.toString$.apply(this, arguments)); }); })(Clazz._O.prototype); @@ -2632,7 +2634,8 @@ Clazz._4Name = function(clazzName, applet, state, asClazz, initialize, isQuiet) } if (!isok) { var name2 = null; - if (clazzName.indexOf("$") >= 0) { + var pt = clazzName.lastIndexOf("$"); + if (pt >= 0) { // BH we allow Java's java.swing.JTable.$BooleanRenderer as a stand-in // for java.swing.JTable.BooleanRenderer // when the static nested class is created using declareType @@ -2640,6 +2643,8 @@ Clazz._4Name = function(clazzName, applet, state, asClazz, initialize, isQuiet) if (Clazz._isClassDefined(name2)) { clazzName = name2; } else { + cl = Clazz._4Name(clazzName.substring(0, pt), applet, state, true, initialize, isQuiet); + cl && (clazzName = name2); name2 = null; } } @@ -6705,8 +6710,6 @@ var printStackTrace = function(e, ps) { } } -TypeError.prototype.printStackTrace$ = ReferenceError.prototype.printStackTrace$ = function() { console.log(this);printStackTrace(this,System.err) } - var C$ = Clazz.newClass(java.lang, "Throwable", function () { Clazz.newInstance(this, arguments); }, null, java.io.Serializable); @@ -6735,7 +6738,7 @@ this.detailMessage = (cause == null ? this.stack : cause.toString ()); this.cause = cause; }, 1); -m$(C$, 'getMessage$', function () {return this.message || this.detailMessage}); +m$(C$, 'getMessage$', function () {return this.message || this.detailMessage || null}); m$(C$, 'getLocalizedMessage$', function () { return this.getMessage$(); @@ -6917,11 +6920,17 @@ if(lineNum>=0){ }); -TypeError.prototype.getMessage$ || (TypeError.prototype.getMessage$ = TypeError.prototype.getLocalizedMessage$ +TypeError.prototype.getMessage$ || ( + + ReferenceError.prototype.getMessage$ = TypeError.prototype.getMessage$ + = ReferenceError.prototype.getMessage$ = TypeError.prototype.getLocalizedMessage$ = function(){ return (this.stack ? this.stack : this.message || this.toString()) + (this.getStackTrace ? this.getStackTrace$() : Clazz._getStackTrace())}); -TypeError.prototype.printStackTrace$ = function(){System.out.println(this + "\n" + this.stack)}; -TypeError.prototype.printStackTrace$java_io_PrintStream = function(stream){stream.println$S(this + "\n" + this.stack);}; -TypeError.prototype.printStackTrace$java_io_PrintWriter = function(printer){printer.println$S(this + "\n" + this.stack);}; + +TypeError.prototype.getStackTrace$ = ReferenceError.prototype.getStackTrace$ = function() { return Clazz._getStackTrace() } +TypeError.prototype.printStackTrace$ = ReferenceError.prototype.printStackTrace$ = function() { printStackTrace(this,System.err) } +ReferenceError.prototype.printStackTrace$java_io_PrintStream = TypeError.prototype.printStackTrace$java_io_PrintStream = function(stream){stream.println$S(this + "\n" + this.stack);}; +ReferenceError.prototype.printStackTrace$java_io_PrintWriter = TypeError.prototype.printStackTrace$java_io_PrintWriter = function(printer){printer.println$S(this + "\n" + this.stack);}; + Clazz.Error = Error; var declareType = function(prefix, name, clazzSuper, interfacez) { diff --git a/sources/net.sf.j2s.java.core/srcjs/swingjs2.js b/sources/net.sf.j2s.java.core/srcjs/swingjs2.js index a62e53c18..e7f00610e 100644 --- a/sources/net.sf.j2s.java.core/srcjs/swingjs2.js +++ b/sources/net.sf.j2s.java.core/srcjs/swingjs2.js @@ -14045,6 +14045,8 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) { // Google closure compiler cannot handle Clazz.new or Clazz.super +// BH 2022.09.20 fix for Class.forName not loading static inner classes directly +// BH 2022.09.20 fix for default toString for classes using "." name not "$" name for inner classes // BH 2022.09.15 fix for new Error() failing; just letting java.lang.Error subclass Throwable // BH 2022.09.08 Fix new Test_Inner().getClass().getMethod("testDollar", new Class[] {Test_Abstract_a.class}).getName() // BH 2022.04.19 TypeError and ResourceError gain printStackTrace$() methods @@ -15531,7 +15533,7 @@ var _jsid = 0; addProto(proto, "notifyAll$", function () {}); addProto(proto, "wait$", function () {alert("Object.wait was called!" + arguments.callee.caller.toString())}); addProto(proto, "toString$", Object.prototype.toString); - addProto(proto, "toString", function () { return (this.__CLASS_NAME__ ? "[" + this.__CLASS_NAME__ + " object]" : this.toString$.apply(this, arguments)); }); + addProto(proto, "toString", function () { return (this.__CLASS_NAME__ ? "[" + (this.__CLASS_NAME$__ || this.__CLASS_NAME__) + " object]" : this.toString$.apply(this, arguments)); }); })(Clazz._O.prototype); @@ -16670,7 +16672,8 @@ Clazz._4Name = function(clazzName, applet, state, asClazz, initialize, isQuiet) } if (!isok) { var name2 = null; - if (clazzName.indexOf("$") >= 0) { + var pt = clazzName.lastIndexOf("$"); + if (pt >= 0) { // BH we allow Java's java.swing.JTable.$BooleanRenderer as a stand-in // for java.swing.JTable.BooleanRenderer // when the static nested class is created using declareType @@ -16678,6 +16681,8 @@ Clazz._4Name = function(clazzName, applet, state, asClazz, initialize, isQuiet) if (Clazz._isClassDefined(name2)) { clazzName = name2; } else { + cl = Clazz._4Name(clazzName.substring(0, pt), applet, state, true, initialize, isQuiet); + cl && (clazzName = name2); name2 = null; } } @@ -20743,8 +20748,6 @@ var printStackTrace = function(e, ps) { } } -TypeError.prototype.printStackTrace$ = ReferenceError.prototype.printStackTrace$ = function() { console.log(this);printStackTrace(this,System.err) } - var C$ = Clazz.newClass(java.lang, "Throwable", function () { Clazz.newInstance(this, arguments); }, null, java.io.Serializable); @@ -20773,7 +20776,7 @@ this.detailMessage = (cause == null ? this.stack : cause.toString ()); this.cause = cause; }, 1); -m$(C$, 'getMessage$', function () {return this.message || this.detailMessage}); +m$(C$, 'getMessage$', function () {return this.message || this.detailMessage || null}); m$(C$, 'getLocalizedMessage$', function () { return this.getMessage$(); @@ -20955,11 +20958,17 @@ if(lineNum>=0){ }); -TypeError.prototype.getMessage$ || (TypeError.prototype.getMessage$ = TypeError.prototype.getLocalizedMessage$ +TypeError.prototype.getMessage$ || ( + + ReferenceError.prototype.getMessage$ = TypeError.prototype.getMessage$ + = ReferenceError.prototype.getMessage$ = TypeError.prototype.getLocalizedMessage$ = function(){ return (this.stack ? this.stack : this.message || this.toString()) + (this.getStackTrace ? this.getStackTrace$() : Clazz._getStackTrace())}); -TypeError.prototype.printStackTrace$ = function(){System.out.println(this + "\n" + this.stack)}; -TypeError.prototype.printStackTrace$java_io_PrintStream = function(stream){stream.println$S(this + "\n" + this.stack);}; -TypeError.prototype.printStackTrace$java_io_PrintWriter = function(printer){printer.println$S(this + "\n" + this.stack);}; + +TypeError.prototype.getStackTrace$ = ReferenceError.prototype.getStackTrace$ = function() { return Clazz._getStackTrace() } +TypeError.prototype.printStackTrace$ = ReferenceError.prototype.printStackTrace$ = function() { printStackTrace(this,System.err) } +ReferenceError.prototype.printStackTrace$java_io_PrintStream = TypeError.prototype.printStackTrace$java_io_PrintStream = function(stream){stream.println$S(this + "\n" + this.stack);}; +ReferenceError.prototype.printStackTrace$java_io_PrintWriter = TypeError.prototype.printStackTrace$java_io_PrintWriter = function(printer){printer.println$S(this + "\n" + this.stack);}; + Clazz.Error = Error; var declareType = function(prefix, name, clazzSuper, interfacez) {