Skip to content

Commit bfe76f2

Browse files
committed
1. Add Class#getSimpleName
2. Break for infinite #getClass method 3. Remove compiler warnings
1 parent 469bf08 commit bfe76f2

File tree

6 files changed

+78
-5
lines changed

6 files changed

+78
-5
lines changed

sources/net.sf.j2s.java.core/src/java/lang/Character.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ public final class Character implements Serializable, Comparable<Character> {
8282
/**
8383
* The <code>char</code> {@link Class} object.
8484
*/
85-
@SuppressWarnings("unchecked")
8685
public static final Class<Character> TYPE = null;
8786

8887
private final char value;

sources/net.sf.j2s.java.core/src/java/lang/Class.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,26 @@ Clazz.getClassName = function (clazzHost) {
199199
return "Array";
200200
}
201201
}
202-
return Clazz.getClassName (obj.constructor, true);
202+
var depth = arguments[2];
203+
if (depth == null) {
204+
depth = 1;
205+
} else if (depth >= 4) {
206+
return "Object";
207+
}
208+
return Clazz.getClassName (obj.constructor, true, depth++);
203209
}
204210
} else if (objType == "number") {
205211
return "Number";
206212
} else if (objType == "boolean") {
207213
return "Boolean";
208214
}
209-
return Clazz.getClassName (obj.constructor, true);
215+
var depth = arguments[2];
216+
if (depth == null) {
217+
depth = 1;
218+
} else if (depth >= 4) {
219+
return "Object";
220+
}
221+
return Clazz.getClassName (obj.constructor, true, depth++);
210222
}
211223
}
212224
};
@@ -1586,7 +1598,7 @@ Clazz.instantialize = function (objThis, args) {
15861598
/* protected */
15871599
/*-# innerFunctionNames -> iFN #-*/
15881600
Clazz.innerFunctionNames = [
1589-
"equals", "hashCode", "toString", "getName", "getClassLoader", "getResourceAsStream" /*# {$no.javascript.support} >>x #*/, "defineMethod", "defineStaticMethod",
1601+
"equals", "hashCode", "toString", "getName", "getSimpleName", "getClassLoader", "getResourceAsStream" /*# {$no.javascript.support} >>x #*/, "defineMethod", "defineStaticMethod",
15901602
"makeConstructor" /*# x<< #*/
15911603
];
15921604

@@ -1616,6 +1628,17 @@ Clazz.innerFunctions = {
16161628
getName : function () {
16171629
return Clazz.getClassName (this, true);
16181630
},
1631+
// Similar to Class#getSimpleName
1632+
getSimpleName : function () {
1633+
var name = Clazz.getClassName (this, true);
1634+
if (name != null) {
1635+
var idx = name.lastIndexOf(".");
1636+
if (idx != -1) {
1637+
name = name.substring(idx + 1);
1638+
}
1639+
}
1640+
return name;
1641+
},
16191642

16201643
getClassLoader : function () {
16211644
var clazzName = this.__CLASS_NAME__;
@@ -1802,6 +1825,7 @@ Clazz.decorateFunction = function (clazzFun, prefix, name) {
18021825
/*
18031826
clazzFun.equals = Clazz.innerFunctions.equals;
18041827
clazzFun.getName = Clazz.innerFunctions.getName;
1828+
clazzFun.getSimpleName = Clazz.innerFunctions.getSimpleName;
18051829
clazzFun.getResourceAsStream = Clazz.innerFunctions.getResourceAsStream;
18061830
*/
18071831
var inF = Clazz.innerFunctionNames;

sources/net.sf.j2s.java.core/src/java/lang/ClassExt.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ Clazz.load = function (musts, clazz, optionals, declaration) {
642642
java.lang.Object = JavaObject;
643643

644644
JavaObject.getName = Clazz.innerFunctions.getName;
645+
JavaObject.getSimpleName = Clazz.innerFunctions.getSimpleName;
645646

646647
w$ = window; // Short for browser's window object
647648
d$ = document; // Short for browser's document object
@@ -1087,6 +1088,44 @@ Clazz.unloadClass = function (qClazzName) {
10871088
return false;
10881089
};
10891090

1091+
// Add support of parsing HTML and CSS with Java/JavaScript object bindings
1092+
1093+
/**
1094+
* Parse HTML and bind HTML elements to Java object's fields.
1095+
* {$:xxxx}<yyy /> or <!--$:xxxx--><yyy /> or <yyy id="$:xxxx" /> : Bind yyy element to Java objects' field #xxxx
1096+
* {$.xxxx} or <!--$.xxxx-->: Insert Java objects' field #xxxx as plain string to given position
1097+
* {$~xxxx} or <!--$~xxxx--> : Insert local variable as plain string to given position
1098+
* {$/} <!--$/--> : Insert current class path to given position
1099+
* {$#} <!--$#--> : Return elements in order within an array
1100+
*
1101+
* To be override: Java2Script compiler just compile HTML into this method without
1102+
* implementation. Different HTML/CSS toolkits can implement their own parser.
1103+
*/
1104+
/* public */
1105+
Clazz.parseHTML = function() {
1106+
if (arguments.length == 0) {
1107+
return null;
1108+
}
1109+
var html = arguments[arguments.length - 1];
1110+
};
1111+
1112+
/**
1113+
* Parse CSS with Java object's field values.
1114+
* {$.xxxx} or <!--$.xxxx--> : Insert Java objects' field #xxxx as plain string to given position
1115+
* {$~xxxx} or <!--$~xxxx--> : Insert local variable as plain string to given position
1116+
* {$/} or <!--$/--> : Insert current class path to given position
1117+
*
1118+
* To be override: Java2Script compiler just compile CSS into this method without
1119+
* implementation. Different HTML/CSS toolkits can implement their own parser.
1120+
*/
1121+
/* public */
1122+
Clazz.parseCSS = function() {
1123+
if (arguments.length == 0) {
1124+
return;
1125+
}
1126+
var css = arguments[arguments.length - 1];
1127+
};
1128+
10901129
//written by Dean Edwards, 2005
10911130
//with input from Tino Zijdel, Matthias Miller, Diego Perini
10921131

sources/net.sf.j2s.java.core/src/java/lang/ClassLoader.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,6 +2432,14 @@ ClazzLoader.getJ2SLibBase = function () {
24322432
if (idx != -1) {
24332433
return src.substring (0, idx);
24342434
}
2435+
idx = src.indexOf ("j2slib.src.z.js"); // consider it as key string!
2436+
if (idx != -1) {
2437+
return src.substring (0, idx);
2438+
}
2439+
idx = src.indexOf ("j2slib.swt.z.js"); // consider it as key string!
2440+
if (idx != -1) {
2441+
return src.substring (0, idx);
2442+
}
24352443
var base = ClazzLoader.classpathMap["@java"];
24362444
if (base != null) {
24372445
return base;

sources/net.sf.j2s.java.core/src/java/lang/StackTraceElement.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public StackTraceElement(String cls, String method, String file, int line) {
7373
* Private, nullary constructor for VM use only.
7474
* </p>
7575
*/
76+
@SuppressWarnings("unused")
7677
private StackTraceElement() {
7778
super();
7879
}

sources/net.sf.j2s.java.core/src/java/lang/Void.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package java.lang;
1919

20-
import java.lang.reflect.Method;
20+
//import java.lang.reflect.Method;
2121

2222
/**
2323
* This class is a placeholder class for the Java keyword <code>void</code>
@@ -34,6 +34,7 @@ public final class Void extends Object {
3434
// Note: This can't be set to "void.class", since *that* is
3535
// defined to be "java.lang.Void.TYPE";
3636

37+
/*
3738
@SuppressWarnings("unchecked")
3839
private static Class<Void> lookupType() {
3940
Class<?> voidType = null;
@@ -45,6 +46,7 @@ private static Class<Void> lookupType() {
4546
}
4647
return (Class<Void>) voidType;
4748
}
49+
// */
4850

4951
private Void() {
5052
}

0 commit comments

Comments
 (0)