X Tutup
Skip to content

Commit cbb1c29

Browse files
author
jossonsmith
committed
Fixed bug of cyclic dependency on generating Clazz.load (...)
Fixed bug of ClazzLoader
1 parent 614eeea commit cbb1c29

File tree

10 files changed

+117
-58
lines changed

10 files changed

+117
-58
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Java2Script Configuration
2-
#Thu Jul 13 21:43:16 CST 2006
2+
#Sun Jul 16 14:25:43 CST 2006
33
j2s.compiler.visitor=SWTScriptVisitor
44
j2s.abandoned.resources.list=bin/net/sf/j2s/java/core/CorePlugin.js,bin/net/sf/j2s/java/core/RegExCompress.js,bin/net/sf/j2s/java/core/Bundle2StringUtil.js
55
j2s.compiler.abbreviation=true

sources/net.sf.j2s.java.core/core-bare.j2s

Lines changed: 0 additions & 6 deletions
This file was deleted.

sources/net.sf.j2s.java.core/core-basic.j2s

Lines changed: 0 additions & 6 deletions
This file was deleted.

sources/net.sf.j2s.java.core/core-common.j2s

Lines changed: 0 additions & 6 deletions
This file was deleted.

sources/net.sf.j2s.java.core/core-error.j2s

Lines changed: 0 additions & 6 deletions
This file was deleted.

sources/net.sf.j2s.java.core/core-more.j2s

Lines changed: 0 additions & 6 deletions
This file was deleted.

sources/net.sf.j2s.java.core/core-util.j2s

Lines changed: 0 additions & 6 deletions
This file was deleted.

sources/net.sf.j2s.java.core/j2score/Class.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,7 @@ Clazz.declarePackage = function (pkgName) {
13211321
};
13221322

13231323
/* protected */
1324-
/*-# evalType -> eT #-*/
1324+
/*x-# evalType -> eT #-x*/
13251325
Clazz.evalType = function (typeStr, isQualified) {
13261326
//*
13271327
var idx = typeStr.lastIndexOf (".");
@@ -1496,10 +1496,22 @@ Clazz.innerFunctions = {
14961496
if (name.indexOf ('/') == 0) {
14971497
is.url = name.substring (1);
14981498
} else {
1499+
var clazzName = this.__CLASS_NAME__;
1500+
/*-# baseFolder -> bFr #-*/
14991501
var baseFolder = null;
1500-
var bins = Clazz.binaryFolders;
1501-
if (bins != null && bins.length != 0) {
1502-
baseFolder = bins[0];
1502+
if (window["ClazzLoader"] != null) {
1503+
baseFolder = ClazzLoader.getClasspathFor (clazzName);
1504+
var x = baseFolder.lastIndexOf (clazzName.replace (/\./g, "/"));
1505+
if (x != -1) {
1506+
baseFolder = baseFolder.substring (0, x);
1507+
} else {
1508+
baseFolder = null;
1509+
}
1510+
} else {
1511+
var bins = Clazz.binaryFolders;
1512+
if (bins != null && bins.length != 0) {
1513+
baseFolder = bins[0];
1514+
}
15031515
}
15041516
if (baseFolder == null || baseFolder.length == 0) {
15051517
baseFolder = "bin/";
@@ -1510,10 +1522,12 @@ Clazz.innerFunctions = {
15101522
if (lastChar != '/') {
15111523
baseFolder += "/";
15121524
}
1513-
if (baseFolder.indexOf ('/') == 0) {
1514-
baseFolder = baseFolder.substring (1);
1515-
}
1516-
var clazzName = this.__CLASS_NAME__;
1525+
/*
1526+
* FIXME: bug here for "/"
1527+
*/
1528+
//if (baseFolder.indexOf ('/') == 0) {
1529+
// baseFolder = baseFolder.substring (1);
1530+
//}
15171531
var idx = clazzName.lastIndexOf ('.');
15181532
if (idx == -1) {
15191533
is.url = baseFolder + name;

sources/net.sf.j2s.java.core/j2score/ClassLoader.js

Lines changed: 85 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* TODO:
2121
* Make optimization over class dependency tree.
2222
* Give more ways for the feedback of loading.
23+
* Use multiple SCRIPT tags so *.js can be downloaded asynchronously.
24+
* Use Class.for.... to load tabs.
2325
*/
2426

2527
/*-#
@@ -31,7 +33,7 @@
3133
/*-#
3234
# parents -> sp
3335
# musts -> sm
34-
# optionals -> so
36+
# xxxoptionals -> so
3537
# declaration -> dcl
3638
# optionalsLoaded -> oled
3739
#-*/
@@ -513,6 +515,9 @@ ClazzLoader.scriptCompleted = function (file) {};
513515
/* protected */
514516
ClazzLoader.globalLoaded = function () {};
515517

518+
/* protected */
519+
ClazzLoader.keepOnLoading = true;
520+
516521
/* private */
517522
/*-# mapPath2ClassNode -> p2node #-*/
518523
ClazzLoader.mapPath2ClassNode = new Object ();
@@ -525,6 +530,16 @@ ClazzLoader.xhrOnload = function (transport, file) {
525530
ClazzLoader.tryToLoadNext (file);
526531
} else {
527532
try {
533+
/*
534+
if (transport.responseText.length >= 2048) {
535+
//fileCount++;
536+
}
537+
if (file.indexOf ("examples") != -1) {
538+
} else {
539+
log (transport.responseText.length + "::" + file);
540+
}
541+
*/
542+
fileCount += transport.responseText.length;
528543
eval (transport.responseText);
529544
} catch (e) {
530545
alert ("[Java2Script] Script error: " + e.message);
@@ -611,9 +626,19 @@ ClazzLoader.loadScript = function (file) {
611626
}
612627
}
613628
};
614-
transport.send (null);
629+
try {
630+
transport.send (null);
631+
} catch (e) {
632+
alert ("[Java2Script] Loading file error: " + e.message);
633+
throw e;
634+
}
615635
} else {
616-
transport.send (null);
636+
try {
637+
transport.send (null);
638+
} catch (e) {
639+
alert ("[Java2Script] Loading file error: " + e.message);
640+
throw e;
641+
}
617642
ClazzLoader.xhrOnload (transport, file);
618643
}
619644
return ;
@@ -694,6 +719,31 @@ ClazzLoader.loadScript = function (file) {
694719
ClazzLoader.scriptLoading (file);
695720
};
696721

722+
/* public */
723+
ClazzLoader.loadCSS = function (cssName) {
724+
var cssKey = "";
725+
var idx = cssName.lastIndexOf (".");
726+
if (idx == -1) {
727+
cssKey = cssName + ".css";
728+
} else {
729+
cssKey = cssName.substring (idx + 1) + ".css";
730+
}
731+
var resLinks = document.getElementsByTagName ("LINK");
732+
for (var i = 0; i < resLinks.length; i++) {
733+
var cssPath = resLinks[i].href;
734+
if (cssPath.lastIndexOf (cssKey) == cssPath.length - cssKey.length) {
735+
return ;
736+
}
737+
}
738+
739+
/*-# cssLink -> rel #-*/
740+
var cssLink = document.createElement ("LINK");
741+
cssLink.rel = "stylesheet";
742+
var path = ClazzLoader.getClasspathFor (cssName);
743+
cssLink.href = path.substring (0, path.lastIndexOf (".js")) + ".css";
744+
document.getElementsByTagName ("HEAD")[0].appendChild (cssLink);
745+
};
746+
697747
/**
698748
* After class is loaded, this method will be executed to check whether there
699749
* are classes in the dependency tree that need to be loaded.
@@ -755,6 +805,9 @@ ClazzLoader.tryToLoadNext = function (file) {
755805
ClazzLoader.updateNode (node);
756806
}
757807
}
808+
if (!ClazzLoader.keepOnLoading) {
809+
return ;
810+
}
758811
var n = ClazzLoader.findNextMustClass (ClazzLoader.clazzTreeRoot,
759812
ClazzNode.STATUS_KNOWN);
760813
//alert ("next..." + n) ;
@@ -779,6 +832,8 @@ ClazzLoader.tryToLoadNext = function (file) {
779832
//log ("in optionals..." + n.name);
780833
ClazzLoader.loadClassNode (n);
781834
} else {
835+
//error ("no more optionals?");
836+
ClazzLoader.updateNode (node);
782837
ClazzLoader.globalLoaded ();
783838
//error ("no optionals?");
784839
}
@@ -827,9 +882,11 @@ ClazzLoader.updateNode = function (node) {
827882
if (nn.status != ClazzNode.STATUS_OPTIONALS_LOADED
828883
&& nn != n) {
829884
nn.status = n.status;
885+
nn.declaration = null;
830886
ClazzLoader.updateNode (nn);
831887
}
832888
}
889+
n.declaration = null;
833890
}
834891
} else {
835892
isMustsOK = false;
@@ -887,24 +944,36 @@ ClazzLoader.updateNode = function (node) {
887944
}
888945
var level = ClazzNode.STATUS_DECLARED;
889946
var isOptionsOK = false;
890-
if (node.optionals == null || node.optionals.length == 0
947+
if (((node.optionals == null || node.optionals.length == 0)
948+
&& (node.musts == null || node.musts.length == 0))
891949
|| node.declaration == null) {
892950
isOptionsOK = true;
893951
} else {
894952
isOptionsOK = true;
895-
for (var i = 0; i < node.optionals.length; i++) {
896-
var n = node.optionals[i];
953+
for (var i = 0; i < node.musts.length; i++) {
954+
var n = node.musts[i];
897955
if (n.status < ClazzNode.STATUS_OPTIONALS_LOADED) {
898956
isOptionsOK = false;
899957
}
900958
}
959+
if (isOptionsOK) {
960+
for (var i = 0; i < node.optionals.length; i++) {
961+
var n = node.optionals[i];
962+
if (n.status < ClazzNode.STATUS_OPTIONALS_LOADED) {
963+
isOptionsOK = false;
964+
}
965+
}
966+
}
901967
}
902968
if (isOptionsOK) {
903969
level = ClazzNode.STATUS_OPTIONALS_LOADED;
904970
node.status = level;
905971
ClazzLoader.scriptCompleted (node.path);
906972
if (node.optionalsLoaded != null) {
907973
node.optionalsLoaded ();
974+
if (!ClazzLoader.keepOnLoading) {
975+
return false;
976+
}
908977
}
909978
/*
910979
* For those classes within one *.js file, update
@@ -915,10 +984,15 @@ ClazzLoader.updateNode = function (node) {
915984
var list = node.declaration.clazzList;
916985
for (var j = 0; j < list.length; j++) {
917986
var nn = list[j];
918-
if (nn.status != ClazzNode.level && nn != node) {
987+
if (nn.status != level && nn != node) {
988+
nn.status = level;
989+
nn.declaration = null;
919990
ClazzLoader.scriptCompleted (nn.path);
920991
if (nn.optionalsLoaded != null) {
921992
nn.optionalsLoaded ();
993+
if (!ClazzLoader.keepOnLoading) {
994+
return false;
995+
}
922996
}
923997
}
924998
}
@@ -1250,6 +1324,7 @@ ClazzLoader.queueBeforeString = new Array ();
12501324
*/
12511325
/* public */
12521326
ClazzLoader.loadClass = function (name, optionalsLoaded) {
1327+
ClazzLoader.keepOnLoading = true;
12531328
if (!ClazzLoader.isClassDefined ("java.lang.String")
12541329
&& name.indexOf ("java.") != 0) {
12551330
var qbs = ClazzLoader.queueBeforeString;
@@ -1282,7 +1357,10 @@ ClazzLoader.loadClass = function (name, optionalsLoaded) {
12821357
ClazzLoader.loadScript (n.path);
12831358
}
12841359
}
1360+
} else if (optionalsLoaded != null && ClazzLoader.isClassDefined (name)) {
1361+
optionalsLoaded ();
12851362
}
1363+
12861364
};
12871365

12881366
/**

sources/net.sf.j2s.java.core/src/java/package.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,14 @@
5151
"$.SubList"
5252
]);
5353

54-
ClazzLoader.jarClasspath (path + "j2slib.common.z.js", [
54+
ClazzLoader.jarClasspath (path + "core.z.js", [
5555
"java.io.Serializable",
5656
"java.lang.CharSequence",
5757
"$.Cloneable",
5858
"$.Comparable",
5959
"$.Runnable",
60-
"java.util.Comparator"
61-
]);
62-
63-
ClazzLoader.jarClasspath (path + "j2slib.basic.z.js", [
60+
"java.util.Comparator",
61+
6462
"java.lang.Number",
6563
"$.Integer",
6664
"$.Long",
@@ -80,7 +78,12 @@
8078
"$.Set",
8179
"$.Map",
8280
"$.List",
83-
"$.RandomAccess"
81+
"$.RandomAccess",
82+
83+
"net.sf.j2s.ajax.HttpRequest",
84+
"$.IXHRCallback",
85+
"$.XHRCallbackAdapter",
86+
"$.XHRCallbackSWTAdapter"
8487
]);
8588

8689
ClazzLoader.loadClass ("java.lang.Encoding");

0 commit comments

Comments
 (0)
X Tutup