From c6b01f437c48c96d10dc6d7cef3978750f4f384f Mon Sep 17 00:00:00 2001 From: Natan Date: Thu, 30 Jan 2025 07:12:07 -0300 Subject: [PATCH] Remove all emulation classes from java.util.concurrent --- .../emu/java/util/concurrent/Callable.java | 23 - .../concurrent/CancellationException.java | 29 - .../util/concurrent/CompletableFuture.java | 722 ------------------ .../concurrent/CompletableFutureUtils.java | 23 - .../util/concurrent/CompletionException.java | 37 - .../java/util/concurrent/CompletionStage.java | 121 --- .../emu/emu/java/util/concurrent/Delayed.java | 23 - .../util/concurrent/ExecutionException.java | 36 - .../emu/java/util/concurrent/Executor.java | 23 - .../emu/java/util/concurrent/Executors.java | 50 -- .../emu/emu/java/util/concurrent/Future.java | 38 - .../RejectedExecutionException.java | 36 - .../java/util/concurrent/RunnableFuture.java | 22 - .../concurrent/RunnableScheduledFuture.java | 26 - .../java/util/concurrent/ScheduledFuture.java | 24 - .../emu/java/util/concurrent/TimeUnit.java | 389 ---------- .../util/concurrent/TimeoutException.java | 28 - .../concurrent/impl/DeferredExecutor.java | 30 - .../emu/java/util/concurrent/impl/Impl.java | 47 -- .../java/util/concurrent/impl/JsPromise.java | 86 --- .../concurrent/impl/NativePromiseImpl.java | 85 --- .../concurrent/impl/NativePromisesImpl.java | 53 -- .../java/util/concurrent/impl/Promise.java | 32 - .../util/concurrent/impl/PromiseImpl.java | 98 --- .../java/util/concurrent/impl/Promises.java | 30 - .../util/concurrent/impl/PromisesImpl.java | 80 -- 26 files changed, 2191 deletions(-) delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/Callable.java delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/CancellationException.java delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/CompletableFuture.java delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/CompletableFutureUtils.java delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/CompletionException.java delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/CompletionStage.java delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/Delayed.java delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/ExecutionException.java delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/Executor.java delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/Executors.java delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/Future.java delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/RejectedExecutionException.java delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/RunnableFuture.java delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/RunnableScheduledFuture.java delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/ScheduledFuture.java delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/TimeUnit.java delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/TimeoutException.java delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/impl/DeferredExecutor.java delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/impl/Impl.java delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/impl/JsPromise.java delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/impl/NativePromiseImpl.java delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/impl/NativePromisesImpl.java delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/impl/Promise.java delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/impl/PromiseImpl.java delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/impl/Promises.java delete mode 100644 backends/backend-teavm/emu/emu/java/util/concurrent/impl/PromisesImpl.java diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/Callable.java b/backends/backend-teavm/emu/emu/java/util/concurrent/Callable.java deleted file mode 100644 index 9898970b..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/Callable.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2016 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 emu.java.util.concurrent; - -/** - * Emulation of Callable. - */ -public interface Callable { - V call() throws Exception; -} diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/CancellationException.java b/backends/backend-teavm/emu/emu/java/util/concurrent/CancellationException.java deleted file mode 100644 index 3d1d80b0..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/CancellationException.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2016 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 emu.java.util.concurrent; - -/** - * Emulation of CancellationException. - */ -public class CancellationException extends IllegalStateException { - - public CancellationException() { - } - - public CancellationException(String message) { - super(message); - } -} diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/CompletableFuture.java b/backends/backend-teavm/emu/emu/java/util/concurrent/CompletableFuture.java deleted file mode 100644 index 3c2b3532..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/CompletableFuture.java +++ /dev/null @@ -1,722 +0,0 @@ -/* - * Copyright 2016 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 emu.java.util.concurrent; - -import static emu.java.util.concurrent.CompletableFutureUtils.checkNotNull; -import emu.java.util.concurrent.impl.DeferredExecutor; -import emu.java.util.concurrent.impl.Impl; -import emu.java.util.concurrent.impl.Promise; -import java.util.function.BiConsumer; -import java.util.function.BiFunction; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Supplier; - -/** - * Emulation of CompletableFuture. - * See - * - * the official Java API doc for details. - */ -public class CompletableFuture implements Future, CompletionStage { - - public interface AsynchronousCompletionTask { - } - - public static CompletableFuture runAsync(Runnable action) { - return runAsync(action, DEFAULT_EXECUTOR); - } - - public static CompletableFuture runAsync(Runnable action, Executor executor) { - return supplyAsync(() -> { - action.run(); - return null; - }, executor); - } - - public static CompletableFuture supplyAsync(Supplier supplier) { - return supplyAsync(supplier, DEFAULT_EXECUTOR); - } - - public static CompletableFuture supplyAsync(Supplier supplier, Executor executor) { - checkNotNull(supplier); - checkNotNull(executor); - - CompletableFuture future = new CompletableFuture<>(); - executor.execute(() -> { - try { - future.tryCompleteValue(supplier.get()); - } - catch(Throwable t) { - future.tryCompleteThrowable(t); - } - }); - return future; - } - - public static CompletableFuture completedFuture(T value) { - return new CompletableFuture<>(value, null); - } - - public static CompletableFuture allOf(CompletableFuture... futures) { - if(futures.length == 0) { - return completedFuture(null); - } - - CompletableFuture completedFuture = null; - for(CompletableFuture future : futures) { - if(!future.isDone()) { - completedFuture = null; - break; - } - if(completedFuture == null) { - completedFuture = future; - } - } - if(completedFuture != null) { - return new CompletableFuture<>(null, completedFuture.reason); - } - - CompletableFuture future = new CompletableFuture<>(); - and(futures).then((value, reason) -> { - if(reason != null) { - future.tryCompleteThrowable(reason); - } - else { - future.tryCompleteValue(null); - } - }); - return future; - } - - public static CompletableFuture anyOf(CompletableFuture... futures) { - if(futures.length == 0) { - return new CompletableFuture<>(); - } - - for(CompletableFuture future : futures) { - if(future.isDone()) { - return new CompletableFuture<>(future.value, future.reason); - } - } - - CompletableFuture future = new CompletableFuture<>(); - or(futures).then((value, reason) -> { - if(reason != null) { - future.tryCompleteThrowable(reason); - } - else { - future.tryCompleteValue(value); - } - }); - return future; - } - - private static Promise and(CompletableFuture... futures) { - return Impl.IMPL.allOf(toPromises(futures)); - } - - private static Promise or(CompletableFuture... futures) { - return Impl.IMPL.anyOf(toPromises(futures)); - } - - private static Promise[] toPromises(CompletableFuture... futures) { - int length = futures.length; - Promise[] promises = new Promise[length]; - for(int i = 0; i < length; i++) { - promises[i] = futures[i].promise; - } - return promises; - } - - private static BiConsumer runAsync( - Executor executor, BiConsumer action) { - - if(executor == null) { - return action; - } - else { - return (r, e) -> executor.execute(() -> action.accept(r, e)); - } - } - - private static final Executor DEFAULT_EXECUTOR = new DeferredExecutor(); - - private final Promise promise; - private boolean done; - private T value; - private Throwable reason; - - public CompletableFuture() { - promise = Impl.IMPL.incomplete(); - } - - private CompletableFuture(T value, Throwable reason) { - this(); - completeStage(value, reason); // TODO - } - - @Override - public CompletableFuture thenApply(Function fn) { - return thenApplyAsync0(fn, null); - } - - @Override - public CompletableFuture thenApplyAsync(Function fn) { - return thenApplyAsync0(fn, DEFAULT_EXECUTOR); - } - - @Override - public CompletableFuture thenApplyAsync(Function fn, Executor executor) { - checkNotNull(executor); - return thenApplyAsync0(fn, executor); - } - - private CompletableFuture thenApplyAsync0(Function fn, Executor executor) { - checkNotNull(fn); - CompletableFuture future = new CompletableFuture<>(); - onStageComplete((r, e) -> { - if(e != null) { - future.tryCompleteThrowable(e); - } - else { - try { - future.tryCompleteValue(fn.apply(r)); - } - catch(Throwable ex) { - future.tryCompleteThrowable(ex); - } - } - }, executor); - return future; - } - - @Override - public CompletableFuture thenAccept(Consumer action) { - return thenAcceptAsync0(action, null); - } - - @Override - public CompletableFuture thenAcceptAsync(Consumer action) { - return thenAcceptAsync0(action, DEFAULT_EXECUTOR); - } - - @Override - public CompletableFuture thenAcceptAsync(Consumer action, Executor executor) { - checkNotNull(executor); - return thenAcceptAsync0(action, executor); - } - - private CompletableFuture thenAcceptAsync0(Consumer action, Executor executor) { - checkNotNull(action); - return thenApplyAsync0((r) -> { - action.accept(r); - return null; - }, executor); - } - - @Override - public CompletableFuture thenRun(Runnable action) { - return thenRunAsync0(action, null); - } - - @Override - public CompletableFuture thenRunAsync(Runnable action) { - return thenRunAsync0(action, DEFAULT_EXECUTOR); - } - - @Override - public CompletableFuture thenRunAsync(Runnable action, Executor executor) { - checkNotNull(executor); - return thenRunAsync0(action, executor); - } - - private CompletableFuture thenRunAsync0(Runnable action, Executor executor) { - checkNotNull(action); - return thenApplyAsync0((r) -> { - action.run(); - return null; - }, executor); - } - - @Override - public CompletableFuture thenCombine(CompletionStage other, - BiFunction fn) { - - return thenCombineAsync0(other, fn, null); - } - - @Override - public CompletableFuture thenCombineAsync(CompletionStage other, - BiFunction fn) { - - return thenCombineAsync0(other, fn, DEFAULT_EXECUTOR); - } - - @Override - public CompletableFuture thenCombineAsync(CompletionStage other, - BiFunction fn, Executor executor) { - checkNotNull(executor); - return thenCombineAsync0(other, fn, executor); - } - - private CompletableFuture thenCombineAsync0(CompletionStage other, - BiFunction fn, Executor executor) { - - checkNotNull(fn); - CompletableFuture future = new CompletableFuture<>(); - CompletableFuture first = this; - CompletableFuture second = other.toCompletableFuture(); - and(first, second).then(runAsync(executor, (ignored, e) -> { - if(e != null) { - future.tryCompleteThrowable(e); - } - else { - try { - future.tryCompleteValue(fn.apply(first.get(), second.get())); - } - catch(Throwable ex) { - future.tryCompleteThrowable(ex); - } - } - })); - return future; - } - - @Override - public CompletableFuture thenAcceptBoth(CompletionStage other, - BiConsumer action) { - - return thenAcceptBothAsync0(other, action, null); - } - - @Override - public CompletableFuture thenAcceptBothAsync(CompletionStage other, - BiConsumer action) { - - return thenAcceptBothAsync0(other, action, DEFAULT_EXECUTOR); - } - - @Override - public CompletableFuture thenAcceptBothAsync(CompletionStage other, - BiConsumer action, Executor executor) { - - checkNotNull(executor); - return thenAcceptBothAsync0(other, action, executor); - } - - private CompletableFuture thenAcceptBothAsync0(CompletionStage other, - BiConsumer action, Executor executor) { - - checkNotNull(action); - return thenCombineAsync0(other, (a, b) -> { - action.accept(a, b); - return null; - }, executor); - } - - @Override - public CompletableFuture runAfterBoth(CompletionStage other, Runnable action) { - return runAfterBothAsync0(other, action, null); - } - - @Override - public CompletableFuture runAfterBothAsync(CompletionStage other, Runnable action) { - return runAfterBothAsync0(other, action, DEFAULT_EXECUTOR); - } - - @Override - public CompletableFuture runAfterBothAsync(CompletionStage other, Runnable action, Executor executor) { - checkNotNull(executor); - return runAfterBothAsync0(other, action, executor); - } - - private CompletableFuture runAfterBothAsync0(CompletionStage other, Runnable action, Executor executor) { - checkNotNull(action); - return thenCombineAsync0(other, (a, b) -> { - action.run(); - return null; - }, executor); - } - - @Override - public CompletableFuture applyToEither(CompletionStage other, Function fn) { - return applyToEitherAsync0(other, fn, null); - } - - @Override - public CompletableFuture applyToEitherAsync(CompletionStage other, Function fn) { - return applyToEitherAsync0(other, fn, DEFAULT_EXECUTOR); - } - - @Override - public CompletableFuture applyToEitherAsync(CompletionStage other, - Function fn, Executor executor) { - - checkNotNull(executor); - return applyToEitherAsync0(other, fn, executor); - } - - @SuppressWarnings("unchecked") - private CompletableFuture applyToEitherAsync0(CompletionStage other, - Function fn, Executor executor) { - - checkNotNull(fn); - CompletableFuture future = new CompletableFuture<>(); - or(this, other.toCompletableFuture()).then(runAsync(executor, (r, e) -> { - if(e != null) { - future.tryCompleteThrowable(e); - } - else { - try { - future.tryCompleteValue(fn.apply((T)r)); - } - catch(Throwable ex) { - future.tryCompleteThrowable(ex); - } - } - })); - return future; - } - - @Override - public CompletableFuture acceptEither(CompletionStage other, Consumer action) { - return acceptEitherAsync0(other, action, null); - } - - @Override - public CompletableFuture acceptEitherAsync(CompletionStage other, Consumer action) { - return acceptEitherAsync0(other, action, DEFAULT_EXECUTOR); - } - - @Override - public CompletableFuture acceptEitherAsync(CompletionStage other, - Consumer action, Executor executor) { - - checkNotNull(executor); - return acceptEitherAsync0(other, action, executor); - } - - private CompletableFuture acceptEitherAsync0(CompletionStage other, - Consumer action, Executor executor) { - checkNotNull(action); - return applyToEitherAsync0(other, (r) -> { - action.accept(r); - return null; - }, executor); - } - - @Override - public CompletableFuture runAfterEither(CompletionStage other, Runnable action) { - return runAfterEitherAsync0(other, action, null); - } - - @Override - public CompletableFuture runAfterEitherAsync(CompletionStage other, Runnable action) { - return runAfterEitherAsync0(other, action, DEFAULT_EXECUTOR); - } - - @Override - public CompletableFuture runAfterEitherAsync(CompletionStage other, Runnable action, Executor executor) { - checkNotNull(executor); - return runAfterEitherAsync0(other, action, executor); - } - - @SuppressWarnings("unchecked") - private CompletableFuture runAfterEitherAsync0(CompletionStage other, Runnable action, Executor executor) { - checkNotNull(action); - return ((CompletableFuture)this).applyToEitherAsync0(other, (r) -> { - action.run(); - return null; - }, executor); - } - - @Override - public CompletableFuture thenCompose(Function> fn) { - return thenComposeAsync0(fn, null); - } - - @Override - public CompletableFuture thenComposeAsync(Function> fn) { - return thenComposeAsync0(fn, DEFAULT_EXECUTOR); - } - - @Override - public CompletableFuture thenComposeAsync(Function> fn, Executor executor) { - checkNotNull(executor); - return thenComposeAsync0(fn, executor); - } - - private CompletableFuture thenComposeAsync0(Function> fn, Executor executor) { - checkNotNull(fn); - CompletableFuture future = new CompletableFuture<>(); - onStageComplete((r, e) -> { - if(e != null) { - future.tryCompleteThrowable(e); - } - else { - try { - CompletableFuture newFuture = fn.apply(r).toCompletableFuture(); - // TODO: async? - // TODO: whenCompleteAsync0? - newFuture.whenCompleteAsync0((r1, ex) -> { - if(ex != null) { - future.tryCompleteThrowable(ex); - } - else { - future.tryCompleteValue(r1); - } - }, executor); - } - catch(Throwable ex) { - future.tryCompleteThrowable(ex); - } - } - }, null); // TODO: executor? - return future; - } - - @Override - public CompletableFuture exceptionally(Function fn) { - checkNotNull(fn); - return handle((r, e) -> e != null ? fn.apply(e) : r); - } - - @Override - public CompletableFuture whenComplete(BiConsumer action) { - return whenCompleteAsync0(action, null); - } - - @Override - public CompletableFuture whenCompleteAsync(BiConsumer action) { - return whenCompleteAsync0(action, DEFAULT_EXECUTOR); - } - - @Override - public CompletableFuture whenCompleteAsync(BiConsumer action, Executor executor) { - checkNotNull(executor); - return whenCompleteAsync0(action, executor); - } - - private CompletableFuture whenCompleteAsync0(BiConsumer action, Executor executor) { - checkNotNull(action); - return handleAsync0((r, e) -> { - action.accept(r, e); - return r; - }, executor); - } - - @Override - public CompletableFuture handle(BiFunction fn) { - return handleAsync0(fn, null); - } - - @Override - public CompletableFuture handleAsync(BiFunction fn) { - return handleAsync0(fn, DEFAULT_EXECUTOR); - } - - @Override - public CompletableFuture handleAsync(BiFunction fn, Executor executor) { - checkNotNull(executor); - return handleAsync0(fn, executor); - } - - private CompletableFuture handleAsync0(BiFunction fn, Executor executor) { - checkNotNull(fn); - CompletableFuture future = new CompletableFuture<>(); - onStageComplete((r, e) -> { - try { - future.tryCompleteValue(fn.apply(r, e)); - } - catch(Throwable ex) { - future.tryCompleteThrowable(ex); - } - }, executor); - return future; - } - - @Override - public CompletableFuture toCompletableFuture() { - return this; - } - - @Override - public boolean cancel(boolean mayInterruptIfRunning) { - return tryCompleteStage(null, new CancellationException()); - } - - @Override - public boolean isCancelled() { - return reason instanceof CancellationException; - } - - @Override - public boolean isDone() { - return done; - } - - public boolean isCompletedExceptionally() { - return reason != null; - } - - /** - * This method does not implement blocking behaviour on CompletableFuture because - * it's not possible to implement that in single thread browser environment. - * Instead a method call, which would block in JVM, will act as if calling thread is interrupted - * immediately and will throw InterruptedException. - */ - @Override - public T get() throws InterruptedException, ExecutionException { - if(!isDone()) { - // TODO: according to GWT Future's javadoc -// throw new IllegalStateException("blocking on CompletableFuture is not supported"); - throw new InterruptedException("blocking on CompletableFuture is not supported"); - } - - if(reason != null) { - if(reason instanceof CancellationException) { - throw (CancellationException)reason; - } - Throwable cause = null; - if(reason instanceof CompletionException) { - cause = reason.getCause(); - } - if(cause == null) { - cause = reason; - } - throw new ExecutionException(cause); - } - return value; - } - - /** - * This method does not implement blocking behaviour on CompletableFuture because - * it's not possible to implement that in single thread browser environment. - * Instead a method call, which would block in JVM, will act as if calling thread is interrupted - * immediately and will throw InterruptedException. - * Timeout parameters are ignored and considered indefinite. - */ - @Override - public T get(long timeout, TimeUnit unit) - throws InterruptedException, ExecutionException, TimeoutException { - return get(); - } - - /** - * This method does not implement blocking behaviour on CompletableFuture because - * it's not possible to implement that in single thread browser environment. - * Instead a method call, which would block in JVM, will act as if calling thread is interrupted - * immediately and will return null as a result. - */ - public T join() { -// if (!isDone()) { -// TODO: according to GWT Future's javadoc -// throw new IllegalStateException("blocking on CompletableFuture is not supported"); -// } - return getNow(null); - } - - public T getNow(T valueIfAbsent) { - return isDone() ? getJoinValue() : valueIfAbsent; - } - - private T getJoinValue() { - if(reason == null) { - return value; - } - - if(reason instanceof CancellationException) { - throw (CancellationException)reason; - } - if(reason instanceof CompletionException) { - throw (CompletionException)reason; - } - throw new CompletionException(reason); - } - - /** - * This method is a simple stub which returns 0. - * It's done for simplicity because this method is designed to be used in monitoring systems - * and has no use in GWT. - */ - public int getNumberOfDependents() { - return 0; - } - - public boolean complete(T value) { - return tryCompleteStage(value, null); - } - - public boolean completeExceptionally(Throwable e) { - checkNotNull(e); - return tryCompleteStage(null, e); - } - - public void obtrudeValue(T value) { - completeStage(value, null); - } - - public void obtrudeException(Throwable e) { - checkNotNull(e); - completeStage(null, e); - } - - private void tryCompleteValue(T value) { - tryCompleteStage(value, null); - } - - private void tryCompleteThrowable(Throwable reason) { - tryCompleteStage(null, wrap(reason)); - } - - private boolean tryCompleteStage(T value, Throwable reason) { - if(done) { - return false; - } - - completeStage(value, reason); - return true; - } - - private void completeStage(T value, Throwable reason) { - this.value = value; - this.reason = reason; - done = true; - if(reason == null) { - promise.resolve(value); - } - else { - promise.reject(reason); - } - } - - private void onStageComplete(BiConsumer action, Executor executor) { - if(done) { - runAsync(executor, action).accept(value, reason); // TODO - } - else { - promise.then(runAsync(executor, action)); - } - } - - private static RuntimeException wrap(Throwable t) { - if(t instanceof CompletionException) { - return (CompletionException)t; - } - return new CompletionException(t); - } -} diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/CompletableFutureUtils.java b/backends/backend-teavm/emu/emu/java/util/concurrent/CompletableFutureUtils.java deleted file mode 100644 index 0691efb3..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/CompletableFutureUtils.java +++ /dev/null @@ -1,23 +0,0 @@ -package emu.java.util.concurrent; - -public class CompletableFutureUtils { - /** - * Ensures that an object reference passed as a parameter to the calling method is not null. - */ - public static T checkNotNull(T reference) { - try { - checkCriticalNotNull(reference); - } - catch(Exception e) { - throw new AssertionError(e); - } - return reference; - } - - public static T checkCriticalNotNull(T reference) { - if(reference == null) { - throw new NullPointerException(); - } - return reference; - } -} \ No newline at end of file diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/CompletionException.java b/backends/backend-teavm/emu/emu/java/util/concurrent/CompletionException.java deleted file mode 100644 index 62b6687c..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/CompletionException.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2016 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 emu.java.util.concurrent; - -/** - * Emulation of CompletionException. - */ -public class CompletionException extends IllegalStateException { - - public CompletionException() { - } - - public CompletionException(String message) { - super(message); - } - - public CompletionException(String message, Throwable cause) { - super(message, cause); - } - - public CompletionException(Throwable cause) { - super(cause); - } -} \ No newline at end of file diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/CompletionStage.java b/backends/backend-teavm/emu/emu/java/util/concurrent/CompletionStage.java deleted file mode 100644 index fbbb5018..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/CompletionStage.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2016 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 emu.java.util.concurrent; - -import java.util.function.BiConsumer; -import java.util.function.BiFunction; -import java.util.function.Consumer; -import java.util.function.Function; - -/** - * Emulation of CompletionStage. - * See - * - * the official Java API doc for details. - */ -public interface CompletionStage { - - CompletionStage applyToEither(CompletionStage other, - Function fn); - - CompletionStage applyToEitherAsync(CompletionStage other, - Function fn); - - CompletionStage applyToEitherAsync(CompletionStage other, - Function fn, Executor executor); - - CompletionStage acceptEither(CompletionStage other, Consumer action); - - CompletionStage acceptEitherAsync(CompletionStage other, - Consumer action); - - CompletionStage acceptEitherAsync(CompletionStage other, - Consumer action, Executor executor); - - CompletionStage thenAccept(Consumer action); - - CompletionStage thenAcceptAsync(Consumer action); - - CompletionStage thenAcceptAsync(Consumer action, Executor executor); - - CompletionStage thenAcceptBoth(CompletionStage other, - BiConsumer action); - - CompletionStage thenAcceptBothAsync(CompletionStage other, - BiConsumer action); - - CompletionStage thenAcceptBothAsync(CompletionStage other, - BiConsumer action, Executor executor); - - CompletionStage thenApply(Function fn); - - CompletionStage thenApplyAsync(Function fn); - - CompletionStage thenApplyAsync(Function fn, Executor executor); - - CompletionStage thenCombine(CompletionStage other, - BiFunction fn); - - CompletionStage thenCombineAsync(CompletionStage other, - BiFunction fn); - - CompletionStage thenCombineAsync(CompletionStage other, - BiFunction fn, Executor executor); - - CompletionStage thenCompose(Function> fn); - - CompletionStage thenComposeAsync(Function> fn); - - CompletionStage thenComposeAsync(Function> fn, - Executor executor); - - CompletionStage thenRun(Runnable action); - - CompletionStage thenRunAsync(Runnable action); - - CompletionStage thenRunAsync(Runnable action, Executor executor); - - CompletionStage runAfterBoth(CompletionStage other, Runnable action); - - CompletionStage runAfterBothAsync(CompletionStage other, Runnable action); - - CompletionStage runAfterBothAsync(CompletionStage other, Runnable action, Executor executor); - - CompletionStage runAfterEither(CompletionStage other, Runnable action); - - CompletionStage runAfterEitherAsync(CompletionStage other, Runnable action); - - CompletionStage runAfterEitherAsync(CompletionStage other, Runnable action, - Executor executor); - - CompletionStage whenComplete(BiConsumer action); - - CompletionStage whenCompleteAsync(BiConsumer action); - - CompletionStage whenCompleteAsync(BiConsumer action, - Executor executor); - - CompletionStage exceptionally(Function fn); - - CompletionStage handle(BiFunction fn); - - CompletionStage handleAsync(BiFunction fn); - - CompletionStage handleAsync(BiFunction fn, - Executor executor); - - CompletableFuture toCompletableFuture(); -} \ No newline at end of file diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/Delayed.java b/backends/backend-teavm/emu/emu/java/util/concurrent/Delayed.java deleted file mode 100644 index 85af9b6c..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/Delayed.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2016 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 emu.java.util.concurrent; - -/** - * Emulation of Delayed. - */ -public interface Delayed extends Comparable { - long getDelay(TimeUnit unit); -} \ No newline at end of file diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/ExecutionException.java b/backends/backend-teavm/emu/emu/java/util/concurrent/ExecutionException.java deleted file mode 100644 index a883ed8c..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/ExecutionException.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2016 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 emu.java.util.concurrent; - -/** - * Emulation of ExecutionException. - */ -public class ExecutionException extends Exception { - protected ExecutionException() { - } - - protected ExecutionException(String message) { - super(message); - } - - public ExecutionException(String message, Throwable cause) { - super(message, cause); - } - - public ExecutionException(Throwable cause) { - super(cause); - } -} \ No newline at end of file diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/Executor.java b/backends/backend-teavm/emu/emu/java/util/concurrent/Executor.java deleted file mode 100644 index 38964462..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/Executor.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2016 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 emu.java.util.concurrent; - -/** - * Emulation of Executor. - */ -public interface Executor { - void execute(Runnable command); -} \ No newline at end of file diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/Executors.java b/backends/backend-teavm/emu/emu/java/util/concurrent/Executors.java deleted file mode 100644 index dc325ca4..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/Executors.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2016 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 emu.java.util.concurrent; - -/** - * Emulation of executors. - */ -public class Executors { - - public static Callable callable(Runnable task, T result) { - return new RunnableAdapter<>(task, result); - } - - public static Callable callable(Runnable task) { - return callable(task, null); - } - - private static class RunnableAdapter implements Callable { - - private final Runnable task; - private final T result; - - private RunnableAdapter(Runnable task, T result) { - this.task = CompletableFutureUtils.checkNotNull(task); - this.result = result; - } - - @Override - public T call() { - task.run(); - return result; - } - } - - private Executors() { - } -} \ No newline at end of file diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/Future.java b/backends/backend-teavm/emu/emu/java/util/concurrent/Future.java deleted file mode 100644 index 7f9cf785..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/Future.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2016 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 emu.java.util.concurrent; - -/** - * Emulation of Future. Since GWT environment is single threaded, attempting to block on the future - * by calling {@link #get()} or {@link #get(long, TimeUnit)} when it is not yet done is - * considered illegal because it would lead to a deadlock. Future implementations must throw - * {@link IllegalStateException} to avoid a deadlock. - * See - * - * the official Java API doc for details. - */ -public interface Future { - boolean cancel(boolean mayInterruptIfRunning); - - boolean isCancelled(); - - boolean isDone(); - - V get() throws InterruptedException, ExecutionException; - - V get(long timeout, TimeUnit unit) - throws InterruptedException, ExecutionException, TimeoutException; -} \ No newline at end of file diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/RejectedExecutionException.java b/backends/backend-teavm/emu/emu/java/util/concurrent/RejectedExecutionException.java deleted file mode 100644 index 632af2d5..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/RejectedExecutionException.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2016 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 emu.java.util.concurrent; - -/** - * GWT emulation of RejectedExecutionException. - */ -public class RejectedExecutionException extends RuntimeException { - public RejectedExecutionException() { - } - - public RejectedExecutionException(String message) { - super(message); - } - - public RejectedExecutionException(String message, Throwable cause) { - super(message, cause); - } - - public RejectedExecutionException(Throwable cause) { - super(cause); - } -} \ No newline at end of file diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/RunnableFuture.java b/backends/backend-teavm/emu/emu/java/util/concurrent/RunnableFuture.java deleted file mode 100644 index 5e29447e..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/RunnableFuture.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2016 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 emu.java.util.concurrent; - -/** - * Emulation of RunnableFuture. - */ -public interface RunnableFuture extends Runnable, Future { -} \ No newline at end of file diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/RunnableScheduledFuture.java b/backends/backend-teavm/emu/emu/java/util/concurrent/RunnableScheduledFuture.java deleted file mode 100644 index 88c31457..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/RunnableScheduledFuture.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2016 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 emu.java.util.concurrent; - -/** - * Emulation of RunnableScheduledFuture. - * - * @param value type returned by the future. - */ -public interface RunnableScheduledFuture extends RunnableFuture, ScheduledFuture { - - boolean isPeriodic(); -} \ No newline at end of file diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/ScheduledFuture.java b/backends/backend-teavm/emu/emu/java/util/concurrent/ScheduledFuture.java deleted file mode 100644 index f162acf2..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/ScheduledFuture.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2016 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 emu.java.util.concurrent; - -/** - * Emulation of ScheduleFuture. - * - * @param value type returned by the future. - */ -public interface ScheduledFuture extends Delayed, Future { -} \ No newline at end of file diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/TimeUnit.java b/backends/backend-teavm/emu/emu/java/util/concurrent/TimeUnit.java deleted file mode 100644 index d2ac20e7..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/TimeUnit.java +++ /dev/null @@ -1,389 +0,0 @@ -/* - * Copyright 2016 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 emu.java.util.concurrent; - -/** - * GWT emulation of TimeUnit, created by removing unsupported operations from - * Doug Lea's public domain version. - */ -public enum TimeUnit { - NANOSECONDS { - public long toNanos(long d) { - return d; - } - - public long toMicros(long d) { - return d / C1_C0; - } - - public long toMillis(long d) { - return d / C2_C0; - } - - public long toSeconds(long d) { - return d / C3_C0; - } - - public long toMinutes(long d) { - return d / C4_C0; - } - - public long toHours(long d) { - return d / C5_C0; - } - - public long toDays(long d) { - return d / C6_C0; - } - - public long convert(long d, TimeUnit u) { - return u.toNanos(d); - } - - int excessNanos(long d, long m) { - return (int)(d - (m * TimeUnit.C2)); - } - }, - MICROSECONDS { - public long toNanos(long d) { - return TimeUnit.x(d, C1_C0, MAX_C1_C0); - } - - public long toMicros(long d) { - return d; - } - - public long toMillis(long d) { - return d / C2_C1; - } - - public long toSeconds(long d) { - return d / C3_C1; - } - - public long toMinutes(long d) { - return d / C4_C1; - } - - public long toHours(long d) { - return d / C5_C1; - } - - public long toDays(long d) { - return d / C6_C1; - } - - public long convert(long d, TimeUnit u) { - return u.toMicros(d); - } - - int excessNanos(long d, long m) { - return (int)((d * TimeUnit.C1) - (m * TimeUnit.C2)); - } - }, - MILLISECONDS { - public long toNanos(long d) { - return TimeUnit.x(d, C2_C0, MAX_C2_C0); - } - - public long toMicros(long d) { - return TimeUnit.x(d, C2_C1, MAX_C2_C1); - } - - public long toMillis(long d) { - return d; - } - - public long toSeconds(long d) { - return d / C3_C2; - } - - public long toMinutes(long d) { - return d / C4_C2; - } - - public long toHours(long d) { - return d / C5_C2; - } - - public long toDays(long d) { - return d / C6_C2; - } - - public long convert(long d, TimeUnit u) { - return u.toMillis(d); - } - - int excessNanos(long d, long m) { - return 0; - } - }, - SECONDS { - public long toNanos(long d) { - return TimeUnit.x(d, C3_C0, MAX_C3_C0); - } - - public long toMicros(long d) { - return TimeUnit.x(d, C3_C1, MAX_C3_C1); - } - - public long toMillis(long d) { - return TimeUnit.x(d, C3_C2, MAX_C3_C2); - } - - public long toSeconds(long d) { - return d; - } - - public long toMinutes(long d) { - return d / C4_C3; - } - - public long toHours(long d) { - return d / C5_C3; - } - - public long toDays(long d) { - return d / C6_C3; - } - - public long convert(long d, TimeUnit u) { - return u.toSeconds(d); - } - - int excessNanos(long d, long m) { - return 0; - } - }, - MINUTES { - public long toNanos(long d) { - return TimeUnit.x(d, C4_C0, MAX_C4_C0); - } - - public long toMicros(long d) { - return TimeUnit.x(d, C4_C1, MAX_C4_C1); - } - - public long toMillis(long d) { - return TimeUnit.x(d, C4_C2, MAX_C4_C2); - } - - public long toSeconds(long d) { - return TimeUnit.x(d, C4_C3, MAX_C4_C3); - } - - public long toMinutes(long d) { - return d; - } - - public long toHours(long d) { - return d / C5_C4; - } - - public long toDays(long d) { - return d / C6_C4; - } - - public long convert(long d, TimeUnit u) { - return u.toMinutes(d); - } - - int excessNanos(long d, long m) { - return 0; - } - }, - HOURS { - public long toNanos(long d) { - return TimeUnit.x(d, C5_C0, MAX_C5_C0); - } - - public long toMicros(long d) { - return TimeUnit.x(d, C5_C1, MAX_C5_C1); - } - - public long toMillis(long d) { - return TimeUnit.x(d, C5_C2, MAX_C5_C2); - } - - public long toSeconds(long d) { - return TimeUnit.x(d, C5_C3, MAX_C5_C3); - } - - public long toMinutes(long d) { - return TimeUnit.x(d, C5_C4, MAX_C5_C4); - } - - public long toHours(long d) { - return d; - } - - public long toDays(long d) { - return d / C6_C5; - } - - public long convert(long d, TimeUnit u) { - return u.toHours(d); - } - - int excessNanos(long d, long m) { - return 0; - } - }, - DAYS { - public long toNanos(long d) { - return TimeUnit.x(d, C6_C0, MAX_C6_C0); - } - - public long toMicros(long d) { - return TimeUnit.x(d, C6_C1, MAX_C6_C1); - } - - public long toMillis(long d) { - return TimeUnit.x(d, C6_C2, MAX_C6_C2); - } - - public long toSeconds(long d) { - return TimeUnit.x(d, C6_C3, MAX_C6_C3); - } - - public long toMinutes(long d) { - return TimeUnit.x(d, C6_C4, MAX_C6_C4); - } - - public long toHours(long d) { - return TimeUnit.x(d, C6_C5, MAX_C6_C5); - } - - public long toDays(long d) { - return d; - } - - public long convert(long d, TimeUnit u) { - return u.toDays(d); - } - - int excessNanos(long d, long m) { - return 0; - } - }; - - // Handy constants for conversion methods - static final long C0 = 1L; - static final long C1 = C0 * 1000L; - static final long C2 = C1 * 1000L; - static final long C3 = C2 * 1000L; - static final long C4 = C3 * 60L; - static final long C5 = C4 * 60L; - static final long C6 = C5 * 24L; - - static final long MAX = Long.MAX_VALUE; - - static final long C6_C0 = C6 / C0; - static final long C6_C1 = C6 / C1; - static final long C6_C2 = C6 / C2; - static final long C6_C3 = C6 / C3; - static final long C6_C4 = C6 / C4; - static final long C6_C5 = C6 / C5; - - static final long C5_C0 = C5 / C0; - static final long C5_C1 = C5 / C1; - static final long C5_C2 = C5 / C2; - static final long C5_C3 = C5 / C3; - static final long C5_C4 = C5 / C4; - - static final long C4_C0 = C4 / C0; - static final long C4_C1 = C4 / C1; - static final long C4_C2 = C4 / C2; - static final long C4_C3 = C4 / C3; - - static final long C3_C0 = C3 / C0; - static final long C3_C1 = C3 / C1; - static final long C3_C2 = C3 / C2; - - static final long C2_C0 = C2 / C0; - static final long C2_C1 = C2 / C1; - - static final long C1_C0 = C1 / C0; - - static final long MAX_C6_C0 = MAX / C6_C0; - static final long MAX_C6_C1 = MAX / C6_C1; - static final long MAX_C6_C2 = MAX / C6_C2; - static final long MAX_C6_C3 = MAX / C6_C3; - static final long MAX_C6_C4 = MAX / C6_C4; - static final long MAX_C6_C5 = MAX / C6_C5; - - static final long MAX_C5_C0 = MAX / C5_C0; - static final long MAX_C5_C1 = MAX / C5_C1; - static final long MAX_C5_C2 = MAX / C5_C2; - static final long MAX_C5_C3 = MAX / C5_C3; - static final long MAX_C5_C4 = MAX / C5_C4; - - static final long MAX_C4_C0 = MAX / C4_C0; - static final long MAX_C4_C1 = MAX / C4_C1; - static final long MAX_C4_C2 = MAX / C4_C2; - static final long MAX_C4_C3 = MAX / C4_C3; - - static final long MAX_C3_C0 = MAX / C3_C0; - static final long MAX_C3_C1 = MAX / C3_C1; - static final long MAX_C3_C2 = MAX / C3_C2; - - static final long MAX_C2_C0 = MAX / C2_C0; - static final long MAX_C2_C1 = MAX / C2_C1; - - static final long MAX_C1_C0 = MAX / C1_C0; - - static long x(long d, long m, long over) { - if(d > over) return Long.MAX_VALUE; - if(d < -over) return Long.MIN_VALUE; - return d * m; - } - - // exceptions below changed from AbstractMethodError for GWT - - public long convert(long sourceDuration, TimeUnit sourceUnit) { - throw new AssertionError(); - } - - public long toNanos(long duration) { - throw new AssertionError(); - } - - public long toMicros(long duration) { - throw new AssertionError(); - } - - public long toMillis(long duration) { - throw new AssertionError(); - } - - public long toSeconds(long duration) { - throw new AssertionError(); - } - - public long toMinutes(long duration) { - throw new AssertionError(); - } - - public long toHours(long duration) { - throw new AssertionError(); - } - - public long toDays(long duration) { - throw new AssertionError(); - } - - abstract int excessNanos(long d, long m); -} \ No newline at end of file diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/TimeoutException.java b/backends/backend-teavm/emu/emu/java/util/concurrent/TimeoutException.java deleted file mode 100644 index 161323d3..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/TimeoutException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2016 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 emu.java.util.concurrent; - -/** - * Emulation of TimeoutException. - */ -public class TimeoutException extends Exception { - public TimeoutException() { - } - - public TimeoutException(String message) { - super(message); - } -} \ No newline at end of file diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/impl/DeferredExecutor.java b/backends/backend-teavm/emu/emu/java/util/concurrent/impl/DeferredExecutor.java deleted file mode 100644 index be538110..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/impl/DeferredExecutor.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2016 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 emu.java.util.concurrent.impl; - -import emu.java.util.concurrent.Executor; - -/** - * - */ -public final class DeferredExecutor implements Executor { - private final Promise resolvedPromise = Impl.IMPL.completed(null); - - @Override - public void execute(Runnable command) { - resolvedPromise.then(command); - } -} \ No newline at end of file diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/impl/Impl.java b/backends/backend-teavm/emu/emu/java/util/concurrent/impl/Impl.java deleted file mode 100644 index ada7ea76..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/impl/Impl.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2016 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 emu.java.util.concurrent.impl; - -import org.teavm.jso.JSBody; - -/** - * - */ -public class Impl { - - public static final Promises IMPL = isSupported() ? new NativePromisesImpl() : - new PromisesImpl(); - - @JSBody(script = "" + - "return typeof Promise === \"function\"\n" + - " // Some of these methods are missing from\n" + - " // Firefox/Chrome experimental implementations\n" + - " && \"resolve\" in Promise\n" + - " && \"reject\" in Promise\n" + - " && \"all\" in Promise\n" + - " && \"race\" in Promise\n" + - " // Older version of the spec had a resolver object\n" + - " // as the arg rather than a function\n" + - " && (function() {\n" + - " var resolve;\n" + - " new Promise(function(r) { resolve = r; });\n" + - " return typeof resolve === \"function\";\n" + - " }());") - private static native boolean isSupported(); - - private Impl() { - } -} \ No newline at end of file diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/impl/JsPromise.java b/backends/backend-teavm/emu/emu/java/util/concurrent/impl/JsPromise.java deleted file mode 100644 index c409629a..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/impl/JsPromise.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2016 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 emu.java.util.concurrent.impl; - -import org.teavm.jso.JSBody; -import org.teavm.jso.JSFunctor; -import org.teavm.jso.JSObject; -import org.teavm.platform.Platform; - -/** - * ECMA 6 Promise API. - * See - * - * MDN Promise documentation. - */ -//@JsType(isNative = true, name = "Promise", namespace = JsPackage.GLOBAL) -public abstract class JsPromise implements JSObject { - - @JSBody(params = {"promises"}, script = "return Promise.all(promises);") - public static native JsPromise all(JsPromise[] promises); - - @JSBody(params = {"promises"}, script = "return Promise.race(promises);") - public static native JsPromise race(JsPromise[] promises); - - @JSBody(params = {"reason"}, script = "return Promise.reject(reason);") - public static native JsPromise reject(JSObject reason); - - @JSBody(params = {"value"}, script = "return Promise.all(value);") - public static native JsPromise resolve(JSObject value); - - @JSBody(params = {"executor"}, script = "return new Promise(executor);") - public static native JsPromise create(Executor executor); - - public static JSObject asJsObject(Object javaObject) { - return Platform.getPlatformObject(javaObject).cast(); - } - - public static T asJavaObject(JSObject that) { - return (T)that; - } - - /* - * Method has no return value for simplicity because the return value of the method, - * onFulfilled and onRejected (OnSettledCallback) are not used. - */ - // TODO: $entry ? - @JSBody(params = {"onFulfilled", "onRejected"}, script = "then(onFulfilled, onRejected);") - public native void then(OnSettledCallback onFulfilled, - OnSettledCallback onRejected); - - @JSFunctor - interface Executor extends JSObject { - void executor(Resolver resolve, Rejector reject); - } - - @JSFunctor - interface Resolver extends JSObject { - void resolve(JSObject value); - } - - @JSFunctor - interface Rejector extends JSObject { - void reject(JSObject reason); - } - - /* - * Single interface for onFulfilled and onRejected callbacks are used for simplicity. - */ - @JSFunctor - interface OnSettledCallback extends JSObject { - void onSettled(JSObject value); - } -} \ No newline at end of file diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/impl/NativePromiseImpl.java b/backends/backend-teavm/emu/emu/java/util/concurrent/impl/NativePromiseImpl.java deleted file mode 100644 index 7c2c3045..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/impl/NativePromiseImpl.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2016 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 emu.java.util.concurrent.impl; - -import java.util.function.BiConsumer; -import org.teavm.jso.JSObject; - -/** - * - */ -final class NativePromiseImpl implements Promise { - - final JsPromise jsPromise; - private JsPromise.Resolver resolver; - private JsPromise.Rejector rejector; - - NativePromiseImpl() { - jsPromise = JsPromise.create((resolve, reject) -> { - resolver = resolve; - rejector = reject; - }); - } - - NativePromiseImpl(JsPromise promise) { - assert promise != null; - this.jsPromise = promise; - } - - @Override - public void resolve(V value) { - JSObject jsObject = JsPromise.asJsObject(value); - resolver.resolve(jsObject); - } - - @Override - public void reject(Throwable reason) { - assert reason != null; - JSObject jsObject = JsPromise.asJsObject(reason); - rejector.reject(jsObject); - } - - @SuppressWarnings("unchecked") - @Override - public void then(BiConsumer callback) { - assert callback != null; - - JsPromise.OnSettledCallback fullFilled = new JsPromise.OnSettledCallback() { - @Override - public void onSettled(JSObject reason) { - Object obj = JsPromise.asJavaObject(reason); - callback.accept((V)obj, null); - } - }; - - JsPromise.OnSettledCallback onRejected = new JsPromise.OnSettledCallback() { - @Override - public void onSettled(JSObject value) { - Object obj = JsPromise.asJavaObject(value); - callback.accept(null, (Throwable)obj); - } - }; - - jsPromise.then(fullFilled, onRejected); - } - - @Override - public void then(Runnable callback) { - assert callback != null; - JsPromise.OnSettledCallback func = value -> callback.run(); - jsPromise.then(func, func); - } -} \ No newline at end of file diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/impl/NativePromisesImpl.java b/backends/backend-teavm/emu/emu/java/util/concurrent/impl/NativePromisesImpl.java deleted file mode 100644 index 1e46fdd7..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/impl/NativePromisesImpl.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2016 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 emu.java.util.concurrent.impl; - -/** - * - */ -final class NativePromisesImpl implements Promises { - - @Override - public Promise allOf(Promise[] promises) { - assert promises.length > 0; - return new NativePromiseImpl<>(JsPromise.all(unwrap(promises))); - } - - @Override - public Promise anyOf(Promise[] promises) { - assert promises.length > 0; - return new NativePromiseImpl<>(JsPromise.race(unwrap(promises))); - } - - @Override - public Promise completed(V value) { - return new NativePromiseImpl<>(JsPromise.resolve(null)); - } - - @Override - public Promise incomplete() { - return new NativePromiseImpl<>(); - } - - private static JsPromise[] unwrap(Promise[] promises) { - int length = promises.length; - JsPromise[] jsPromises = new JsPromise[length]; - for(int i = 0; i < length; ++i) { - jsPromises[i] = ((NativePromiseImpl)promises[i]).jsPromise; - } - return jsPromises; - } -} \ No newline at end of file diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/impl/Promise.java b/backends/backend-teavm/emu/emu/java/util/concurrent/impl/Promise.java deleted file mode 100644 index d2e17a91..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/impl/Promise.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2016 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 emu.java.util.concurrent.impl; - -import java.util.function.BiConsumer; - -/** - * - */ -public interface Promise { - - void resolve(V value); - - void reject(Throwable reason); - - void then(BiConsumer callback); - - void then(Runnable callback); -} diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/impl/PromiseImpl.java b/backends/backend-teavm/emu/emu/java/util/concurrent/impl/PromiseImpl.java deleted file mode 100644 index f1782ca5..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/impl/PromiseImpl.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2016 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 emu.java.util.concurrent.impl; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.BiConsumer; -import org.teavm.jso.JSBody; -import org.teavm.jso.JSFunctor; -import org.teavm.jso.JSObject; - -/** - * - */ -final class PromiseImpl implements Promise { - private V value; - private Throwable reason; - private boolean done; - private final List callbacks = new ArrayList<>(); - - @Override - public void resolve(V value) { - complete(value, null); - } - - @Override - public void reject(Throwable reason) { - assert reason != null; - complete(null, reason); - } - - @Override - public void then(BiConsumer callback) { - assert callback != null; - Runnable run = new Runnable() { - @Override - public void run() { - callback.accept(value, reason); - } - }; - then(run); - } - - @Override - public void then(Runnable callback) { - assert callback != null; - callbacks.add(callback); - if(done) { - runCallbacks(); - } - } - - private void complete(V value, Throwable reason) { - if(!done) { - this.value = value; - this.reason = reason; - done = true; - runCallbacks(); - } - } - - private void runCallbacks() { - if(!callbacks.isEmpty()) { - TimerCallback callbackk = new TimerCallback() { - @Override - public void onTick() { - for(Runnable callback : callbacks) { - callback.run(); - } - callbacks.clear(); - } - }; - setTimeout(callbackk, 0); - } - } - - // TODO: use $entry? - @JSBody(params = {"callback", "time"}, script = "setTimeout(callback, time);") - private static native int setTimeout(TimerCallback callback, int time); - - @JSFunctor - private interface TimerCallback extends JSObject { - void onTick(); - } -} \ No newline at end of file diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/impl/Promises.java b/backends/backend-teavm/emu/emu/java/util/concurrent/impl/Promises.java deleted file mode 100644 index 88b615fa..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/impl/Promises.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2016 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 emu.java.util.concurrent.impl; - -/** - * - */ -public interface Promises { - - Promise allOf(Promise[] promises); - - Promise anyOf(Promise[] promises); - - Promise completed(V value); - - Promise incomplete(); -} \ No newline at end of file diff --git a/backends/backend-teavm/emu/emu/java/util/concurrent/impl/PromisesImpl.java b/backends/backend-teavm/emu/emu/java/util/concurrent/impl/PromisesImpl.java deleted file mode 100644 index 48af8fb8..00000000 --- a/backends/backend-teavm/emu/emu/java/util/concurrent/impl/PromisesImpl.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2016 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 emu.java.util.concurrent.impl; - -import java.util.function.BiConsumer; - -/** - * - */ -final class PromisesImpl implements Promises { - @Override - public Promise allOf(Promise[] promises) { - assert promises.length > 0; - - Promise andPromise = new PromiseImpl<>(); - BiConsumer callback = new BiConsumer() { - int counter = promises.length; - - @Override - public void accept(Object value, Throwable e) { - if(e != null) { - andPromise.reject(e); - } - else if(--counter == 0) { - andPromise.resolve(null); - } - } - }; - - for(Promise promise : promises) { - promise.then(callback); - } - return andPromise; - } - - @Override - public Promise anyOf(Promise[] promises) { - assert promises.length > 0; - - Promise orPromise = new PromiseImpl<>(); - BiConsumer callback = (value, e) -> { - if(e != null) { - orPromise.reject(e); - } - else { - orPromise.resolve(value); - } - }; - - for(Promise promise : promises) { - promise.then(callback); - } - return orPromise; - } - - @Override - public Promise completed(V value) { - PromiseImpl promise = new PromiseImpl<>(); - promise.resolve(value); - return promise; - } - - @Override - public Promise incomplete() { - return new PromiseImpl<>(); - } -} \ No newline at end of file