Skip to content

Commit 44b7d7c

Browse files
author
zhourenjian
committed
1. Fixing bug that Java2Script is not compatible with YUI or other JavaScript libraries on Object.prototype
2. Add System.currentMillionsecond 3. Packing SimpleStore 4. Packing JFace
1 parent ad9b155 commit 44b7d7c

File tree

9 files changed

+395
-20
lines changed

9 files changed

+395
-20
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,15 @@ Clazz.makeFunction = function (jsr) {
341341
jsr.setEvent (e);
342342
}
343343
jsr.run ();
344+
/*
344345
if (e != null && jsr.isReturned != null && jsr.isReturned()) {
345346
// Is it correct to stopPropagation here? --Feb 19, 2006
346347
e.cancelBubble = true;
347348
if (e.stopPropagation) {
348349
e.stopPropagation();
349350
}
350351
}
352+
*/
351353
if (jsr.returnSet == 1) {
352354
return jsr.returnNumber;
353355
} else if (jsr.returnSet == 2) {
@@ -674,11 +676,12 @@ Object.prototype.notify = function () {};
674676
Object.prototype.notifyAll = function () {};
675677
Object.prototype.wait = function () {};
676678

679+
Object.prototype.to$tring = Object.prototype.toString;
677680
Object.prototype.toString = function () {
678681
if (this.__CLASS_NAME__ != null) {
679682
return "[" + this.__CLASS_NAME__ + " object]";
680683
} else {
681-
return "[object]";
684+
return this.to$tring ();
682685
}
683686
};
684687

@@ -722,6 +725,9 @@ System = {
722725
}
723726
System.props.setProperty (key, val);
724727
},
728+
currentTimeMillis : function () {
729+
return new Date ().getTime ();
730+
},
725731
arraycopy : function (src, srcPos, dest, destPos, length) {
726732
if (src !== dest) {
727733
for (var i = 0; i < length; i++) {

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,16 @@ ClazzLoader.packageClasspath = function (pkg, base, index) {
480480
if (map[key] == null) {
481481
map[key] = base;
482482
}
483+
key = "@net.sf.j2s";
484+
if (map[key] == null) {
485+
map[key] = base;
486+
}
483487
} else if (pkg == "swt") { //abbrev
484488
pkg = "org.eclipse.swt";
485489
} else if (pkg == "ajax") { //abbrev
486490
pkg = "net.sf.j2s.ajax";
491+
} else if (pkg == "j2s") { //abbrev
492+
pkg = "net.sf.j2s";
487493
}
488494
if (pkg.lastIndexOf (".*") == pkg.length - 2) {
489495
pkg = pkg.substring (0, pkg.length - 2);
@@ -941,6 +947,7 @@ ClazzLoader.loadScript = function (file) {
941947
// ignore onload event and no call of ClazzLoader.scriptLoading
942948
return;
943949
}
950+
script.defer = true;
944951
// Alert when the script is loaded
945952
if (typeof (script.onreadystatechange) == "undefined" || !ClazzLoader.isIE) { // W3C
946953
if (ClazzLoader.isGecko && (file.indexOf ("file:") == 0
@@ -1040,7 +1047,6 @@ ClazzLoader.loadScript = function (file) {
10401047
}
10411048
} else { // IE
10421049
ClazzLoader.needOnloadCheck = true;
1043-
script.defer = true;
10441050
script.onreadystatechange = function () {
10451051
var ee = arguments.callee;
10461052
var path = ee.path;
@@ -2764,6 +2770,7 @@ ClazzLoader.lastHotspotJSFailed = false;
27642770
ClazzLoader.loadHotspotScript = function (hotspotURL, iframeID) {
27652771
var script = document.createElement ("SCRIPT");
27662772
script.type = "text/javascript";
2773+
script.defer = true;
27672774
script.src = hotspotURL;
27682775
if (typeof (script.onreadystatechange) == "undefined" || !ClazzLoader.isIE) { // W3C
27692776
script.onload = script.onerror = function () {

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,14 @@ if (!isDebugging) {
118118
"$.CompoundPipeSWTRequest"
119119
]);
120120
}
121-
121+
122+
ClazzLoader.jarClasspath (ClazzLoader.getClasspathFor ("net.sf.j2s.*") + "store.z.js", [
123+
"net.sf.j2s.store.IStore",
124+
"$.CookieStore",
125+
"$.XSSCookieStore",
126+
"$.SimpleStore"
127+
]);
128+
122129
ClazzLoader.jarClasspath (base + "lang/StringBuilder.z.js",
123130
["java.lang.AbstractStringBuilder", "$.StringBuilder"]);
124131
base = base.substring (0, base.lastIndexOf ("java/"));

sources/net.sf.j2s.java.core/src/java/util/Hashtable.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ public Object nextElement() {
6666
}
6767
};
6868

69-
/**
70-
* @j2sKeep
71-
*/
7269
private static <K, V> Entry<K, V> newEntry(K key, V value, int hash) {
7370
return new Entry<K, V>(key, value);
7471
}

sources/net.sf.j2s.java.org.eclipse.core.runtime/src/org/eclipse/core/runtime/Status.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
/**
1717
* A concrete status implementation, suitable either for
1818
* instantiating or subclassing.
19-
*
20-
* @j2sRequireImport org.eclipse.core.internal.runtime.Assert
2119
*/
2220
public class Status implements IStatus {
2321
/**
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/* private */
2+
window["org.eclipse.jface.registered"] = false;
3+
4+
Clazz.declarePackage ("org.eclipse.jface");
5+
6+
(function () {
7+
ClazzLoader.registerPackages ("org.eclipse.jface", [
8+
"action",
9+
"bindings",
10+
"bindings.keys",
11+
"bindings.keys.formatting",
12+
"commands",
13+
"contexts",
14+
"dialogs",
15+
"operation",
16+
"perference",
17+
"resource",
18+
"util",
19+
"viewers",
20+
"viewers.deffered",
21+
"window",
22+
"wizard"]);
23+
24+
var path = ClazzLoader.getClasspathFor ("org.eclipse.jface.*");
25+
26+
ClazzLoader.jarClasspath (path + "resource.z.js", [
27+
"org.eclipse.jface.resource.DataFormatException",
28+
"$.DeviceResourceDescriptor",
29+
"$.ColorDescriptor",
30+
"$.DeviceResourceException",
31+
"$.FontDescriptor",
32+
"$.ArrayFontDescriptor",
33+
"$.ImageDescriptor",
34+
"$.ImageDataImageDescriptor",
35+
"$.FileImageDescriptor",
36+
"$.DerivedImageDescriptor",
37+
"$.CompositeImageDescriptor",
38+
"$.ImageRegistry",
39+
"$.JFaceResources",
40+
"$.JFaceColors",
41+
"$.MissingImageDescriptor",
42+
"$.NamedFontDescriptor",
43+
"$.ResourceRegistry",
44+
"$.RGBColorDescriptor",
45+
"$.ColorRegistry",
46+
"$.FontRegistry",
47+
"$.ResourceManager",
48+
"$.AbstractResourceManager",
49+
"$.DeviceResourceManager",
50+
"$.LocalResourceManager",
51+
"$.StringConverter",
52+
"$.URLImageDescriptor"
53+
]);
54+
55+
ClazzLoader.jarClasspath (path + "util.z.js", [
56+
"org.eclipse.jface.util.Geometry",
57+
"$.ILogger",
58+
"$.IOpenEventListener",
59+
"$.IPropertyChangeListener",
60+
"$.ISafeRunnableRunner",
61+
"$.ListenerList",
62+
"$.OpenStrategy",
63+
"$.Policy",
64+
"$.PropertyChangeEvent",
65+
"$.SafeRunnable"
66+
]);
67+
68+
ClazzLoader.jarClasspath (path + "window.z.js", [
69+
"net.sf.j2s.ajax.AWindowDelegate",
70+
"$.AWindowRunnable",
71+
"org.eclipse.jface.operation.IRunnableContext",
72+
"$.IRunnableWithProgress",
73+
"$.IThreadListener",
74+
"org.eclipse.jface.window.IShellProvider",
75+
"$.SameShellProvider",
76+
"$.WindowManager",
77+
"$.Window"/*,
78+
"$.ApplicationWindow"*/
79+
]);
80+
81+
ClazzLoader.jarClasspath (path + "viewers.interfaces.z.js", [
82+
"org.eclipse.jface.viewers.IBaseLabelProvider",
83+
"$.IBasicPropertyConstants",
84+
"$.ICellEditorListener",
85+
"$.ICellEditorValidator",
86+
"$.ICellModifier",
87+
"$.ICheckable",
88+
"$.ICheckStateListener",
89+
"$.IColorDecorator",
90+
"$.IColorProvider",
91+
"$.IContentProvider",
92+
"$.IDecoration",
93+
"$.IDoubleClickListener",
94+
"$.IElementComparer",
95+
"$.IFilter",
96+
"$.IFontDecorator",
97+
"$.IFontProvider",
98+
"$.IInputProvider",
99+
"$.IInputSelectionProvider",
100+
"$.ILabelDecorator",
101+
"$.IDelayedLabelDecorator",
102+
"$.ILabelProvider",
103+
"$.ILabelProviderListener",
104+
"$.ILazyContentProvider",
105+
"$.ILightweightLabelDecorator",
106+
"$.IOpenListener",
107+
"$.ISelection",
108+
"$.ISelectionChangedListener",
109+
"$.ISelectionProvider",
110+
"$.IPostSelectionProvider",
111+
"$.IStructuredContentProvider",
112+
"$.IStructuredSelection",
113+
"$.ITableColorProvider",
114+
"$.ITableFontProvider",
115+
"$.ITableLabelProvider",
116+
"$.ITreeContentProvider",
117+
"$.ITreeViewerListener",
118+
"$.IViewerLabelProvider"
119+
]);
120+
}) ();
121+
122+
/* private */
123+
window["org.eclipse.jface.registered"] = true;

sources/net.sf.j2s.java.org.eclipse.jface/src/org/eclipse/jface/resource/ImageRegistry.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
* Unlike the FontRegistry, it is an error to replace images. As a result
4343
* there are no events that fire when values are changed in the registry
4444
* </p>
45-
*
46-
* @j2sRequireImport org.eclipse.jface.util.Assert
4745
*/
4846
public class ImageRegistry {
4947
/**

sources/net.sf.j2s.java.org.eclipse.jface/src/org/eclipse/jface/resource/ResourceManager.java

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
* </p>
3535
*
3636
* @since 3.1
37-
*
38-
* @j2sRequireImport java.util.ArrayList
3937
*/
4038
public abstract class ResourceManager {
4139

@@ -266,11 +264,20 @@ public void dispose() {
266264
public void disposeExec(Runnable r) {
267265
Assert.isNotNull(r);
268266

269-
if (disposeExecs == null) {
267+
if (disposeExecs == null)
268+
/**
269+
* @j2sNative
270+
* this.disposeExecs = new Array ();
271+
*/
272+
{
270273
disposeExecs = new ArrayList();
271274
}
272-
275+
/**
276+
* @j2sNative
277+
* this.disposeExecs[this.disposeExecs.length] = r;
278+
*/ {
273279
disposeExecs.add(r);
280+
}
274281
}
275282

276283
/**
@@ -287,10 +294,36 @@ public void cancelDisposeExec(Runnable r) {
287294
return;
288295
}
289296

297+
/**
298+
* @j2sNative
299+
* var empty = true;
300+
* var removed = false;
301+
* var length = this.disposeExecs.length;
302+
* for (var i = 0; i < length; i++) {
303+
* if (this.disposeExecs[i] === r) {
304+
* this.disposeExecs[i] = null;
305+
* removed = true;
306+
* if (!empty) {
307+
* break;
308+
* }
309+
* }
310+
* if (this.disposeExecs[i] != null) {
311+
* empty = false;
312+
* if (removed) {
313+
* break;
314+
* }
315+
* }
316+
* }
317+
* if (empty) {
318+
* this.disposeExecs = null;
319+
* }
320+
*/
321+
{
290322
disposeExecs.remove(r);
291323

292324
if (disposeExecs.isEmpty()) {
293325
disposeExecs = null;
294326
}
327+
}
295328
}
296329
}

0 commit comments

Comments
 (0)