diff --git a/dev/core/src/com/google/gwt/dev/javac/testing/impl/JavaResourceBase.java b/dev/core/src/com/google/gwt/dev/javac/testing/impl/JavaResourceBase.java index fdec1b1e4d..e4fe4fea2c 100644 --- a/dev/core/src/com/google/gwt/dev/javac/testing/impl/JavaResourceBase.java +++ b/dev/core/src/com/google/gwt/dev/javac/testing/impl/JavaResourceBase.java @@ -82,6 +82,7 @@ public class JavaResourceBase { "public interface CharSequence {", " char charAt(int index);", " int length();", + " default boolean isEmpty() { return length() == 0; }", " String toString();", "}"); @@ -345,7 +346,6 @@ public class JavaResourceBase { " }", " private native boolean equals(String obj) /*-{ return false; }-*/;", " public boolean equalsIgnoreCase(String str) { return false; }", - " public native boolean isEmpty() /*-{ return true; }-*/;", " public int length() { return 0; }", " public static String valueOf(int i) { return \"\" + i; }", " public static String valueOf(char c) { return \"\" + c; }", diff --git a/tools/api-checker/config/gwt212_213userapi.conf b/tools/api-checker/config/gwt212_213userapi.conf index 1c09dc5145..b43799d894 100644 --- a/tools/api-checker/config/gwt212_213userapi.conf +++ b/tools/api-checker/config/gwt212_213userapi.conf @@ -156,6 +156,8 @@ java.lang.Deprecated MISSING java.lang.FunctionalInterface MISSING java.lang.Override MISSING java.lang.SafeVarargs MISSING +# Moved to CharSequence as a default method +java.lang.String::isEmpty() MISSING java.lang.SuppressWarnings MISSING java.lang.annotation.AnnotationTypeMismatchException MISSING java.lang.annotation.Documented MISSING diff --git a/user/super/com/google/gwt/emul/java/lang/CharSequence.java b/user/super/com/google/gwt/emul/java/lang/CharSequence.java index 560bd9f875..e4a01f1f4b 100644 --- a/user/super/com/google/gwt/emul/java/lang/CharSequence.java +++ b/user/super/com/google/gwt/emul/java/lang/CharSequence.java @@ -58,6 +58,38 @@ public boolean hasNext() { }, Spliterator.SIZED | Spliterator.SUBSIZED | Spliterator.ORDERED, false); } + default IntStream codePoints() { + return StreamSupport.intStream(() -> { + PrimitiveIterator.OfInt it = new PrimitiveIterator.OfInt() { + int cursor; + + @Override + public int nextInt() { + checkElement(hasNext()); + int codePoint = CharSequence.this.toString().codePointAt(cursor++); + if (codePoint >= 1 << 16) { + cursor++; + } + return codePoint; + } + + @Override + public boolean hasNext() { + return cursor < length(); + } + }; + return Spliterators.spliterator(it, length(), Spliterator.ORDERED); + }, Spliterator.SIZED | Spliterator.SUBSIZED | Spliterator.ORDERED, false); + } + + default boolean isEmpty() { + return length() == 0; + } + + static int compare(CharSequence cs1, CharSequence cs2) { + return cs1.toString().compareTo(cs2.toString()); + } + // CHECKSTYLE_OFF: Utility methods. @JsMethod static boolean $isInstance(HasCharSequenceTypeMarker instance) { diff --git a/user/super/com/google/gwt/emul/java/lang/String.java b/user/super/com/google/gwt/emul/java/lang/String.java index 693f53bdc7..5d7f6c25c9 100644 --- a/user/super/com/google/gwt/emul/java/lang/String.java +++ b/user/super/com/google/gwt/emul/java/lang/String.java @@ -27,11 +27,14 @@ import java.nio.charset.Charset; import java.nio.charset.UnsupportedCharsetException; import java.util.Comparator; +import java.util.List; import java.util.Locale; import java.util.Spliterator; import java.util.Spliterators; import java.util.StringJoiner; import java.util.function.Consumer; +import java.util.function.Function; +import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; import javaemul.internal.ArrayHelper; @@ -488,10 +491,6 @@ public String intern() { return checkNotNull(this); } - public boolean isEmpty() { - return length() == 0; - } - public int lastIndexOf(int codePoint) { return lastIndexOf(fromCodePoint(codePoint)); } @@ -791,6 +790,10 @@ public String repeat(int count) { return asNativeString().repeat(count); } + public R transform(Function f) { + return f.apply(this); + } + private int getLeadingWhitespaceLength() { int length = length(); for (int i = 0; i < length; i++) { @@ -811,6 +814,131 @@ private int getTrailingWhitespaceLength() { return length; } + public String indent(int spaces) { + if (isEmpty()) { + return ""; + } + Stream indentedLines; + if (spaces >= 0) { + String spaceString = " ".repeat(spaces); + indentedLines = lines().map(line -> spaceString + line); + } else { + indentedLines = lines().map( + line -> line.substring(Math.min(-spaces, line.getLeadingWhitespaceLength()))); + } + return indentedLines.collect(Collectors.joining("\n", "", "\n")); + } + + public String stripIndent() { + if (isEmpty()) { + return ""; + } + List lines = lines().collect(Collectors.toList()); + int minIndent; + char lastChar = charAt(length() - 1); + String suffix = ""; + if (lastChar != '\r' && lastChar != '\n') { + minIndent = Integer.MAX_VALUE; + for (int i = 0; i < lines.size() - 1; i++) { + String line = lines.get(i); + int leadingWhitespace = line.getLeadingWhitespaceLength(); + // only update minIndent if not blank + if (leadingWhitespace < line.length()) { + minIndent = Math.min(minIndent, leadingWhitespace); + } + } + // the last line affects minIndent even if blank + minIndent = Math.min(minIndent, lines.get(lines.size() - 1).getLeadingWhitespaceLength()); + } else { + suffix = "\n"; + minIndent = 0; + } + final int outdent = minIndent; + return lines.stream().map(line -> { + if (line.isBlank()) { + return ""; + } + return line.substring(outdent).stripTrailing(); + }) + .collect(Collectors.joining("\n", "", suffix)); + } + + public String translateEscapes() { + StringBuilder result = new StringBuilder(); + int translated = 0; + while (translated < length()) { + int nextBackslash = indexOf("\\", translated); + if (nextBackslash == -1) { + result.append(substring(translated)); + return result.toString(); + } + if (nextBackslash == length() - 1) { + throw new IllegalArgumentException(); + } + result.append(substring(translated, nextBackslash)); + char currentChar = charAt(nextBackslash + 1); + translated = nextBackslash + 2; + switch (currentChar) { + case 'b': + result.append('\b'); + break; + case 's': + result.append(' '); + break; + case 't': + result.append('\t'); + break; + case 'n': + result.append('\n'); + break; + case 'f': + result.append('\f'); + break; + case 'r': + result.append('\r'); + break; + case '\n': + // discard + break; + case '\r': + // discard \r and possibly \n that comes right after + if (translated < length() && charAt(translated) == '\n') { + translated++; + } + break; + case '"': + result.append('"'); + break; + case '\'': + result.append('\''); + break; + case '\\': + result.append('\\'); + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + int unicode = currentChar - '0'; + char nextChar = charAt(translated); + while (nextChar >= '0' && nextChar < '8' && unicode < 32) { + unicode = (unicode << 3) + (nextChar - '0'); + translated++; + nextChar = translated < length() ? charAt(translated) : 0; + } + result.append((char) unicode); + break; + default: + throw new IllegalArgumentException(); + } + } + return result.toString(); + } + private class LinesSpliterator extends Spliterators.AbstractSpliterator { private int nextIndex = 0; private int rPosition = -1; diff --git a/user/super/com/google/gwt/emul/java/util/BitSet.java b/user/super/com/google/gwt/emul/java/util/BitSet.java index ea8a087c5b..1fa15d5567 100644 --- a/user/super/com/google/gwt/emul/java/util/BitSet.java +++ b/user/super/com/google/gwt/emul/java/util/BitSet.java @@ -18,6 +18,9 @@ import static javaemul.internal.InternalPreconditions.checkArraySize; +import java.util.function.IntConsumer; +import java.util.stream.IntStream; +import java.util.stream.StreamSupport; import javaemul.internal.ArrayHelper; import javaemul.internal.LongUtils; @@ -37,6 +40,37 @@ public class BitSet { private final int[] array; + private class BitSetSpliterator implements Spliterator.OfInt { + int nextBitIndex = 0; + + @Override + public boolean tryAdvance(IntConsumer action) { + int nextBit = nextSetBit(nextBitIndex); + if (nextBit >= 0) { + nextBitIndex = nextBit + 1; + action.accept(nextBit); + return true; + } + return false; + } + + @Override + public Spliterator.OfInt trySplit() { + return null; + } + + @Override + public long estimateSize() { + return size(); + } + + @Override + public int characteristics() { + return Spliterator.SIZED | Spliterator.SUBSIZED | Spliterator.ORDERED + | Spliterator.DISTINCT | Spliterator.SORTED; + } + } + public BitSet() { array = new int[0]; } @@ -604,6 +638,11 @@ public int nextSetBit(int fromIndex) { return bitIndex(index) + Integer.numberOfTrailingZeros(word); } + public IntStream stream() { + Spliterator.OfInt spliterator = new BitSetSpliterator(); + return StreamSupport.intStream(spliterator, false); + } + public int previousClearBit(int fromIndex) { if (fromIndex == -1) { return -1; diff --git a/user/super/com/google/gwt/emul/java/util/Map.java b/user/super/com/google/gwt/emul/java/util/Map.java index 06d057017b..470b0c56ed 100644 --- a/user/super/com/google/gwt/emul/java/util/Map.java +++ b/user/super/com/google/gwt/emul/java/util/Map.java @@ -276,6 +276,13 @@ static Comparator> comparingByValue(Comparator return (Comparator> & Serializable) (a, b) -> cmp.compare(a.getValue(), b.getValue()); } + + static Map.Entry copyOf(Map.Entry e) { + if (e instanceof AbstractMap.SimpleImmutableEntry) { + return (Entry) e; + } + return entry(e.getKey(), e.getValue()); + } } void clear(); diff --git a/user/super/com/google/gwt/emul/java/util/stream/Collectors.java b/user/super/com/google/gwt/emul/java/util/stream/Collectors.java index 519b375422..3966af525d 100644 --- a/user/super/com/google/gwt/emul/java/util/stream/Collectors.java +++ b/user/super/com/google/gwt/emul/java/util/stream/Collectors.java @@ -16,6 +16,7 @@ package java.util.stream; +import java.util.AbstractMap; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -33,6 +34,7 @@ import java.util.Set; import java.util.StringJoiner; import java.util.function.BiConsumer; +import java.util.function.BiFunction; import java.util.function.BinaryOperator; import java.util.function.Function; import java.util.function.Predicate; @@ -71,6 +73,30 @@ public static Collector collectingAndThen( downstream.finisher().andThen(finisher)); } + public static Collector teeing(Collector downstream1, + Collector downstream2, BiFunction merger) { + return teeing2(downstream1, downstream2, merger); + } + + private static Collector teeing2(Collector downstream1, + Collector downstream2, BiFunction merger) { + return Collector.of( + () -> new AbstractMap.SimpleEntry<>(downstream1.supplier().get(), + downstream2.supplier().get()), + (a,b) -> { + downstream1.accumulator().accept(a.getKey(), b); + downstream2.accumulator().accept(a.getValue(), b); + }, + (a,b) -> { + X part = downstream1.combiner().apply(a.getKey(), b.getKey()); + Y part2 = downstream2.combiner().apply(a.getValue(), b.getValue()); + return new AbstractMap.SimpleEntry<>(part, part2); + }, + (e) -> merger.apply(downstream1.finisher().apply(e.getKey()), + downstream2.finisher().apply(e.getValue())) + ); + } + public static Collector counting() { // Using Long::sum here fails in JDT return reducing(0L, item -> 1L, (a, b) -> (Long) a.longValue() + b.longValue()); diff --git a/user/super/com/google/gwt/emul/java/util/stream/DoubleStream.java b/user/super/com/google/gwt/emul/java/util/stream/DoubleStream.java index c0d81589a4..a26d15e04b 100644 --- a/user/super/com/google/gwt/emul/java/util/stream/DoubleStream.java +++ b/user/super/com/google/gwt/emul/java/util/stream/DoubleStream.java @@ -58,6 +58,15 @@ default DoubleStream.Builder add(double t) { DoubleStream build(); } + /** + * See + * the official Java API doc for details. + */ + interface DoubleMapMultiConsumer { + void accept(double value, DoubleConsumer consumer); + } + static Builder builder() { return new Builder() { private double[] items = new double[0]; @@ -317,5 +326,13 @@ public boolean tryAdvance(DoubleConsumer action) { return StreamSupport.doubleStream(spliterator, false); } + default DoubleStream mapMulti(DoubleStream.DoubleMapMultiConsumer mapper) { + return flatMap(element -> { + Builder builder = builder(); + mapper.accept(element, (DoubleConsumer) builder::add); + return builder.build(); + }); + } + double[] toArray(); } diff --git a/user/super/com/google/gwt/emul/java/util/stream/IntStream.java b/user/super/com/google/gwt/emul/java/util/stream/IntStream.java index bac1b49844..81d687fa6b 100644 --- a/user/super/com/google/gwt/emul/java/util/stream/IntStream.java +++ b/user/super/com/google/gwt/emul/java/util/stream/IntStream.java @@ -61,6 +61,15 @@ default IntStream.Builder add(int t) { IntStream build(); } + /** + * See + * the official Java API doc for details. + */ + interface IntMapMultiConsumer { + void accept(int value, IntConsumer consumer); + } + static Builder builder() { return new Builder() { private int[] items = new int[0]; @@ -366,5 +375,13 @@ public boolean tryAdvance(IntConsumer action) { return StreamSupport.intStream(spliterator, false); } + default IntStream mapMulti(IntMapMultiConsumer mapper) { + return flatMap(element -> { + Builder builder = builder(); + mapper.accept(element, (IntConsumer) builder::add); + return builder.build(); + }); + } + int[] toArray(); } diff --git a/user/super/com/google/gwt/emul/java/util/stream/LongStream.java b/user/super/com/google/gwt/emul/java/util/stream/LongStream.java index 821c2f7f40..dfe97dd74b 100644 --- a/user/super/com/google/gwt/emul/java/util/stream/LongStream.java +++ b/user/super/com/google/gwt/emul/java/util/stream/LongStream.java @@ -61,6 +61,15 @@ default LongStream.Builder add(long t) { LongStream build(); } + /** + * See + * the official Java API doc for details. + */ + interface LongMapMultiConsumer { + void accept(long value, LongConsumer consumer); + } + static Builder builder() { return new Builder() { private long[] items = new long[0]; @@ -364,5 +373,13 @@ public boolean tryAdvance(LongConsumer action) { return StreamSupport.longStream(spliterator, false); } + default LongStream mapMulti(LongStream.LongMapMultiConsumer mapper) { + return flatMap(element -> { + Builder builder = builder(); + mapper.accept(element, (LongConsumer) builder::add); + return builder.build(); + }); + } + long[] toArray(); } diff --git a/user/super/com/google/gwt/emul/java/util/stream/Stream.java b/user/super/com/google/gwt/emul/java/util/stream/Stream.java index 386d329391..a0a468f110 100644 --- a/user/super/com/google/gwt/emul/java/util/stream/Stream.java +++ b/user/super/com/google/gwt/emul/java/util/stream/Stream.java @@ -17,9 +17,11 @@ import static javaemul.internal.InternalPreconditions.checkState; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; +import java.util.List; import java.util.Optional; import java.util.Spliterator; import java.util.Spliterators; @@ -28,8 +30,11 @@ import java.util.function.BiFunction; import java.util.function.BinaryOperator; import java.util.function.Consumer; +import java.util.function.DoubleConsumer; import java.util.function.Function; +import java.util.function.IntConsumer; import java.util.function.IntFunction; +import java.util.function.LongConsumer; import java.util.function.Predicate; import java.util.function.Supplier; import java.util.function.ToDoubleFunction; @@ -246,6 +251,10 @@ public boolean tryAdvance(Consumer action) { return StreamSupport.stream(spliterator, false); } + default List toList() { + return Collections.unmodifiableList(this.collect(Collectors.toList())); + } + Stream filter(Predicate predicate); Optional findAny(); @@ -323,6 +332,38 @@ public boolean tryAdvance(Consumer action) { return StreamSupport.stream(spliterator, false); } + default Stream mapMulti(BiConsumer> mapper) { + return flatMap(element -> { + List buffer = new ArrayList<>(); + mapper.accept(element, (Consumer) buffer::add); + return buffer.stream(); + }); + } + + default DoubleStream mapMultiToDouble(BiConsumer mapper) { + return flatMapToDouble(element -> { + List buffer = new ArrayList<>(); + mapper.accept(element, (DoubleConsumer) buffer::add); + return buffer.stream().mapToDouble(n -> n); + }); + } + + default IntStream mapMultiToInt(BiConsumer mapper) { + return flatMapToInt(element -> { + List buffer = new ArrayList<>(); + mapper.accept(element, (IntConsumer) buffer::add); + return buffer.stream().mapToInt(n -> n); + }); + } + + default LongStream mapMultiToLong(BiConsumer mapper) { + return flatMapToLong(element -> { + List buffer = new ArrayList<>(); + mapper.accept(element, (LongConsumer) buffer::add); + return buffer.stream().mapToLong(n -> n); + }); + } + Object[] toArray(); A[] toArray(IntFunction generator); diff --git a/user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/lang/CharSequenceTest.java b/user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/lang/CharSequenceTest.java new file mode 100644 index 0000000000..0be7a113ef --- /dev/null +++ b/user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/lang/CharSequenceTest.java @@ -0,0 +1,31 @@ +/* + * Copyright 2025 GWT Project Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.emultest.java17.lang; + +import com.google.gwt.emultest.java.util.EmulTestBase; + +/** + * Tests for Java 17 java.lang.CharSequence emulation. + */ +public class CharSequenceTest extends EmulTestBase { + + public void testIsEmpty() { + assertTrue(hideFromCompiler(new StringBuilder()).isEmpty()); + assertFalse(hideFromCompiler(new StringBuilder("foo")).isEmpty()); + assertTrue(hideFromCompiler("").isEmpty()); + assertFalse(hideFromCompiler("foo").isEmpty()); + } +} diff --git a/user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/lang/StringTest.java b/user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/lang/StringTest.java new file mode 100644 index 0000000000..872f9e183d --- /dev/null +++ b/user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/lang/StringTest.java @@ -0,0 +1,87 @@ +/* + * Copyright 2025 GWT Project Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.emultest.java17.lang; + +import com.google.gwt.emultest.java.util.EmulTestBase; + +/** + * Tests for java.lang.String Java 12 API emulation. + */ +public class StringTest extends EmulTestBase { + + public void testTransform() { + int stringLength = hideFromCompiler("foo").transform(String::length); + assertEquals(3, stringLength); + } + + public void testIndent() { + assertEquals("", hideFromCompiler("").indent(0)); + assertEquals("", hideFromCompiler("").indent(2)); + assertEquals("", hideFromCompiler("").indent(-2)); + assertEquals(" \n", hideFromCompiler(" ").indent(0)); + assertEquals(" \n", hideFromCompiler(" ").indent(2)); + assertEquals("\n", hideFromCompiler(" ").indent(-2)); + assertEquals("x\n", hideFromCompiler("x").indent(0)); + assertEquals(" x\n", hideFromCompiler("x").indent(2)); + assertEquals("x\n", hideFromCompiler("x").indent(-2)); + assertEquals(" x \n", hideFromCompiler(" x ").indent(0)); + assertEquals(" x \n", hideFromCompiler(" x ").indent(2)); + assertEquals("x \n", hideFromCompiler(" x ").indent(-2)); + assertEquals("x\n", hideFromCompiler(" x").indent(-2)); + assertEquals(" x \n", hideFromCompiler(" \t x ").indent(-2)); + assertEquals("x\ny\n", hideFromCompiler("x\ny").indent(0)); + assertEquals("x\ny\n", hideFromCompiler("x\r\ny").indent(0)); + assertEquals("x\ny\n", hideFromCompiler("x\ry").indent(0)); + assertEquals(" x\n y\n", hideFromCompiler("x\ny").indent(2)); + assertEquals(" x\n y\n", hideFromCompiler("x\r\ny").indent(2)); + assertEquals(" x\n y\n", hideFromCompiler("x\ry").indent(2)); + assertEquals("x\ny\n", hideFromCompiler(" x\n y").indent(-2)); + assertEquals("x\ny\n", hideFromCompiler(" x\r\n y").indent(-2)); + assertEquals("x\ny\n", hideFromCompiler(" x\r y").indent(-2)); + } + + public void testStripIndent() { + assertEquals("", hideFromCompiler("").stripIndent()); + assertEquals("x", hideFromCompiler("x").stripIndent()); + assertEquals("x", hideFromCompiler(" x").stripIndent()); + assertEquals("x\n", hideFromCompiler("x\r\n").stripIndent()); + assertEquals("x\n", hideFromCompiler(" x\n ").stripIndent()); + assertEquals(" x\n", hideFromCompiler(" x\n ").stripIndent()); + assertEquals(" x\n", hideFromCompiler(" x\n").stripIndent()); + assertEquals("x\ny", hideFromCompiler(" x\n y").stripIndent()); + assertEquals("x\ny", hideFromCompiler(" x\r\n y").stripIndent()); + assertEquals(" x\ny", hideFromCompiler(" x\n y").stripIndent()); + assertEquals("x\n y", hideFromCompiler(" x\n y").stripIndent()); + assertEquals("x\n\ny", hideFromCompiler(" x\n \n y").stripIndent()); + assertEquals(" x\ny", hideFromCompiler("\t x\r\n y").stripIndent()); + assertEquals("x\n\ny", hideFromCompiler(" x\n\n y").stripIndent()); + } + + public void testTranslateEscapes() { + assertEquals("\b \r\n\t\f", + hideFromCompiler("\\b\\s\\r\\n\\t\\f").translateEscapes()); + assertEquals("\u0001\u0011\u00d1", + hideFromCompiler("\\1\\21\\321").translateEscapes()); + assertEquals("\u00ff\u001f8\u00200", + hideFromCompiler("\\377\\378\\400").translateEscapes()); + assertEquals("ab", + hideFromCompiler("a\\\nb").translateEscapes()); + assertEquals("", + hideFromCompiler("\\\r\n").translateEscapes()); + assertEquals("", + hideFromCompiler("\\\r\\\n").translateEscapes()); + } +} \ No newline at end of file diff --git a/user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/util/MapEntryTest.java b/user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/util/MapEntryTest.java new file mode 100644 index 0000000000..798342846e --- /dev/null +++ b/user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/util/MapEntryTest.java @@ -0,0 +1,37 @@ +/* + * Copyright 2025 GWT Project Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.emultest.java17.util; + +import com.google.gwt.emultest.java.util.EmulTestBase; + +import java.util.AbstractMap; +import java.util.Map; + +/** + * Tests for Java 17 java.util.Map.Entry emulation. + */ +public class MapEntryTest extends EmulTestBase { + + public void testCopyOf() { + AbstractMap.SimpleEntry mutableEntry = new AbstractMap.SimpleEntry<>("a", 4); + Map.Entry copy = Map.Entry.copyOf(mutableEntry); + assertEquals(mutableEntry.getKey(), copy.getKey()); + assertEquals(mutableEntry.getValue(), copy.getValue()); + assertNotSame(mutableEntry, copy); + Map.Entry otherCopy = Map.Entry.copyOf(copy); + assertSame(copy, otherCopy); + } +} diff --git a/user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/util/stream/CollectorsTest.java b/user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/util/stream/CollectorsTest.java new file mode 100644 index 0000000000..49b6472f25 --- /dev/null +++ b/user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/util/stream/CollectorsTest.java @@ -0,0 +1,37 @@ +/* + * Copyright 2025 GWT Project Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.emultest.java17.util.stream; + +import com.google.gwt.emultest.java.util.EmulTestBase; + +import java.util.stream.Collector; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * Tests for java.util.stream.Collectors Java 12 API emulation. + */ +public class CollectorsTest extends EmulTestBase { + + public void testTeeing() { + Collector teeing = Collectors.teeing( + Collectors.reducing(Double::sum), + Collectors.counting(), + (sum, count) -> sum.orElse(0.0) / count); + assertEquals(4.0, Stream.of(2.0, 4.0, 6.0).collect(teeing), 0.01); + } + +} \ No newline at end of file diff --git a/user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/util/stream/DoubleStreamTest.java b/user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/util/stream/DoubleStreamTest.java new file mode 100644 index 0000000000..fa01bf92ee --- /dev/null +++ b/user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/util/stream/DoubleStreamTest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2025 GWT Project Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.emultest.java17.util.stream; + +import com.google.gwt.emultest.java.util.EmulTestBase; + +import java.util.stream.DoubleStream; + +/** + * Tests for Java 17 java.util.stream.DoubleStream emulation. + */ +public class DoubleStreamTest extends EmulTestBase { + + public void testMapMulti() { + DoubleStream.DoubleMapMultiConsumer doubling = (num, callback) -> { + callback.accept(num); + callback.accept(num + num); + }; + assertEquals(new double[0], + DoubleStream.of().mapMulti(doubling).toArray()); + assertEquals(new double[]{1.0, 2.0, 3.0, 6.0}, + DoubleStream.of(1.0, 3.0).mapMulti(doubling).toArray()); + assertEquals(new double[0], + DoubleStream.of(1.0, 2.0).mapMulti((a, b) -> {}).toArray()); + } +} diff --git a/user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/util/stream/IntStreamTest.java b/user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/util/stream/IntStreamTest.java new file mode 100644 index 0000000000..aba1ec649d --- /dev/null +++ b/user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/util/stream/IntStreamTest.java @@ -0,0 +1,40 @@ +/* + * Copyright 2025 GWT Project Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.emultest.java17.util.stream; + +import com.google.gwt.emultest.java.util.EmulTestBase; + +import java.util.stream.IntStream; +import java.util.stream.Stream; + +/** + * Tests for Java 17 java.util.stream.IntStream emulation. + */ +public class IntStreamTest extends EmulTestBase { + + public void testMapMulti() { + IntStream.IntMapMultiConsumer doubling = (num, callback) -> { + callback.accept(num); + callback.accept(num + num); + }; + assertEquals(new int[0], + IntStream.of().mapMulti(doubling).toArray()); + assertEquals(new int[]{1, 2, 3, 6}, + IntStream.of(1, 3).mapMulti(doubling).toArray()); + assertEquals(new int[0], + IntStream.of(1, 3).mapMulti((a, b) -> {}).toArray()); + } +} diff --git a/user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/util/stream/LongStreamTest.java b/user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/util/stream/LongStreamTest.java new file mode 100644 index 0000000000..47dcd47044 --- /dev/null +++ b/user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/util/stream/LongStreamTest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2025 GWT Project Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.emultest.java17.util.stream; + +import com.google.gwt.emultest.java.util.EmulTestBase; + +import java.util.stream.LongStream; + +/** + * Tests for Java 17 java.util.stream.LongStream emulation. + */ +public class LongStreamTest extends EmulTestBase { + + public void testMapMulti() { + LongStream.LongMapMultiConsumer doubling = (num, callback) -> { + callback.accept(num); + callback.accept(num + num); + }; + assertEquals(new long[0], + LongStream.of().mapMulti(doubling).toArray()); + assertEquals(new long[]{1L, 2L, 3L, 6L}, + LongStream.of(1L, 3L).mapMulti(doubling).toArray()); + assertEquals(new long[0], + LongStream.of(1L, 2L).mapMulti((a, b) -> {}).toArray()); + } +} diff --git a/user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/util/stream/StreamTest.java b/user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/util/stream/StreamTest.java new file mode 100644 index 0000000000..d599ee164d --- /dev/null +++ b/user/test-super/com/google/gwt/emultest/super/com/google/gwt/emultest/java17/util/stream/StreamTest.java @@ -0,0 +1,92 @@ +/* + * Copyright 2025 GWT Project Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.emultest.java17.util.stream; + +import com.google.gwt.emultest.java.util.EmulTestBase; + +import java.util.Arrays; +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import java.util.function.DoubleConsumer; +import java.util.function.IntConsumer; +import java.util.function.LongConsumer; +import java.util.stream.Stream; + +/** + * Tests for Java 17 java.util.stream.Stream emulation. + */ +public class StreamTest extends EmulTestBase { + + public void testToList() { + assertEquals(Arrays.asList(), + hideFromCompiler(Stream.of()).toList()); + assertEquals(Arrays.asList("a", "b"), + hideFromCompiler(Stream.of("a", "b")).toList()); + } + + public void testMapMulti() { + BiConsumer> doubling = (str, callback) -> { + callback.accept(str); + callback.accept(str + str); + }; + assertEquals(Arrays.asList(), + Stream.of().mapMulti(doubling).toList()); + assertEquals(Arrays.asList("a", "aa", "b", "bb"), + Stream.of("a", "b").mapMulti(doubling).toList()); + assertEquals(Arrays.asList(), + Stream.of("a", "b").mapMulti((a, b) -> {}).toList()); + } + + public void testMapMultiToInt() { + BiConsumer doubling = (str, callback) -> { + callback.accept(str.length()); + callback.accept(str.length() * 2); + }; + assertEquals(new int[]{1, 2, 3, 6}, + Stream.of("a", "bbb").mapMultiToInt(doubling).toArray()); + assertEquals(new int[0], + Stream.of().mapMultiToInt(doubling).toArray()); + assertEquals(new int[0], + Stream.of("a", "b").mapMultiToInt((a, b) -> {}).toArray()); + } + + public void testMapMultiToLong() { + BiConsumer doubling = (str, callback) -> { + callback.accept(str.length()); + callback.accept(str.length() * 2L); + }; + assertEquals(new long[]{1L, 2L, 3L, 6L}, + Stream.of("a", "bbb").mapMultiToLong(doubling).toArray()); + assertEquals(new long[0], + Stream.of().mapMultiToLong(doubling).toArray()); + assertEquals(new long[0], + Stream.of("a", "b").mapMultiToLong((a, b) -> { + }).toArray()); + } + + public void testMapMultiToDouble() { + BiConsumer doubling = (str, callback) -> { + callback.accept(str.length()); + callback.accept(str.length() * 2); + }; + assertEquals(new double[]{1.0, 2.0, 3.0, 6.0}, + Stream.of("a", "bbb").mapMultiToDouble(doubling).toArray()); + assertEquals(new double[0], + Stream.of().mapMultiToDouble(doubling).toArray()); + assertEquals(new double[0], + Stream.of("a", "b").mapMultiToDouble((a, b) -> {}).toArray()); + } +} diff --git a/user/test/com/google/gwt/emultest/EmulJava17Suite.java b/user/test/com/google/gwt/emultest/EmulJava17Suite.java new file mode 100644 index 0000000000..b71f8d0f5f --- /dev/null +++ b/user/test/com/google/gwt/emultest/EmulJava17Suite.java @@ -0,0 +1,43 @@ +/* + * Copyright 2025 GWT Project Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.emultest; + +import com.google.gwt.emultest.java17.lang.CharSequenceTest; +import com.google.gwt.emultest.java17.lang.StringTest; +import com.google.gwt.emultest.java17.util.MapEntryTest; +import com.google.gwt.emultest.java17.util.stream.CollectorsTest; +import com.google.gwt.emultest.java17.util.stream.DoubleStreamTest; +import com.google.gwt.emultest.java17.util.stream.IntStreamTest; +import com.google.gwt.emultest.java17.util.stream.LongStreamTest; +import com.google.gwt.emultest.java17.util.stream.StreamTest; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** Test JRE emulations. */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ + CharSequenceTest.class, + StringTest.class, + CollectorsTest.class, + StreamTest.class, + DoubleStreamTest.class, + IntStreamTest.class, + LongStreamTest.class, + MapEntryTest.class +}) +public class EmulJava17Suite { +} diff --git a/user/test/com/google/gwt/emultest/EmulSuite.gwt.xml b/user/test/com/google/gwt/emultest/EmulSuite.gwt.xml index 85c3a4cf6b..b545eb5314 100644 --- a/user/test/com/google/gwt/emultest/EmulSuite.gwt.xml +++ b/user/test/com/google/gwt/emultest/EmulSuite.gwt.xml @@ -20,7 +20,8 @@ - + + diff --git a/user/test/com/google/gwt/emultest/EmulSuite.java b/user/test/com/google/gwt/emultest/EmulSuite.java index 6cbe3ef105..5ac7cde95d 100644 --- a/user/test/com/google/gwt/emultest/EmulSuite.java +++ b/user/test/com/google/gwt/emultest/EmulSuite.java @@ -28,6 +28,7 @@ import com.google.gwt.emultest.java.io.WriterTest; import com.google.gwt.emultest.java.lang.BooleanTest; import com.google.gwt.emultest.java.lang.ByteTest; +import com.google.gwt.emultest.java.lang.CharSequenceTest; import com.google.gwt.emultest.java.lang.CharacterTest; import com.google.gwt.emultest.java.lang.CompilerConstantStringTest; import com.google.gwt.emultest.java.lang.DoubleEqualsSemanticsTest; @@ -88,6 +89,7 @@ // -- java.lang BooleanTest.class, ByteTest.class, + CharSequenceTest.class, CharacterTest.class, CompilerConstantStringTest.class, DoubleTest.class, diff --git a/user/test/com/google/gwt/emultest/java/lang/CharSequenceTest.java b/user/test/com/google/gwt/emultest/java/lang/CharSequenceTest.java new file mode 100644 index 0000000000..ab8028f995 --- /dev/null +++ b/user/test/com/google/gwt/emultest/java/lang/CharSequenceTest.java @@ -0,0 +1,48 @@ +/* + * Copyright 2025 GWT Project Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.emultest.java.lang; + +import com.google.gwt.emultest.java.util.EmulTestBase; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * Tests for Java 17 java.lang.CharSequence emulation. + */ +public class CharSequenceTest extends EmulTestBase { + + public void testCompare() { + assertEquals(-1, CharSequence.compare(hideFromCompiler("a"), "b")); + assertEquals(1, CharSequence.compare(hideFromCompiler("b"), "a")); + assertEquals(0, CharSequence.compare(hideFromCompiler("a"), "a")); + assertEquals(-1, CharSequence.compare(hideFromCompiler("a"), + new StringBuilder("b"))); + } + + public void testCodePoints() { + assertEquals(List.of(), collectCodePoints("")); + assertEquals(List.of("a", "b", "c"), collectCodePoints("abc")); + assertEquals(List.of("\uD83D\uDE0D"), collectCodePoints("\uD83D\uDE0D")); + assertEquals(List.of("x", "\uD83D\uDE0D", "y"), collectCodePoints("x\uD83D\uDE0Dy")); + } + + private List collectCodePoints(String str) { + return str.codePoints().mapToObj(cp -> new String(Character.toChars(cp))) + .collect(Collectors.toList()); + } + +} diff --git a/user/test/com/google/gwt/emultest/java/util/BitSetTest.java b/user/test/com/google/gwt/emultest/java/util/BitSetTest.java index 071288e548..7a299e4138 100644 --- a/user/test/com/google/gwt/emultest/java/util/BitSetTest.java +++ b/user/test/com/google/gwt/emultest/java/util/BitSetTest.java @@ -1421,4 +1421,15 @@ public void testValueOfLongs() { "565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 584, 640, 641, 642, 643, 644, 645, " + "646, 711}", set.toString()); } + + public void testStream() { + BitSet bitSet = new BitSet(); + assertEquals(new int[]{}, bitSet.stream().toArray()); + bitSet.set(2); + assertEquals(new int[]{2}, bitSet.stream().toArray()); + bitSet.set(5); + assertEquals(new int[]{2, 5}, bitSet.stream().toArray()); + bitSet.set(100); + assertEquals(new int[]{2, 5, 100}, bitSet.stream().toArray()); + } } diff --git a/user/test/com/google/gwt/emultest/java/util/EmulTestBase.java b/user/test/com/google/gwt/emultest/java/util/EmulTestBase.java index 93fd94b9e7..ead15f52e3 100644 --- a/user/test/com/google/gwt/emultest/java/util/EmulTestBase.java +++ b/user/test/com/google/gwt/emultest/java/util/EmulTestBase.java @@ -79,4 +79,12 @@ public static void assertIAE(String methodName, Runnable runnable) { public String getModuleName() { return "com.google.gwt.emultest.EmulSuite"; } + + protected T hideFromCompiler(T value) { + if (Math.random() < -1) { + // Can never happen, but fools the compiler enough not to optimize this call. + fail(); + } + return value; + } } diff --git a/user/test/com/google/gwt/emultest/java11/lang/StringTest.java b/user/test/com/google/gwt/emultest/java11/lang/StringTest.java index 92650aca51..fd22210702 100644 --- a/user/test/com/google/gwt/emultest/java11/lang/StringTest.java +++ b/user/test/com/google/gwt/emultest/java11/lang/StringTest.java @@ -99,12 +99,4 @@ public void testLines() { assertEquals(Arrays.asList("", "", "c"), "\n\r\nc".lines().collect(Collectors.toList())); } - - private T hideFromCompiler(T value) { - if (Math.random() < -1) { - // Can never happen, but fools the compiler enough not to optimize this call. - fail(); - } - return value; - } } diff --git a/user/test/com/google/gwt/emultest/java17/lang/CharSequenceTest.java b/user/test/com/google/gwt/emultest/java17/lang/CharSequenceTest.java new file mode 100644 index 0000000000..cf97b61dde --- /dev/null +++ b/user/test/com/google/gwt/emultest/java17/lang/CharSequenceTest.java @@ -0,0 +1,37 @@ +/* + * Copyright 2025 GWT Project Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.emultest.java17.lang; + +import com.google.gwt.dev.util.arg.SourceLevel; +import com.google.gwt.emultest.java.util.EmulTestBase; +import com.google.gwt.junit.DoNotRunWith; +import com.google.gwt.junit.JUnitShell; +import com.google.gwt.junit.Platform; + +/** + * Tests for Java 17 java.lang.CharSequence emulation. + */ +@DoNotRunWith(Platform.Devel) +public class CharSequenceTest extends EmulTestBase { + + public void testIsEmpty() { + assertFalse(isGwtSourceLevel17()); + } + + private boolean isGwtSourceLevel17() { + return JUnitShell.getCompilerOptions().getSourceLevel().compareTo(SourceLevel.JAVA17) >= 0; + } +} diff --git a/user/test/com/google/gwt/emultest/java17/lang/StringTest.java b/user/test/com/google/gwt/emultest/java17/lang/StringTest.java new file mode 100644 index 0000000000..39d61a4f69 --- /dev/null +++ b/user/test/com/google/gwt/emultest/java17/lang/StringTest.java @@ -0,0 +1,49 @@ +/* + * Copyright 2025 GWT Project Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.emultest.java17.lang; + +import com.google.gwt.dev.util.arg.SourceLevel; +import com.google.gwt.emultest.java.util.EmulTestBase; +import com.google.gwt.junit.DoNotRunWith; +import com.google.gwt.junit.JUnitShell; +import com.google.gwt.junit.Platform; + +/** + * Tests for java.lang.String Java 12 - 17 API emulation. + */ +@DoNotRunWith(Platform.Devel) +public class StringTest extends EmulTestBase { + + public void testTransform() { + assertFalse(isGwtSourceLevel17()); + } + + public void testIndent() { + assertFalse(isGwtSourceLevel17()); + } + + public void testStripIndent() { + assertFalse(isGwtSourceLevel17()); + } + + public void testTranslateEscapes() { + assertFalse(isGwtSourceLevel17()); + } + + private boolean isGwtSourceLevel17() { + return JUnitShell.getCompilerOptions().getSourceLevel().compareTo(SourceLevel.JAVA17) >= 0; + } +} \ No newline at end of file diff --git a/user/test/com/google/gwt/emultest/java17/util/MapEntryTest.java b/user/test/com/google/gwt/emultest/java17/util/MapEntryTest.java new file mode 100644 index 0000000000..f715603840 --- /dev/null +++ b/user/test/com/google/gwt/emultest/java17/util/MapEntryTest.java @@ -0,0 +1,37 @@ +/* + * Copyright 2025 GWT Project Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.emultest.java17.util; + +import com.google.gwt.dev.util.arg.SourceLevel; +import com.google.gwt.emultest.java.util.EmulTestBase; +import com.google.gwt.junit.DoNotRunWith; +import com.google.gwt.junit.JUnitShell; +import com.google.gwt.junit.Platform; + +/** + * Tests for Java 17 java.util.Map.Entry emulation. + */ +@DoNotRunWith(Platform.Devel) +public class MapEntryTest extends EmulTestBase { + + public void testCopyOf() { + assertFalse(isGwtSourceLevel17()); + } + + private boolean isGwtSourceLevel17() { + return JUnitShell.getCompilerOptions().getSourceLevel().compareTo(SourceLevel.JAVA17) >= 0; + } +} diff --git a/user/test/com/google/gwt/emultest/java17/util/stream/CollectorsTest.java b/user/test/com/google/gwt/emultest/java17/util/stream/CollectorsTest.java new file mode 100644 index 0000000000..c2820cfc06 --- /dev/null +++ b/user/test/com/google/gwt/emultest/java17/util/stream/CollectorsTest.java @@ -0,0 +1,38 @@ +/* + * Copyright 2025 GWT Project Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.emultest.java17.util.stream; + +import com.google.gwt.dev.util.arg.SourceLevel; +import com.google.gwt.emultest.java.util.EmulTestBase; +import com.google.gwt.junit.DoNotRunWith; +import com.google.gwt.junit.JUnitShell; +import com.google.gwt.junit.Platform; + +/** + * Tests for java.util.stream.Collectors Java 12 - 17 API emulation. + */ +@DoNotRunWith(Platform.Devel) +public class CollectorsTest extends EmulTestBase { + + public void testTeeing() { + assertFalse(isGwtSourceLevel17()); + } + + private boolean isGwtSourceLevel17() { + return JUnitShell.getCompilerOptions().getSourceLevel().compareTo(SourceLevel.JAVA17) >= 0; + } + +} \ No newline at end of file diff --git a/user/test/com/google/gwt/emultest/java17/util/stream/DoubleStreamTest.java b/user/test/com/google/gwt/emultest/java17/util/stream/DoubleStreamTest.java new file mode 100644 index 0000000000..a4f0f86815 --- /dev/null +++ b/user/test/com/google/gwt/emultest/java17/util/stream/DoubleStreamTest.java @@ -0,0 +1,37 @@ +/* + * Copyright 2025 GWT Project Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.emultest.java17.util.stream; + +import com.google.gwt.dev.util.arg.SourceLevel; +import com.google.gwt.emultest.java.util.EmulTestBase; +import com.google.gwt.junit.DoNotRunWith; +import com.google.gwt.junit.JUnitShell; +import com.google.gwt.junit.Platform; + +/** + * Tests for java.util.stream.DoubleStream Java 17 emulation. + */ +@DoNotRunWith(Platform.Devel) +public class DoubleStreamTest extends EmulTestBase { + + public void testMapMulti() { + assertFalse(isGwtSourceLevel17()); + } + + private boolean isGwtSourceLevel17() { + return JUnitShell.getCompilerOptions().getSourceLevel().compareTo(SourceLevel.JAVA17) >= 0; + } +} diff --git a/user/test/com/google/gwt/emultest/java17/util/stream/IntStreamTest.java b/user/test/com/google/gwt/emultest/java17/util/stream/IntStreamTest.java new file mode 100644 index 0000000000..6d7270b66a --- /dev/null +++ b/user/test/com/google/gwt/emultest/java17/util/stream/IntStreamTest.java @@ -0,0 +1,37 @@ +/* + * Copyright 2025 GWT Project Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.emultest.java17.util.stream; + +import com.google.gwt.dev.util.arg.SourceLevel; +import com.google.gwt.emultest.java.util.EmulTestBase; +import com.google.gwt.junit.DoNotRunWith; +import com.google.gwt.junit.JUnitShell; +import com.google.gwt.junit.Platform; + +/** + * Tests for java.util.stream.IntStream Java 17 emulation. + */ +@DoNotRunWith(Platform.Devel) +public class IntStreamTest extends EmulTestBase { + + public void testMapMulti() { + assertFalse(isGwtSourceLevel17()); + } + + private boolean isGwtSourceLevel17() { + return JUnitShell.getCompilerOptions().getSourceLevel().compareTo(SourceLevel.JAVA17) >= 0; + } +} diff --git a/user/test/com/google/gwt/emultest/java17/util/stream/LongStreamTest.java b/user/test/com/google/gwt/emultest/java17/util/stream/LongStreamTest.java new file mode 100644 index 0000000000..8c867e2a94 --- /dev/null +++ b/user/test/com/google/gwt/emultest/java17/util/stream/LongStreamTest.java @@ -0,0 +1,37 @@ +/* + * Copyright 2025 GWT Project Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.emultest.java17.util.stream; + +import com.google.gwt.dev.util.arg.SourceLevel; +import com.google.gwt.emultest.java.util.EmulTestBase; +import com.google.gwt.junit.DoNotRunWith; +import com.google.gwt.junit.JUnitShell; +import com.google.gwt.junit.Platform; + +/** + * Tests for java.util.stream.LongStream Java 17 emulation. + */ +@DoNotRunWith(Platform.Devel) +public class LongStreamTest extends EmulTestBase { + + public void testMapMulti() { + assertFalse(isGwtSourceLevel17()); + } + + private boolean isGwtSourceLevel17() { + return JUnitShell.getCompilerOptions().getSourceLevel().compareTo(SourceLevel.JAVA17) >= 0; + } +} diff --git a/user/test/com/google/gwt/emultest/java17/util/stream/StreamTest.java b/user/test/com/google/gwt/emultest/java17/util/stream/StreamTest.java new file mode 100644 index 0000000000..92fc217135 --- /dev/null +++ b/user/test/com/google/gwt/emultest/java17/util/stream/StreamTest.java @@ -0,0 +1,53 @@ +/* + * Copyright 2025 GWT Project Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.emultest.java17.util.stream; + +import com.google.gwt.dev.util.arg.SourceLevel; +import com.google.gwt.emultest.java.util.EmulTestBase; +import com.google.gwt.junit.DoNotRunWith; +import com.google.gwt.junit.JUnitShell; +import com.google.gwt.junit.Platform; + +/** + * Tests for java.util.stream.Stream Java 12 - 17 API emulation. + */ +@DoNotRunWith(Platform.Devel) +public class StreamTest extends EmulTestBase { + + public void testToList() { + assertFalse(isGwtSourceLevel17()); + } + + public void testMapMulti() { + assertFalse(isGwtSourceLevel17()); + } + + public void testMapMultiToInt() { + assertFalse(isGwtSourceLevel17()); + } + + public void testMapMultiToLong() { + assertFalse(isGwtSourceLevel17()); + } + + public void testMapMultiToDouble() { + assertFalse(isGwtSourceLevel17()); + } + + private boolean isGwtSourceLevel17() { + return JUnitShell.getCompilerOptions().getSourceLevel().compareTo(SourceLevel.JAVA17) >= 0; + } +}