diff --git a/guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ImmutableList.java b/guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ImmutableList.java index 7f7b72be38bd..6fddbedc9a33 100644 --- a/guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ImmutableList.java +++ b/guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ImmutableList.java @@ -29,6 +29,7 @@ import java.util.List; import java.util.RandomAccess; import java.util.stream.Collector; +import jsinterop.annotations.JsMethod; import org.checkerframework.checker.nullness.qual.Nullable; /** @@ -118,6 +119,12 @@ private static void arrayCopy(Object[] dest, int pos, Object... source) { System.arraycopy(source, 0, dest, pos, source.length); } + /** ImmutableList.of API that is friendly to use from JavaScript. */ + @JsMethod(name = "of") + static ImmutableList jsOf(E... elements) { + return copyOf(elements); + } + public static ImmutableList copyOf(Iterable elements) { checkNotNull(elements); // for GWT return (elements instanceof Collection) @@ -142,6 +149,7 @@ public static ImmutableList copyOf(Collection elements) { return copyFromCollection(elements); } + @JsMethod public static ImmutableList copyOf(E[] elements) { checkNotNull(elements); // eager for GWT return copyOf(Arrays.asList(elements)); diff --git a/guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ImmutableSet.java b/guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ImmutableSet.java index 6b7353176c23..a5ba12333ae1 100644 --- a/guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ImmutableSet.java +++ b/guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ImmutableSet.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.Set; import java.util.stream.Collector; +import jsinterop.annotations.JsMethod; /** * GWT emulated version of {@link com.google.common.collect.ImmutableSet}. For the unsorted sets, @@ -85,6 +86,13 @@ public static ImmutableSet of(E e1, E e2, E e3, E e4, E e5, E e6, E... ot return copyOf(all.iterator()); } + /** ImmutableSet.of API that is friendly to use from JavaScript. */ + @JsMethod(name = "of") + static ImmutableSet jsOf(E... elements) { + return copyOf(elements); + } + + @JsMethod public static ImmutableSet copyOf(E[] elements) { checkNotNull(elements); switch (elements.length) {