Thanks to visit codestin.com
Credit goes to github.com

Skip to content

from hansonr #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified sources/net.sf.j2s.java.core/dist/SwingJS-site.zip
Binary file not shown.
17 changes: 17 additions & 0 deletions sources/net.sf.j2s.java.core/src/test/Test_Error.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
10 changes: 10 additions & 0 deletions sources/net.sf.j2s.java.core/src/test/Test_Inner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
9 changes: 8 additions & 1 deletion sources/net.sf.j2s.java.core/src/test/Test_InnerAo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
29 changes: 19 additions & 10 deletions sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// 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, [email protected]

// NOTES by Bob Hanson

// 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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -2632,14 +2634,17 @@ 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
name2 = clazzName.replace(/\$/g,".");
if (Clazz._isClassDefined(name2)) {
clazzName = name2;
} else {
cl = Clazz._4Name(clazzName.substring(0, pt), applet, state, true, initialize, isQuiet);
cl && (clazzName = name2);
name2 = null;
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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$();
Expand Down Expand Up @@ -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) {
Expand Down
27 changes: 18 additions & 9 deletions sources/net.sf.j2s.java.core/srcjs/swingjs2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -16670,14 +16672,17 @@ 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
name2 = clazzName.replace(/\$/g,".");
if (Clazz._isClassDefined(name2)) {
clazzName = name2;
} else {
cl = Clazz._4Name(clazzName.substring(0, pt), applet, state, true, initialize, isQuiet);
cl && (clazzName = name2);
name2 = null;
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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$();
Expand Down Expand Up @@ -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) {
Expand Down