Skip to content

Commit

Permalink
Merge branch 'main' into java9-stream-apis-test
Browse files Browse the repository at this point in the history
  • Loading branch information
niloc132 committed Nov 7, 2023
2 parents e86b814 + abceee4 commit a98d998
Show file tree
Hide file tree
Showing 20 changed files with 572 additions and 25 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@

`$ ant clean dist-dev`

or if you don't have `python` and `g++` just run

`$ ant clean dist-dev`

Then you will get all `.jar` files in the folder `build/lib` and
the redistributable file will be: `build/dist/gwt-0.0.0.zip`

Expand Down
6 changes: 5 additions & 1 deletion build_tools/doctool/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
<import file="${gwt.root}/common.ant.xml" />

<target name="compile" description="Compiles this project">
<gwt.javac />
<!--
As guarded below in the build target, doctool can't be built on
Java 8. In theory release could be set to 9, but 9 and 10 are EOL.
-->
<gwt.javac release="11" />
</target>

<target name="build" depends="compile" description="Packages this project into a jar" unless="${isJava8}">
Expand Down
8 changes: 3 additions & 5 deletions common.ant.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@
<property name="javac.debug" value="true"/>
<property name="javac.debuglevel" value="lines,vars,source"/>
<property name="javac.encoding" value="utf-8"/>
<property name="javac.source" value="8"/>
<property name="javac.target" value="8"/>
<property name="javac.release" value="8"/>
<property name="javac.nowarn" value="true"/>

<!-- javac and errorprone instructions from https://errorprone.info/docs/installation#ant -->
Expand Down Expand Up @@ -158,8 +157,7 @@
<macrodef name="gwt.javac">
<attribute name="srcdir" default="src" />
<attribute name="destdir" default="${javac.out}" />
<attribute name="source" default="${javac.source}" />
<attribute name="target" default="${javac.target}" />
<attribute name="release" default="${javac.release}" />
<attribute name="excludes" default="" />
<attribute name="processorpath" default="" />
<attribute name="errorprone.args" default="" />
Expand All @@ -172,7 +170,7 @@
</path>
<mkdir dir="@{destdir}"/>
<javac srcdir="@{srcdir}" sourcepath="@{srcdir}" destdir="@{destdir}" debug="${javac.debug}"
debuglevel="${javac.debuglevel}" source="@{source}" target="@{target}"
debuglevel="${javac.debuglevel}" source="@{release}" target="@{release}" release="@{release}"
nowarn="${javac.nowarn}" encoding="${javac.encoding}" includeantruntime="false"
fork="true" compiler="modern" excludes="@{excludes}">
<compilerarg value="-J-Xbootclasspath/p:${errorprone.javac.jar}" if:true="${isJava8}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ function installScript(filename) {
var docbody = doc.body;
var script = doc.createElement('script');
script.language='javascript';
script.crossOrigin='';
if (location.host) {
script.crossOrigin='';
}
script.src = code;
if (__MODULE_FUNC__.__errFn) {
script.onerror = function() {
Expand Down
4 changes: 2 additions & 2 deletions doc/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<property file="${gwt.root}/build/out/packages.properties" />
<javadoc classpathref="DOC_PATH" failonerror="true" maxmemory="1g"
destdir="${project.build}/javadoc"
source="${javac.source}"
source="${javac.release}"
encoding="UTF-8"
access="package"
packagenames="${USER_PKGS}"
Expand Down Expand Up @@ -125,7 +125,7 @@
sourcepath="${gwt.root}/user/super/com/google/gwt/emul:${gwt.root}/dev/core/super/com/google/gwt/dev/jjs/intrinsic"
encoding="UTF-8"
access="public"
source="${javac.source}"
source="${javac.release}"
packagenames="${JAVA_PKGS}"
docletpath="${project.build}/../build_tools/doctool/bin"
doclet="com.google.doctool.custom.JavaEmulSummaryDoclet">
Expand Down
1 change: 1 addition & 0 deletions user/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
<gwt.javac srcdir="test" destdir="${javac.junit.out}"
excludes="com/google/gwt/langtest/**,**/super/**"
processorpath="test.extraclasspath"
release="11"
errorprone.args="
-Xep:SelfAssignment:OFF
-Xep:MissingCasesInEnumSwitch:OFF
Expand Down
38 changes: 34 additions & 4 deletions user/super/com/google/gwt/emul/java/util/Optional.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
*/
package java.util;

import static javaemul.internal.InternalPreconditions.checkCriticalElement;
import static javaemul.internal.InternalPreconditions.checkCriticalNotNull;
import static javaemul.internal.InternalPreconditions.checkNotNull;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

import static javaemul.internal.InternalPreconditions.checkCriticalElement;
import static javaemul.internal.InternalPreconditions.checkCriticalNotNull;
import static javaemul.internal.InternalPreconditions.checkNotNull;
import java.util.stream.Stream;

/**
* See <a href="https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html">
Expand Down Expand Up @@ -72,6 +73,14 @@ public void ifPresent(Consumer<? super T> consumer) {
}
}

public void ifPresentOrElse(Consumer<? super T> action, Runnable emptyAction) {
if (isPresent()) {
action.accept(ref);
} else {
emptyAction.run();
}
}

public Optional<T> filter(Predicate<? super T> predicate) {
checkNotNull(predicate);
if (!isPresent() || predicate.test(ref)) {
Expand All @@ -96,6 +105,23 @@ public <U> Optional<U> flatMap(Function<? super T, Optional<U>> mapper) {
return empty();
}

public Optional<T> or(Supplier<? extends Optional<? extends T>> supplier) {
checkNotNull(supplier);
if (isPresent()) {
return this;
} else {
return (Optional) checkNotNull(supplier.get());
}
}

public Stream<T> stream() {
if (isPresent()) {
return Stream.of(ref);
} else {
return Stream.empty();
}
}

public T orElse(T other) {
return isPresent() ? ref : other;
}
Expand All @@ -104,6 +130,10 @@ public T orElseGet(Supplier<? extends T> other) {
return isPresent() ? ref : other.get();
}

public T orElseThrow() {
return get();
}

public <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X {
if (isPresent()) {
return ref;
Expand Down
25 changes: 23 additions & 2 deletions user/super/com/google/gwt/emul/java/util/OptionalDouble.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
*/
package java.util;

import static javaemul.internal.InternalPreconditions.checkCriticalElement;

import java.util.function.DoubleConsumer;
import java.util.function.DoubleSupplier;
import java.util.function.Supplier;

import static javaemul.internal.InternalPreconditions.checkCriticalElement;
import java.util.stream.DoubleStream;

/**
* See <a href="https://docs.oracle.com/javase/8/docs/api/java/util/OptionalDouble.html">
Expand Down Expand Up @@ -65,6 +66,22 @@ public void ifPresent(DoubleConsumer consumer) {
}
}

public void ifPresentOrElse(DoubleConsumer action, Runnable emptyAction) {
if (isPresent()) {
action.accept(ref);
} else {
emptyAction.run();
}
}

public DoubleStream stream() {
if (isPresent()) {
return DoubleStream.of(ref);
} else {
return DoubleStream.empty();
}
}

public double orElse(double other) {
return present ? ref : other;
}
Expand All @@ -73,6 +90,10 @@ public double orElseGet(DoubleSupplier other) {
return present ? ref : other.getAsDouble();
}

public double orElseThrow() {
return getAsDouble();
}

public <X extends Throwable> double orElseThrow(Supplier<X> exceptionSupplier) throws X {
if (present) {
return ref;
Expand Down
25 changes: 23 additions & 2 deletions user/super/com/google/gwt/emul/java/util/OptionalInt.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
*/
package java.util;

import static javaemul.internal.InternalPreconditions.checkCriticalElement;

import java.util.function.IntConsumer;
import java.util.function.IntSupplier;
import java.util.function.Supplier;

import static javaemul.internal.InternalPreconditions.checkCriticalElement;
import java.util.stream.IntStream;

/**
* See <a href="https://docs.oracle.com/javase/8/docs/api/java/util/OptionalInt.html">
Expand Down Expand Up @@ -65,6 +66,22 @@ public void ifPresent(IntConsumer consumer) {
}
}

public void ifPresentOrElse(IntConsumer action, Runnable emptyAction) {
if (present) {
action.accept(ref);
} else {
emptyAction.run();
}
}

public IntStream stream() {
if (present) {
return IntStream.of(ref);
} else {
return IntStream.empty();
}
}

public int orElse(int other) {
return present ? ref : other;
}
Expand All @@ -73,6 +90,10 @@ public int orElseGet(IntSupplier other) {
return present ? ref : other.getAsInt();
}

public int orElseThrow() {
return getAsInt();
}

public <X extends Throwable> int orElseThrow(Supplier<X> exceptionSupplier) throws X {
if (present) {
return ref;
Expand Down
25 changes: 23 additions & 2 deletions user/super/com/google/gwt/emul/java/util/OptionalLong.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
*/
package java.util;

import static javaemul.internal.InternalPreconditions.checkCriticalElement;

import java.util.function.LongConsumer;
import java.util.function.LongSupplier;
import java.util.function.Supplier;

import static javaemul.internal.InternalPreconditions.checkCriticalElement;
import java.util.stream.LongStream;

/**
* See <a href="https://docs.oracle.com/javase/8/docs/api/java/util/OptionalLong.html">
Expand Down Expand Up @@ -65,6 +66,22 @@ public void ifPresent(LongConsumer consumer) {
}
}

public void ifPresentOrElse(LongConsumer action, Runnable emptyAction) {
if (present) {
action.accept(ref);
} else {
emptyAction.run();
}
}

public LongStream stream() {
if (present) {
return LongStream.of(ref);
} else {
return LongStream.empty();
}
}

public long orElse(long other) {
return present ? ref : other;
}
Expand All @@ -73,6 +90,10 @@ public long orElseGet(LongSupplier other) {
return present ? ref : other.getAsLong();
}

public long orElseThrow() {
return getAsLong();
}

public <X extends Throwable> long orElseThrow(Supplier<X> exceptionSupplier) throws X {
if (present) {
return ref;
Expand Down
35 changes: 35 additions & 0 deletions user/test/com/google/gwt/emultest/EmulJava10Suite.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2023 Google Inc.
*
* 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.java10.util.OptionalDoubleTest;
import com.google.gwt.emultest.java10.util.OptionalIntTest;
import com.google.gwt.emultest.java10.util.OptionalLongTest;
import com.google.gwt.emultest.java10.util.OptionalTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

/** Test JRE emulations. */
@RunWith(Suite.class)
@SuiteClasses({
OptionalDoubleTest.class,
OptionalIntTest.class,
OptionalLongTest.class,
OptionalTest.class,
})
public class EmulJava10Suite {
}
12 changes: 10 additions & 2 deletions user/test/com/google/gwt/emultest/EmulJava9Suite.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
import com.google.gwt.emultest.java9.util.stream.StreamTest;
import com.google.gwt.emultest.java9.util.ListTest;
import com.google.gwt.emultest.java9.util.MapTest;
import com.google.gwt.emultest.java9.util.OptionalDoubleTest;
import com.google.gwt.emultest.java9.util.OptionalIntTest;
import com.google.gwt.emultest.java9.util.OptionalLongTest;
import com.google.gwt.emultest.java9.util.OptionalTest;
import com.google.gwt.emultest.java9.util.SetTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
Expand All @@ -36,8 +40,12 @@
LongStreamTest.class,
StreamTest.class,
ListTest.class,
SetTest.class,
MapTest.class
MapTest.class,
OptionalDoubleTest.class,
OptionalIntTest.class,
OptionalLongTest.class,
OptionalTest.class,
SetTest.class
})
public class EmulJava9Suite {
}
Loading

0 comments on commit a98d998

Please sign in to comment.