Skip to content

Commit fb48fc2

Browse files
author
pstockley
committed
Rebasing gwt-interop-utils on top of the just-released by Google jsinterop-base #3
1 parent b42eb48 commit fb48fc2

File tree

13 files changed

+55
-517
lines changed

13 files changed

+55
-517
lines changed

src/gwt/interop/utils/client/plainobjects/JsPlainObj.java

+12-14
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ of this software and associated documentation files (the "Software"), to deal
2626
import jsinterop.annotations.JsOverlay;
2727
import jsinterop.annotations.JsPackage;
2828
import jsinterop.annotations.JsType;
29+
import jsinterop.base.Js;
2930

3031
/**
3132
* This class represents a Plain Javascript Object i.e An object that
@@ -66,10 +67,7 @@ public class JsPlainObj {
6667
if (fieldName == null)
6768
fieldName = (String)f;
6869
else {
69-
if (f instanceof Integer)
70-
JsHelper.setObjectProperty(jsPlainObj, fieldName, ((Integer) f).intValue());
71-
else
72-
JsHelper.setObjectProperty(jsPlainObj, fieldName, f);
70+
Js.asPropertyMap(jsPlainObj).set(fieldName, f);
7371

7472
fieldName = null;
7573
}
@@ -88,7 +86,7 @@ public class JsPlainObj {
8886
*/
8987
@JsOverlay
9088
final public int getInt(String prop) {
91-
return JsHelper.getObjectIntProperty(this, prop);
89+
return Js.asPropertyMap(this).getAny(prop).asInt();
9290
}
9391

9492
/**
@@ -101,7 +99,7 @@ final public int getInt(String prop) {
10199
*/
102100
@JsOverlay
103101
final public double getDbl(String prop) {
104-
return JsHelper.getObjectProperty(this, prop);
102+
return Js.asPropertyMap(this).getAny(prop).asDouble();
105103
}
106104

107105
/**
@@ -114,7 +112,7 @@ final public double getDbl(String prop) {
114112
*/
115113
@JsOverlay
116114
final public boolean getBool(String prop) {
117-
return JsHelper.getObjectProperty(this, prop);
115+
return Js.asPropertyMap(this).getAny(prop).asBoolean();
118116
}
119117

120118
/**
@@ -127,7 +125,7 @@ final public boolean getBool(String prop) {
127125
*/
128126
@JsOverlay
129127
final public String getStr(String prop) {
130-
return JsHelper.getObjectProperty(this, prop);
128+
return Js.asPropertyMap(this).getAny(prop).asString();
131129
}
132130

133131
/**
@@ -141,7 +139,7 @@ final public String getStr(String prop) {
141139
*/
142140
@JsOverlay
143141
final public <O> O getObj(String prop) {
144-
return JsHelper.getObjectProperty(this, prop);
142+
return Js.uncheckedCast(Js.asPropertyMap(this).get(prop));
145143
}
146144

147145
/**
@@ -153,7 +151,7 @@ final public <O> O getObj(String prop) {
153151
*/
154152
@JsOverlay
155153
final public void set(String prop, int v) {
156-
JsHelper.setObjectProperty(this, prop, v);
154+
Js.asPropertyMap(this).set(prop, v);
157155
}
158156

159157
/**
@@ -165,7 +163,7 @@ final public void set(String prop, int v) {
165163
*/
166164
@JsOverlay
167165
final public void set(String prop, double v) {
168-
JsHelper.setObjectProperty(this, prop, v);
166+
Js.asPropertyMap(this).set(prop, v);
169167
}
170168

171169
/**
@@ -177,7 +175,7 @@ final public void set(String prop, double v) {
177175
*/
178176
@JsOverlay
179177
final public void set(String prop, boolean v) {
180-
JsHelper.setObjectProperty(this, prop, v);
178+
Js.asPropertyMap(this).set(prop, v);
181179
}
182180

183181
/**
@@ -189,7 +187,7 @@ final public void set(String prop, boolean v) {
189187
*/
190188
@JsOverlay
191189
final public void set(String prop, String v) {
192-
JsHelper.setObjectProperty(this, prop, v);
190+
Js.asPropertyMap(this).set(prop, v);
193191
}
194192

195193
/**
@@ -202,7 +200,7 @@ final public void set(String prop, String v) {
202200
*/
203201
@JsOverlay
204202
final public <V> void set(String prop, V v) {
205-
JsHelper.setObjectProperty(this, prop, v);
203+
Js.asPropertyMap(this).set(prop, v);
206204
}
207205

208206
@JsOverlay

src/gwt/interop/utils/server/collections/JavaArray.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public Array<T> concatValue(T a) {
4141
}
4242

4343
@Override
44-
public T get(int index) {
44+
public T getAt(int index) {
4545
return internalArray.get(index);
4646
}
4747

@@ -87,7 +87,7 @@ public void push(T[] value) {
8787
}
8888

8989
@Override
90-
public void set(int index, T value) {
90+
public void setAt(int index, T value) {
9191
internalArray.set(index, value);
9292
}
9393

@@ -316,15 +316,15 @@ public <A> A reduce(ReduceFullFn<A, T> fn, A initialValue) {
316316
@Override
317317
public <A> A reduceRight(ReduceFn<A, T> fn, A initialValue) {
318318
for(int i = internalArray.size() - 1; i >=0 ; i--) {
319-
initialValue = fn.doReduce(initialValue, get(i));
319+
initialValue = fn.doReduce(initialValue, getAt(i));
320320
}
321321
return initialValue;
322322
}
323323

324324
@Override
325325
public <A> A reduceRight(ReduceFullFn<A, T> fn, A initialValue) {
326326
for(int i = internalArray.size() - 1; i >=0 ; i--) {
327-
initialValue = fn.doReduce(initialValue, get(i), i, this);
327+
initialValue = fn.doReduce(initialValue, getAt(i), i, this);
328328
}
329329
return initialValue;
330330
}

src/gwt/interop/utils/server/collections/JavaLinkedArray.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public Array<T> concatValue(T a) {
3939
}
4040

4141
@Override
42-
public T get(int index) {
42+
public T getAt(int index) {
4343
return internalArray.get(index);
4444
}
4545

@@ -84,7 +84,7 @@ public void push(T[] value) {
8484
}
8585

8686
@Override
87-
public void set(int index, T value) {
87+
public void setAt(int index, T value) {
8888
internalArray.set(index, value);
8989
}
9090

src/gwt/interop/utils/server/collections/JavaStringMap.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import gwt.interop.utils.shared.collections.Array;
44
import gwt.interop.utils.shared.collections.StringMap;
5+
import jsinterop.base.JsPropertyMap;
56

67
import java.util.HashMap;
78
import java.util.Map;
@@ -15,6 +16,10 @@ public JavaStringMap() {
1516
internalMap = new HashMap<>();
1617
}
1718

19+
static JsPropertyMap<Object> of() {
20+
return new JavaStringMap<>();
21+
}
22+
1823
/**
1924
* Return the value with the supplied string key
2025
*
@@ -32,7 +37,7 @@ public T get(String key) {
3237
* @param key The key.
3338
* @param value The value to set
3439
*/
35-
public void put(String key, T value) {
40+
public void set(String key, T value) {
3641

3742
internalMap.put(key, value);
3843
}
@@ -42,7 +47,7 @@ public void put(String key, T value) {
4247
*
4348
* @param key The key of the value to remove
4449
*/
45-
public void remove(String key) {
50+
public void delete(String key) {
4651

4752
internalMap.remove(key);
4853
}
@@ -53,7 +58,7 @@ public void remove(String key) {
5358
* @param key The key to test
5459
* @return <code>true</code> if the key is set
5560
*/
56-
public boolean hasKey(String key) {
61+
public boolean has(String key) {
5762

5863
return internalMap.containsKey(key);
5964
}
@@ -118,6 +123,6 @@ public void forEach(StringMap.ForEachFn<T> forEachFn) {
118123
* @param toMerge The StringMap to merge
119124
*/
120125
public void merge(StringMap<T> toMerge) {
121-
toMerge.forEach((value, key, maps) -> put(key, value));
126+
toMerge.forEach((value, key, maps) -> set(key, value));
122127
}
123128
}

src/gwt/interop/utils/shared/JsHelper.java

-121
Original file line numberDiff line numberDiff line change
@@ -30,106 +30,6 @@ of this software and associated documentation files (the "Software"), to deal
3030
*/
3131
public class JsHelper {
3232

33-
/**
34-
* Set the given int property on a javascript object
35-
*
36-
* @param o The object.
37-
* @param p The property to set
38-
* @param v The value
39-
* @param <O> The type of object (Must be either annotated with JsType or be based on
40-
* JavaScriptObject
41-
*/
42-
public static native <O> void setObjectProperty(O o, String p, int v) /*-{
43-
o[p] = v;
44-
}-*/;
45-
46-
/**
47-
* Set the given double property on a javascript object
48-
*
49-
* @param o The object.
50-
* @param p The property to set
51-
* @param v The value
52-
* @param <O> The type of object (Must be either annotated with JsType or be based on
53-
* JavaScriptObject
54-
*/
55-
public static native <O> void setObjectProperty(O o, String p, double v)/*-{
56-
o[p] = v;
57-
}-*/;
58-
59-
/**
60-
* Set the given boolean property on a javascript object
61-
*
62-
* @param o The object.
63-
* @param p The property to set
64-
* @param v The value
65-
* @param <O> The type of object (Must be either annotated with JsType or be based on
66-
* JavaScriptObject
67-
*/
68-
public static native <O> void setObjectProperty(O o, String p, boolean v)/*-{
69-
o[p] = v;
70-
}-*/;
71-
72-
/**
73-
* Set the given property on a javascript object.
74-
*
75-
* @param o The object.
76-
* @param p The property to set
77-
* @param v The value
78-
* @param <O> The type of object (Must be either annotated with JsType or be based on
79-
* JavaScriptObject
80-
*/
81-
public static native <O> void setObjectProperty(O o, String p, Object v )/*-{
82-
o[p] = v;
83-
}-*/;
84-
85-
86-
/**
87-
* Retrieve an int property from a javascript object
88-
* @param o The object
89-
* @param p The property to get
90-
* @param <O> The type of object (Must be either annotated with JsType or be based on
91-
* JavaScriptObject
92-
* @return The integer value
93-
*/
94-
public static native <O> int getObjectIntProperty(O o, String p) /*-{
95-
return o[p];
96-
}-*/;
97-
98-
/**
99-
* Retrieve an object property from a javascript object
100-
*
101-
* @param o The object
102-
* @param p The property to get
103-
* @param <O> The type of object (Must be either annotated with JsType or be based on
104-
* JavaScriptObject
105-
* @param <R> The type of return object
106-
* @return The object value
107-
*/
108-
public static native <O, R> R getObjectProperty(O o, String p) /*-{
109-
return o[p];
110-
}-*/;
111-
112-
/**
113-
* Remove a property from a javascript object
114-
*
115-
* @param o The object
116-
* @param p The property to remove
117-
*/
118-
public static native void removeProperty(Object o, String p) /*-{
119-
delete o[p];
120-
}-*/;
121-
122-
/**
123-
* Returns is the specified property is defined on a javascript object
124-
*
125-
* @param o The object
126-
* @param p The property to test
127-
* @return true is the property exists
128-
*/
129-
public static native boolean hasProperty(Object o, String p) /*-{
130-
return o[p] !== undefined;
131-
}-*/;
132-
13333
/**
13434
* Returns is the specified property is defined as a function on a javascript object
13535
* @param o The object
@@ -216,25 +116,4 @@ public static native <R> R except(Object o, String[] exclude) /*-{
216116
217117
return out;
218118
}-*/;
219-
220-
/**
221-
* Perform an unsafe cast of an object
222-
*
223-
* @param o The object
224-
* @param <T> The type to cast to
225-
* @return The object cast to the specified type
226-
*/
227-
public static native <T> T unsafeCast(Object o) /*-{
228-
return o;
229-
}-*/;
230-
231-
/**
232-
* Perform an unsafe cast of an object into an int value
233-
*
234-
* @param o The object
235-
* @return The object cast to an int
236-
*/
237-
public static native int unsafeCastAsInt(Object o) /*-{
238-
return o;
239-
}-*/;
240119
}

0 commit comments

Comments
 (0)