Skip to content

Commit b41968f

Browse files
gkdnGoogle Java Core Libraries
authored and
Google Java Core Libraries
committedJul 5, 2023
Under J2CL, expose {ImmutableList,ImmutableSet}.{of,copyOf} for JavaScript usage.
RELNOTES=`collect`: Under J2CL, exposed `ImmutableList` and `ImmutableSet` methods `copyOf` and `of` for JavaScript usage. PiperOrigin-RevId: 545771930
1 parent 31c478f commit b41968f

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed
 

‎guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ImmutableList.java

+8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.List;
3030
import java.util.RandomAccess;
3131
import java.util.stream.Collector;
32+
import jsinterop.annotations.JsMethod;
3233
import org.checkerframework.checker.nullness.qual.Nullable;
3334

3435
/**
@@ -118,6 +119,12 @@ private static void arrayCopy(Object[] dest, int pos, Object... source) {
118119
System.arraycopy(source, 0, dest, pos, source.length);
119120
}
120121

122+
/** ImmutableList.of API that is friendly to use from JavaScript. */
123+
@JsMethod(name = "of")
124+
static <E> ImmutableList<E> jsOf(E... elements) {
125+
return copyOf(elements);
126+
}
127+
121128
public static <E> ImmutableList<E> copyOf(Iterable<? extends E> elements) {
122129
checkNotNull(elements); // for GWT
123130
return (elements instanceof Collection)
@@ -142,6 +149,7 @@ public static <E> ImmutableList<E> copyOf(Collection<? extends E> elements) {
142149
return copyFromCollection(elements);
143150
}
144151

152+
@JsMethod
145153
public static <E> ImmutableList<E> copyOf(E[] elements) {
146154
checkNotNull(elements); // eager for GWT
147155
return copyOf(Arrays.asList(elements));

‎guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ImmutableSet.java

+8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.List;
2828
import java.util.Set;
2929
import java.util.stream.Collector;
30+
import jsinterop.annotations.JsMethod;
3031

3132
/**
3233
* GWT emulated version of {@link com.google.common.collect.ImmutableSet}. For the unsorted sets,
@@ -85,6 +86,13 @@ public static <E> ImmutableSet<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E... ot
8586
return copyOf(all.iterator());
8687
}
8788

89+
/** ImmutableSet.of API that is friendly to use from JavaScript. */
90+
@JsMethod(name = "of")
91+
static <E> ImmutableSet<E> jsOf(E... elements) {
92+
return copyOf(elements);
93+
}
94+
95+
@JsMethod
8896
public static <E> ImmutableSet<E> copyOf(E[] elements) {
8997
checkNotNull(elements);
9098
switch (elements.length) {

0 commit comments

Comments
 (0)
Please sign in to comment.