Skip to content

Commit a5f217f

Browse files
committed
java.lang.Class implemented
1 parent 4aacb1b commit a5f217f

File tree

7 files changed

+81
-224
lines changed

7 files changed

+81
-224
lines changed

sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/ASTKeywordVisitor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ public boolean visit(ArrayCreation node) {
198198
ITypeBinding binding = node.resolveTypeBinding();
199199
if (inode == null) {
200200
buffer.append(ASTScriptVisitor.j2sGetArrayClass(binding, 0));
201+
buffer.append(", [");
201202
List<ASTNode> dim = node.dimensions();
202203
visitList(dim, ", ");
203204
for (int i = binding.getDimensions() - dim.size(); --i >= 0;)
@@ -214,6 +215,7 @@ public boolean visit(ArrayInitializer node) {
214215
//ITypeBinding binding = node.resolveTypeBinding();
215216
//int n = binding.getDimensions();
216217
buffer.append(ASTScriptVisitor.j2sGetArrayClass(node.resolveTypeBinding(), -1));
218+
buffer.append(", [");
217219
@SuppressWarnings("unchecked")
218220
List<ASTNode> expressions = node.expressions();
219221
visitList(expressions, ", ");

sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/ASTScriptVisitor.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,23 +2419,14 @@ public boolean visit(TypeLiteral node) {
24192419
Type type = node.getType();
24202420
ITypeBinding binding = type.resolveBinding();
24212421
if (type.isPrimitiveType()) {
2422-
String name = binding.getName();
24232422
// adds Integer.TYPE, Float.TYPE, etc.
2424-
buffer.append(getPrimitiveTYPE(name));
2425-
return false;
2423+
buffer.append(getPrimitiveTYPE(binding.getName()));
24262424
} else if (type instanceof ArrayType) {
24272425
buffer.append(j2sGetArrayClass(binding, 1));
2428-
return false;
24292426
} else {
2430-
String name = binding.getName();
2431-
if ("Object".equals(name) || "java.lang.Object".equals(name)) {
2432-
buffer.append("Clazz._O"); // BH was JavaObject, but that
2433-
// introduces a new top-level
2434-
// JavaScript object
2435-
return false;
2436-
}
2427+
// BH we are creating a new Class object around this class
2428+
buffer.append("Clazz.$newClass(" + Bindings.removeBrackets(binding.getQualifiedName()) + ")");
24372429
}
2438-
type.accept(this);
24392430
return false;
24402431
}
24412432

@@ -2615,16 +2606,15 @@ private void addCallInit() {
26152606
* faux class with the correct _paramType and __NDIM
26162607
*
26172608
* @param type
2618-
* @param dimFlag -1 : initialized depth; n > 0 uninitialized depth; 0: not necessary
2619-
*
2609+
* @param dimFlag -1 : initialized depth; n > 0 uninitialized depth as Clazz.arrayClass$; 0: not necessary
26202610
* @return JavaScript for array creation
26212611
*/
26222612
static String j2sGetArrayClass(ITypeBinding type, int dimFlag) {
26232613
ITypeBinding ebinding = type.getElementType();
26242614
String params = (ebinding.isPrimitive() ? getPrimitiveTYPE(ebinding.getName()) : Bindings.removeBrackets(ebinding.getQualifiedName()))
26252615
+ (dimFlag == 0 ? "" : ", " + dimFlag * type.getDimensions());
26262616
return (dimFlag > 0 ? "Clazz.arrayClass$(" + params + ")"
2627-
: " Clazz.newArray$(" + params + ", [");
2617+
: " Clazz.newArray$(" + params);
26282618
}
26292619

26302620
private static boolean isStatic(int modifiers) {

sources/net.sf.j2s.core/test/dev/js/j2sApplet.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1916,7 +1916,13 @@ J2S.Cache.put = function(filename, data) {
19161916
J2S._registerApplet(applet._id, applet);
19171917
try {
19181918
if (applet.__Info.main) {
1919-
Clazz._4Name(applet.__Info.main).main([]);
1919+
try{
1920+
var cl = Clazz._4Name(applet.__Info.main);
1921+
}catch(e) {
1922+
alert ("Java class " + applet.__Info.main + " was not found.");
1923+
return;
1924+
}
1925+
cl.$clazz$.main([]);
19201926
} else {
19211927
applet._newApplet(viewerOptions);
19221928
}

0 commit comments

Comments
 (0)