From ef7e65989e98e1c84718af8f1f261f52e5ba7ad3 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 20 Feb 2018 14:23:14 +0100 Subject: [PATCH] =?UTF-8?q?Promise=20=E2=80=94=20add=20onError=20and=20onS?= =?UTF-8?q?uccess?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prefix "on" makes method purpose more clear (especially if you are not familiar with "signals" concept). --- .../debugger/actions/ArrayAction.java | 20 +----- .../org/jetbrains/ide/OpenFileHttpService.kt | 26 ++------ .../runners/AsyncGenericProgramRunner.java | 18 +----- .../impl/AsyncProjectViewSupport.java | 22 ++++--- .../com/intellij/ui/tree/AsyncTreeModel.java | 27 ++------ .../jetbrains/concurrency/AsyncPromiseTest.kt | 7 +- .../org/jetbrains/concurrency/AsyncPromise.kt | 44 +++++++------ .../jetbrains/concurrency/DonePromise.java | 12 ++-- .../org/jetbrains/concurrency/Promise.java | 31 ++++++++- .../jetbrains/concurrency/RejectedPromise.kt | 14 ++-- .../src/org/jetbrains/concurrency/promise.kt | 64 +++++++++++-------- .../backend/src/debugger/SuspendContext.kt | 43 +++++-------- .../src/debugger/SuspendContextManagerBase.kt | 20 +----- .../backend/src/rpc/CommandProcessor.kt | 21 ++---- .../backend/src/rpc/CommandSenderBase.kt | 36 ++++------- .../backend/src/rpc/UnsafeSetResult.java | 15 +++++ .../src/BasicDebuggerViewSupport.kt | 24 ++----- .../debugger-ui/src/DebugProcessImpl.kt | 19 +----- .../src/FunctionScopesValueGroup.kt | 20 +----- .../debugger-ui/src/ScopeVariablesGroup.kt | 26 ++------ .../debugger-ui/src/SuspendContextView.kt | 18 +----- .../debugger-ui/src/VariableView.kt | 18 +++--- .../jetbrains/debugger/RejectErrorReporter.kt | 20 +----- 23 files changed, 218 insertions(+), 347 deletions(-) create mode 100644 platform/script-debugger/backend/src/rpc/UnsafeSetResult.java diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/ArrayAction.java b/java/debugger/impl/src/com/intellij/debugger/actions/ArrayAction.java index f65b81fc94f5..0003f6a0ceda 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/ArrayAction.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/ArrayAction.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.debugger.actions; import com.intellij.debugger.engine.DebugProcessImpl; @@ -65,7 +51,7 @@ public abstract class ArrayAction extends DebuggerAction { // title = title + " " + label.substring(index); //} createNewRenderer(node, renderer, debuggerContext, node.getName()) - .done(newRenderer -> setArrayRenderer(newRenderer, node, debuggerContext)); + .onSuccess(newRenderer -> setArrayRenderer(newRenderer, node, debuggerContext)); } @NotNull @@ -119,7 +105,7 @@ public abstract class ArrayAction extends DebuggerAction { if (debugProcess != null) { debugProcess.getManagerThread().schedule(new SuspendContextCommandImpl(debuggerContext.getSuspendContext()) { @Override - public void contextAction(@NotNull SuspendContextImpl suspendContext) throws Exception { + public void contextAction(@NotNull SuspendContextImpl suspendContext) { final Renderer lastRenderer = descriptor.getLastRenderer(); if (lastRenderer instanceof ArrayRenderer) { ((JavaValue)container).setRenderer(newRenderer, node); diff --git a/platform/built-in-server/src/org/jetbrains/ide/OpenFileHttpService.kt b/platform/built-in-server/src/org/jetbrains/ide/OpenFileHttpService.kt index a0e7c737ad67..f486622c481f 100644 --- a/platform/built-in-server/src/org/jetbrains/ide/OpenFileHttpService.kt +++ b/platform/built-in-server/src/org/jetbrains/ide/OpenFileHttpService.kt @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2015 JetBrains s.r.o. - * - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.ide import com.intellij.ide.impl.ProjectUtil.focusProjectWindow @@ -118,7 +104,7 @@ internal class OpenFileHttpService : RestService() { } val promise = openFile(apiRequest, context, request) ?: return null - promise.done { sendStatus(HttpResponseStatus.OK, keepAlive, channel) } + promise.onSuccess { sendStatus(HttpResponseStatus.OK, keepAlive, channel) } .rejected { if (it === NOT_FOUND) { // don't expose file status @@ -134,7 +120,7 @@ internal class OpenFileHttpService : RestService() { return null } - internal fun openFile(request: OpenFileRequest, context: ChannelHandlerContext, httpRequest: HttpRequest?): Promise? { + internal fun openFile(request: OpenFileRequest, context: ChannelHandlerContext, httpRequest: HttpRequest?): Promise? { val systemIndependentPath = FileUtil.toSystemIndependentName(FileUtil.expandUserHome(request.file!!)) val file = Paths.get(FileUtil.toSystemDependentName(systemIndependentPath)) if (file.isAbsolute) { @@ -198,7 +184,7 @@ internal class OpenFileRequest { } private class OpenFileTask(internal val path: String, internal val request: OpenFileRequest) { - internal val promise = AsyncPromise() + internal val promise = AsyncPromise() } private fun navigate(project: Project?, file: VirtualFile, request: OpenFileRequest) { @@ -251,8 +237,8 @@ private fun openRelativePath(path: String, request: OpenFileRequest): Boolean { } ?: false } -private fun openAbsolutePath(file: Path, request: OpenFileRequest): Promise { - val promise = AsyncPromise() +private fun openAbsolutePath(file: Path, request: OpenFileRequest): Promise { + val promise = AsyncPromise() ApplicationManager.getApplication().invokeLater { promise.catchError { val virtualFile = runWriteAction { LocalFileSystem.getInstance().refreshAndFindFileByPath(file.systemIndependentPath) } diff --git a/platform/lang-api/src/com/intellij/execution/runners/AsyncGenericProgramRunner.java b/platform/lang-api/src/com/intellij/execution/runners/AsyncGenericProgramRunner.java index 7d2c4f661236..6aaac8fa2103 100644 --- a/platform/lang-api/src/com/intellij/execution/runners/AsyncGenericProgramRunner.java +++ b/platform/lang-api/src/com/intellij/execution/runners/AsyncGenericProgramRunner.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.runners; import com.intellij.execution.ExecutionException; @@ -37,7 +23,7 @@ public abstract class AsyncGenericProgramRunner @Nullable Callback callback, @NotNull RunProfileState state) throws ExecutionException { prepare(environment, state) - .done(result -> UIUtil.invokeLaterIfNeeded(() -> { + .onSuccess(result -> UIUtil.invokeLaterIfNeeded(() -> { if (!environment.getProject().isDisposed()) { startRunProfile(environment, state, callback, result); } diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/AsyncProjectViewSupport.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/AsyncProjectViewSupport.java index e8060a126060..4aa26a861f95 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/AsyncProjectViewSupport.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/AsyncProjectViewSupport.java @@ -35,10 +35,9 @@ import com.intellij.util.ui.tree.TreeUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.concurrency.Promise; -import javax.swing.JTree; +import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; - import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -207,7 +206,10 @@ class AsyncProjectViewSupport { } private void acceptAndUpdate(TreeVisitor visitor, List list, boolean structure) { - if (visitor != null) myAsyncTreeModel.accept(visitor, false).done(path -> update(list, structure)); + if (visitor != null) { + myAsyncTreeModel.accept(visitor, false) + .onSuccess(path -> update(list, structure)); + } } private void updatePresentationsFromRootTo(@NotNull VirtualFile file) { @@ -238,15 +240,17 @@ class AsyncProjectViewSupport { void accept(List visitors, Consumer> consumer) { if (visitors != null && !visitors.isEmpty()) { if (1 == visitors.size()) { - myAsyncTreeModel.accept(visitors.get(0)).done(path -> { - if (path != null) consumer.consume(singletonList(path)); - }); + myAsyncTreeModel.accept(visitors.get(0)) + .onSuccess(path -> { + if (path != null) consumer.consume(singletonList(path)); + }); } else { List> promises = visitors.stream().map(visitor -> myAsyncTreeModel.accept(visitor)).collect(toList()); - collectResults(promises, true).done(list -> { - if (list != null && !list.isEmpty()) consumer.consume(list); - }); + collectResults(promises, true) + .onSuccess(list -> { + if (list != null && !list.isEmpty()) consumer.consume(list); + }); } } } diff --git a/platform/platform-impl/src/com/intellij/ui/tree/AsyncTreeModel.java b/platform/platform-impl/src/com/intellij/ui/tree/AsyncTreeModel.java index 2ab31d7e1077..60f5c3e1bf86 100644 --- a/platform/platform-impl/src/com/intellij/ui/tree/AsyncTreeModel.java +++ b/platform/platform-impl/src/com/intellij/ui/tree/AsyncTreeModel.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ui.tree; import com.intellij.openapi.Disposable; @@ -36,7 +22,6 @@ import javax.swing.event.TreeModelEvent; import javax.swing.event.TreeModelListener; import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; - import java.util.*; import java.util.Map.Entry; import java.util.function.IntFunction; @@ -165,8 +150,8 @@ public final class AsyncTreeModel extends AbstractTreeModel implements Identifia onValidThread(() -> async.setError("rejected")); } else { - promise.rejected(onValidThread(async::setError)); - promise.done(onValidThread(path -> resolve(async, path))); + promise.onError(onValidThread(async::setError)); + promise.onSuccess(onValidThread(path -> resolve(async, path))); } return async; } @@ -256,7 +241,9 @@ public final class AsyncTreeModel extends AbstractTreeModel implements Identifia @Override protected Collection getChildren(@NotNull Node node) { if (node.leaf || !allowLoading) return node.getChildren(); - promiseChildren(node).done(parent -> setChildren(parent.getChildren())).rejected(this::setError); + promiseChildren(node) + .onSuccess(parent -> setChildren(parent.getChildren())) + .onError(this::setError); return null; } }; @@ -288,7 +275,7 @@ public final class AsyncTreeModel extends AbstractTreeModel implements Identifia } @NotNull - private Consumer onValidThread(Consumer consumer) { + private java.util.function.Consumer onValidThread(Consumer consumer) { return value -> onValidThread(() -> consumer.consume(value)); } diff --git a/platform/platform-tests/testSrc/org/jetbrains/concurrency/AsyncPromiseTest.kt b/platform/platform-tests/testSrc/org/jetbrains/concurrency/AsyncPromiseTest.kt index 4144bcd2a840..de1c09663ff7 100644 --- a/platform/platform-tests/testSrc/org/jetbrains/concurrency/AsyncPromiseTest.kt +++ b/platform/platform-tests/testSrc/org/jetbrains/concurrency/AsyncPromiseTest.kt @@ -36,7 +36,8 @@ class AsyncPromiseTest { val count = AtomicInteger() val r = { - promise.done { count.incrementAndGet() } + promise + .onSuccess { count.incrementAndGet() } } val s = { @@ -101,10 +102,10 @@ class AsyncPromiseTest { val r = { if (reject) { - promise.rejected { count.incrementAndGet() } + promise.onError { count.incrementAndGet() } } else { - promise.done { count.incrementAndGet() } + promise.onSuccess { count.incrementAndGet() } } } diff --git a/platform/projectModel-api/src/org/jetbrains/concurrency/AsyncPromise.kt b/platform/projectModel-api/src/org/jetbrains/concurrency/AsyncPromise.kt index eb4250dbdce3..cbb688340a6d 100644 --- a/platform/projectModel-api/src/org/jetbrains/concurrency/AsyncPromise.kt +++ b/platform/projectModel-api/src/org/jetbrains/concurrency/AsyncPromise.kt @@ -3,7 +3,6 @@ package org.jetbrains.concurrency import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.util.Getter -import com.intellij.util.Consumer import com.intellij.util.Function import org.jetbrains.concurrency.Promise.State import java.util.* @@ -11,12 +10,13 @@ import java.util.concurrent.CountDownLatch import java.util.concurrent.TimeUnit import java.util.concurrent.TimeoutException import java.util.concurrent.atomic.AtomicReference +import java.util.function.Consumer private val LOG = Logger.getInstance(AsyncPromise::class.java) private data class PromiseValue(val result: T? = null, val error: Throwable? = null) -open class AsyncPromise : Promise, Getter, CancellablePromise { +open class AsyncPromise : Promise, Getter, CancellablePromise { private val doneRef = AtomicReference?>() private val rejectedRef = AtomicReference?>() @@ -31,13 +31,18 @@ open class AsyncPromise : Promise, Getter, CancellablePromise { } } - override fun done(done: Consumer): Promise { + override fun onSuccess(done: Consumer): Promise { setHandler(doneRef, done, State.FULFILLED) return this } - override fun rejected(rejected: Consumer): Promise { - setHandler(rejectedRef, rejected, State.REJECTED) + override fun rejected(rejected: com.intellij.util.Consumer): Promise { + setHandler(rejectedRef, Consumer { rejected.consume(it) }, State.REJECTED) + return this + } + + override fun onError(errorHandler: Consumer): Promise { + setHandler(rejectedRef, errorHandler, State.REJECTED) return this } @@ -83,8 +88,8 @@ open class AsyncPromise : Promise, Getter, CancellablePromise { addHandlers(Consumer({ promise.catchError { handler.`fun`(it) - .done { promise.catchError { promise.setResult(it) } } - .rejected(rejectedHandler) + .onSuccess { promise.catchError { promise.setResult(it) } } + .onError(rejectedHandler) } }), rejectedHandler) return promise @@ -96,9 +101,10 @@ open class AsyncPromise : Promise, Getter, CancellablePromise { } val value = valueRef.get() + @Suppress("UNCHECKED_CAST") when { value == null -> addHandlers(Consumer({ child.catchError { child.setResult(it) } }), Consumer({ child.setError(it) })) - value.error == null -> child.setResult(value.result) + value.error == null -> child.setResult(value.result as T) else -> child.setError(value.error) } return this @@ -109,7 +115,7 @@ open class AsyncPromise : Promise, Getter, CancellablePromise { setHandler(rejectedRef, rejected, State.REJECTED) } - fun setResult(result: T?) { + fun setResult(result: T) { if (!valueRef.compareAndSet(null, PromiseValue(result = result))) { return } @@ -118,7 +124,7 @@ open class AsyncPromise : Promise, Getter, CancellablePromise { rejectedRef.set(null) if (done != null && !isObsolete(done)) { - done.consume(result) + done.accept(result) } } @@ -141,14 +147,14 @@ open class AsyncPromise : Promise, Getter, CancellablePromise { LOG.errorIfNotMessage(error) } else if (!isObsolete(rejected)) { - rejected.consume(error) + rejected.accept(error) } return true } - override fun processed(processed: Consumer): Promise { - done(processed) - rejected { processed.consume(null) } + override fun onProcessed(action: Consumer): Promise { + onSuccess { action.accept(it) } + onError { action.accept(null) } return this } @@ -223,11 +229,11 @@ open class AsyncPromise : Promise, Getter, CancellablePromise { } } - private fun callConsumerIfTargeted(targetState: State, newConsumer: Consumer, value: PromiseValue) { + private fun callConsumerIfTargeted(targetState: State, newConsumer: Consumer, value: PromiseValue) { val currentState = if (value.error == null) State.FULFILLED else State.REJECTED if (currentState == targetState) { @Suppress("UNCHECKED_CAST") - newConsumer.consume(if (currentState == State.FULFILLED) value.result as C_T? else value.error as C_T) + newConsumer.accept(if (currentState == State.FULFILLED) value.result as C_T else value.error as C_T) } } @@ -260,7 +266,7 @@ private class CompoundConsumer(c1: Consumer, c2: Consumer) : Cons } } - override fun consume(t: T) { + override fun accept(t: T) { val list = synchronized(this) { val list = consumers consumers = null @@ -269,13 +275,13 @@ private class CompoundConsumer(c1: Consumer, c2: Consumer) : Cons for (consumer in list) { if (!isObsolete(consumer)) { - consumer.consume(t) + consumer.accept(t) } } } } -internal fun isObsolete(consumer: Consumer<*>?) = consumer is Obsolescent && consumer.isObsolete +internal fun isObsolete(consumer: Any) = consumer is Obsolescent && consumer.isObsolete inline fun AsyncPromise<*>.catchError(runnable: () -> T): T? { try { diff --git a/platform/projectModel-api/src/org/jetbrains/concurrency/DonePromise.java b/platform/projectModel-api/src/org/jetbrains/concurrency/DonePromise.java index 7f92d3eb0864..362354a4ec4e 100644 --- a/platform/projectModel-api/src/org/jetbrains/concurrency/DonePromise.java +++ b/platform/projectModel-api/src/org/jetbrains/concurrency/DonePromise.java @@ -2,7 +2,6 @@ package org.jetbrains.concurrency; import com.intellij.openapi.util.Getter; -import com.intellij.util.Consumer; import com.intellij.util.Function; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -11,6 +10,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import java.util.function.Consumer; import static org.jetbrains.concurrency.Promises.rejectedPromise; import static org.jetbrains.concurrency.Promises.resolvedPromise; @@ -24,9 +24,9 @@ class DonePromise implements Getter, Promise, Future { @NotNull @Override - public Promise done(@NotNull Consumer done) { + public Promise onSuccess(@NotNull Consumer done) { if (!AsyncPromiseKt.isObsolete(done)) { - done.consume(result); + done.accept(result); } return this; } @@ -43,14 +43,14 @@ class DonePromise implements Getter, Promise, Future { @NotNull @Override - public Promise processed(@NotNull Consumer processed) { - done(processed); + public Promise onProcessed(@NotNull Consumer processed) { + onSuccess(processed); return this; } @NotNull @Override - public Promise rejected(@NotNull Consumer rejected) { + public Promise onError(@NotNull Consumer rejected) { return this; } diff --git a/platform/projectModel-api/src/org/jetbrains/concurrency/Promise.java b/platform/projectModel-api/src/org/jetbrains/concurrency/Promise.java index 2cd5442d150a..4cda651ea43d 100644 --- a/platform/projectModel-api/src/org/jetbrains/concurrency/Promise.java +++ b/platform/projectModel-api/src/org/jetbrains/concurrency/Promise.java @@ -71,13 +71,30 @@ public interface Promise { * Execute passed handler on promise resolve. */ @NotNull - Promise done(@NotNull Consumer done); + Promise onSuccess(@NotNull java.util.function.Consumer done); + + /** + * Execute passed handler on promise resolve. + * @deprecated Use {@link #onSuccess(java.util.function.Consumer)} + */ + @NotNull + default Promise done(@NotNull Consumer done) { + return onSuccess(it -> done.consume(it)); + } /** * Execute passed handler on promise reject. */ @NotNull - Promise rejected(@NotNull Consumer rejected); + Promise onError(@NotNull java.util.function.Consumer rejected); + + /** + * Execute passed handler on promise reject. + */ + @NotNull + default Promise rejected(@NotNull Consumer rejected) { + return onError(it -> rejected.consume(it)); + } /** * Resolve or reject passed promise as soon as this promise resolved or rejected. @@ -89,7 +106,15 @@ public interface Promise { * Execute passed handler on promise resolve (result value will be passed), * or on promise reject (null as result value will be passed). */ - Promise processed(@NotNull Consumer processed); + Promise onProcessed(@NotNull java.util.function.Consumer processed); + + /** + * Execute passed handler on promise resolve (result value will be passed), + * or on promise reject (null as result value will be passed). + */ + default Promise processed(@NotNull Consumer action) { + return onProcessed(it -> action.consume(it)); + } /** * Get promise state. diff --git a/platform/projectModel-api/src/org/jetbrains/concurrency/RejectedPromise.kt b/platform/projectModel-api/src/org/jetbrains/concurrency/RejectedPromise.kt index 83bd40275fec..fb3645575a47 100644 --- a/platform/projectModel-api/src/org/jetbrains/concurrency/RejectedPromise.kt +++ b/platform/projectModel-api/src/org/jetbrains/concurrency/RejectedPromise.kt @@ -1,16 +1,16 @@ // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.concurrency -import com.intellij.util.Consumer import com.intellij.util.Function import java.util.concurrent.Future import java.util.concurrent.TimeUnit +import java.util.function.Consumer internal class RejectedPromise(private val error: Throwable) : Promise, Future { override fun getState() = Promise.State.REJECTED - override fun done(done: Consumer) = this + override fun onSuccess(done: Consumer) = this override fun processed(child: Promise): Promise { if (child is AsyncPromise) { @@ -19,15 +19,15 @@ internal class RejectedPromise(private val error: Throwable) : Promise, Fu return this } - override fun rejected(rejected: Consumer): Promise { - if (!isObsolete(rejected)) { - rejected.consume(error) + override fun onError(action: Consumer): Promise { + if (!isObsolete(action)) { + action.accept(error) } return this } - override fun processed(processed: Consumer): RejectedPromise { - processed.consume(null) + override fun onProcessed(processed: Consumer): RejectedPromise { + processed.accept(null) return this } diff --git a/platform/projectModel-api/src/org/jetbrains/concurrency/promise.kt b/platform/projectModel-api/src/org/jetbrains/concurrency/promise.kt index a41c7b8c9fc7..4d5f60fd95d3 100644 --- a/platform/projectModel-api/src/org/jetbrains/concurrency/promise.kt +++ b/platform/projectModel-api/src/org/jetbrains/concurrency/promise.kt @@ -56,7 +56,7 @@ abstract class ValueNodeAsyncFunction(private val node: Obsolesce override fun isObsolete() = node.isObsolete } -abstract class ObsolescentConsumer(private val obsolescent: Obsolescent) : Obsolescent, Consumer { +abstract class ObsolescentConsumer(private val obsolescent: Obsolescent) : Obsolescent, java.util.function.Consumer { override fun isObsolete() = obsolescent.isObsolete } @@ -67,20 +67,20 @@ inline fun Promise.then(obsolescent: Obsolescent, crossinline }) -inline fun Promise.done(node: Obsolescent, crossinline handler: (T) -> Unit) = done(object : ObsolescentConsumer(node) { - override fun consume(param: T) = handler(param) +inline fun Promise.onSuccess(node: Obsolescent, crossinline handler: (T) -> Unit) = onSuccess(object : ObsolescentConsumer(node) { + override fun accept(param: T) = handler(param) }) inline fun Promise<*>.processed(node: Obsolescent, crossinline handler: () -> Unit): Promise? { @Suppress("UNCHECKED_CAST") return (this as Promise) - .processed(object : ObsolescentConsumer(node) { - override fun consume(param: Any?) = handler() + .onProcessed(object : ObsolescentConsumer(node) { + override fun accept(param: Any?) = handler() }) } @Suppress("UNCHECKED_CAST") -inline fun Promise<*>.doneRun(crossinline handler: () -> Unit) = done({ handler() }) +inline fun Promise<*>.doneRun(crossinline handler: () -> Unit) = onSuccess { handler() } @Suppress("UNCHECKED_CAST") inline fun Promise<*>.thenRun(crossinline handler: () -> T): Promise = (this as Promise).then({ handler() }) @@ -94,9 +94,11 @@ inline fun Promise.thenAsync(node: Obsolescent, crossinline h }) @Suppress("UNCHECKED_CAST") -inline fun Promise.thenAsyncAccept(node: Obsolescent, crossinline handler: (T) -> Promise<*>) = thenAsync(object : ValueNodeAsyncFunction(node) { - override fun `fun`(param: T) = handler(param) as Promise -}) +inline fun Promise.thenAsyncAccept(node: Obsolescent, crossinline handler: (T) -> Promise<*>): Promise { + return thenAsync(object : ValueNodeAsyncFunction(node) { + override fun `fun`(param: T) = handler(param) as Promise + }) +} inline fun Promise.thenAsyncAccept(crossinline handler: (T) -> Promise<*>) = thenAsync(Function> { param -> @Suppress("UNCHECKED_CAST") @@ -104,8 +106,8 @@ inline fun Promise.thenAsyncAccept(crossinline handler: (T) -> Promise<*> }) -inline fun Promise<*>.rejected(node: Obsolescent, crossinline handler: (Throwable) -> Unit) = rejected(object : ObsolescentConsumer(node) { - override fun consume(param: Throwable) = handler(param) +inline fun Promise<*>.onError(node: Obsolescent, crossinline handler: (Throwable) -> Unit) = onError(object : ObsolescentConsumer(node) { + override fun accept(param: Throwable) = handler(param) }) @JvmOverloads @@ -116,7 +118,7 @@ fun collectResults(promises: List>, ignoreErrors: Boolean = false val results: MutableList = if (promises.size == 1) SmartList() else ArrayList(promises.size) for (promise in promises) { - promise.done { results.add(it) } + promise.onSuccess { results.add(it) } } return all(promises, results, ignoreErrors) } @@ -125,10 +127,15 @@ fun collectResults(promises: List>, ignoreErrors: Boolean = false fun createError(error: String, log: Boolean = false): RuntimeException = MessageError(error, log) inline fun AsyncPromise.compute(runnable: () -> T) { - val result = catchError(runnable) - if (!isRejected) { - setResult(result) + val result = try { + runnable() } + catch (e: Throwable) { + setError(e) + return + } + + setResult(result) } inline fun runAsync(crossinline runnable: () -> T): Promise { @@ -172,16 +179,17 @@ fun Logger.errorIfNotMessage(e: Throwable): Boolean { return false } -fun ActionCallback.toPromise(): Promise { - val promise = AsyncPromise() - doWhenDone { promise.setResult(null) }.doWhenRejected { error -> promise.setError(createError(error ?: "Internal error")) } +fun ActionCallback.toPromise(): Promise { + val promise = AsyncPromise() + doWhenDone { promise.setResult(null) } + .doWhenRejected { error -> promise.setError(createError(error ?: "Internal error")) } return promise } fun all(promises: Collection>): Promise<*> = if (promises.size == 1) promises.first() else all(promises, null) @JvmOverloads -fun all(promises: Collection>, totalResult: T?, ignoreErrors: Boolean = false): Promise { +fun all(promises: Collection>, totalResult: T, ignoreErrors: Boolean = false): Promise { if (promises.isEmpty()) { @Suppress("UNCHECKED_CAST") return DONE as Promise @@ -190,21 +198,21 @@ fun all(promises: Collection>, totalResult: T?, ignoreErrors: Boo val totalPromise = AsyncPromise() val done = CountDownConsumer(promises.size, totalPromise, totalResult) val rejected = if (ignoreErrors) { - Consumer { done.consume(null) } + Consumer { done.accept(null) } } else { Consumer { totalPromise.setError(it) } } for (promise in promises) { - promise.done(done) + promise.onSuccess(done) promise.rejected(rejected) } return totalPromise } -private class CountDownConsumer(@Volatile private var countDown: Int, private val promise: AsyncPromise, private val totalResult: T?) : Consumer { - override fun consume(t: Any?) { +private class CountDownConsumer(@Volatile private var countDown: Int, private val promise: AsyncPromise, private val totalResult: T) : java.util.function.Consumer { + override fun accept(t: Any?) { if (--countDown == 0) { promise.setResult(totalResult) } @@ -221,11 +229,11 @@ fun any(promises: Collection>, totalError: String): Promise { } val totalPromise = AsyncPromise() - val done = Consumer { result -> totalPromise.setResult(result) } - val rejected = object : Consumer { + val done = java.util.function.Consumer { result -> totalPromise.setResult(result) } + val rejected = object : java.util.function.Consumer { @Volatile private var toConsume = promises.size - override fun consume(throwable: Throwable) { + override fun accept(throwable: Throwable) { if (--toConsume <= 0) { totalPromise.setError(totalError) } @@ -233,8 +241,8 @@ fun any(promises: Collection>, totalError: String): Promise { } for (promise in promises) { - promise.done(done) - promise.rejected(rejected) + promise.onSuccess(done) + promise.onError(rejected) } return totalPromise } \ No newline at end of file diff --git a/platform/script-debugger/backend/src/debugger/SuspendContext.kt b/platform/script-debugger/backend/src/debugger/SuspendContext.kt index f8e8b572c1c3..4158e032d653 100755 --- a/platform/script-debugger/backend/src/debugger/SuspendContext.kt +++ b/platform/script-debugger/backend/src/debugger/SuspendContext.kt @@ -1,28 +1,13 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.debugger -import com.intellij.util.Consumer import org.jetbrains.concurrency.Promise import org.jetbrains.debugger.values.ValueManager /** * An object that matches the execution state of the VM while suspended */ -interface SuspendContext { +interface SuspendContext { val state: SuspendState val script: Script? @@ -60,22 +45,26 @@ interface SuspendContext { get() = throw UnsupportedOperationException() } -abstract class ContextDependentAsyncResultConsumer(private val context: SuspendContext<*>) : Consumer { - override final fun consume(result: T) { +abstract class ContextDependentAsyncResultConsumer(private val context: SuspendContext<*>) : java.util.function.Consumer { + override final fun accept(result: T) { val vm = context.vm if (vm.attachStateManager.isAttached && !vm.suspendContextManager.isContextObsolete(context)) { - consume(result, vm) + accept(result, vm) } } - protected abstract fun consume(result: T, vm: Vm) + protected abstract fun accept(result: T, vm: Vm) } -inline fun Promise.done(context: SuspendContext<*>, crossinline handler: (result: T) -> Unit) = done(object : ContextDependentAsyncResultConsumer(context) { - override fun consume(result: T, vm: Vm) = handler(result) -}) +inline fun Promise.onSuccess(context: SuspendContext<*>, crossinline handler: (result: T) -> Unit): Promise { + return onSuccess(object : ContextDependentAsyncResultConsumer(context) { + override fun accept(result: T, vm: Vm) = handler(result) + }) +} -inline fun Promise<*>.rejected(context: SuspendContext<*>, crossinline handler: (error: Throwable) -> Unit) = rejected(object : ContextDependentAsyncResultConsumer(context) { - override fun consume(result: Throwable, vm: Vm) = handler(result) -}) \ No newline at end of file +inline fun Promise<*>.onError(context: SuspendContext<*>, crossinline handler: (error: Throwable) -> Unit): Promise { + return onError(object : ContextDependentAsyncResultConsumer(context) { + override fun accept(result: Throwable, vm: Vm) = handler(result) + }) +} \ No newline at end of file diff --git a/platform/script-debugger/backend/src/debugger/SuspendContextManagerBase.kt b/platform/script-debugger/backend/src/debugger/SuspendContextManagerBase.kt index 6ef94575366e..4f780e09c32a 100644 --- a/platform/script-debugger/backend/src/debugger/SuspendContextManagerBase.kt +++ b/platform/script-debugger/backend/src/debugger/SuspendContextManagerBase.kt @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.debugger import org.jetbrains.concurrency.AsyncPromise @@ -24,7 +10,7 @@ import java.util.concurrent.atomic.AtomicReference abstract class SuspendContextManagerBase, CALL_FRAME : CallFrame> : SuspendContextManager { val contextRef = AtomicReference() - protected val suspendCallback = AtomicReference>() + protected val suspendCallback = AtomicReference>() protected abstract val debugListener: DebugEventListener @@ -46,7 +32,7 @@ abstract class SuspendContextManagerBase, CAL protected fun dismissContextOnDone(promise: Promise<*>): Promise<*> { val context = contextOrFail - promise.done { contextDismissed(context) } + promise.onSuccess { contextDismissed(context) } return promise } diff --git a/platform/script-debugger/backend/src/rpc/CommandProcessor.kt b/platform/script-debugger/backend/src/rpc/CommandProcessor.kt index 04d2714a700e..6ed27be0106d 100644 --- a/platform/script-debugger/backend/src/rpc/CommandProcessor.kt +++ b/platform/script-debugger/backend/src/rpc/CommandProcessor.kt @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.rpc import com.intellij.openapi.diagnostic.Logger @@ -23,7 +9,10 @@ import java.util.concurrent.atomic.AtomicInteger val LOG = Logger.getInstance(CommandProcessor::class.java) -abstract class CommandProcessor() : CommandSenderBase(), MessageManager.Handler, INCOMING, INCOMING_WITH_SEQ, SUCCESS_RESPONSE>, ResultReader, MessageProcessor { +abstract class CommandProcessor : CommandSenderBase(), + MessageManager.Handler, INCOMING, INCOMING_WITH_SEQ, SUCCESS_RESPONSE>, + ResultReader, + MessageProcessor { private val currentSequence = AtomicInteger() protected val messageManager = MessageManager(this) diff --git a/platform/script-debugger/backend/src/rpc/CommandSenderBase.kt b/platform/script-debugger/backend/src/rpc/CommandSenderBase.kt index 789ff0637e38..40751ebea271 100644 --- a/platform/script-debugger/backend/src/rpc/CommandSenderBase.kt +++ b/platform/script-debugger/backend/src/rpc/CommandSenderBase.kt @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.rpc import org.jetbrains.concurrency.AsyncPromise @@ -23,28 +9,28 @@ import org.jetbrains.jsonProtocol.Request abstract class CommandSenderBase { protected abstract fun doSend(message: Request, callback: RequestPromise) - fun send(message: Request): Promise { + fun send(message: Request): Promise { val callback = RequestPromise(message.methodName) doSend(message, callback) return callback } } -class RequestPromise(private val methodName: String?) : AsyncPromise(), RequestCallback { +class RequestPromise(private val methodName: String?) : AsyncPromise(), RequestCallback { override fun onSuccess(response: SUCCESS_RESPONSE?, resultReader: ResultReader?) { catchError { + val r: Any? if (resultReader == null || response == null) { - @Suppress("UNCHECKED_CAST") - setResult(response as RESULT?) + r = response + } + else if (methodName == null) { + r = null } else { - if (methodName == null) { - setResult(null) - } - else { - setResult(resultReader.readResult(methodName, response)) - } + r = resultReader.readResult(methodName, response) } + + UnsafeSetResult.setResult(this, r) } } diff --git a/platform/script-debugger/backend/src/rpc/UnsafeSetResult.java b/platform/script-debugger/backend/src/rpc/UnsafeSetResult.java new file mode 100644 index 000000000000..aeed056864e9 --- /dev/null +++ b/platform/script-debugger/backend/src/rpc/UnsafeSetResult.java @@ -0,0 +1,15 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package org.jetbrains.rpc; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.concurrency.AsyncPromise; + +// we cannot fix all WIP types to be nullable for now, +// but don't want to to use explicitly nullable result type for method setResult +class UnsafeSetResult { + static void setResult(@NotNull AsyncPromise promise, @Nullable Object result) { + //noinspection unchecked + promise.setResult((T)result); + } +} diff --git a/platform/script-debugger/debugger-ui/src/BasicDebuggerViewSupport.kt b/platform/script-debugger/debugger-ui/src/BasicDebuggerViewSupport.kt index f32d3e5e5b70..73703b9f5543 100644 --- a/platform/script-debugger/debugger-ui/src/BasicDebuggerViewSupport.kt +++ b/platform/script-debugger/debugger-ui/src/BasicDebuggerViewSupport.kt @@ -1,26 +1,12 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.debugger import com.intellij.xdebugger.frame.XCompositeNode import com.intellij.xdebugger.frame.XValueChildrenList import com.intellij.xdebugger.frame.XValueNode import org.jetbrains.concurrency.Promise -import org.jetbrains.concurrency.done -import org.jetbrains.concurrency.rejected +import org.jetbrains.concurrency.onError +import org.jetbrains.concurrency.onSuccess import org.jetbrains.concurrency.resolvedPromise import org.jetbrains.debugger.values.ObjectValue import org.jetbrains.debugger.values.Value @@ -41,10 +27,10 @@ open class BasicDebuggerViewSupport : MemberFilter, DebuggerViewSupport { override fun computeReceiverVariable(context: VariableContext, callFrame: CallFrame, node: XCompositeNode): Promise<*> { return callFrame.receiverVariable - .done(node) { + .onSuccess(node) { node.addChildren(if (it == null) XValueChildrenList.EMPTY else XValueChildrenList.singleton(VariableView(it, context)), true) } - .rejected(node) { + .onError(node) { node.addChildren(XValueChildrenList.EMPTY, true) } } diff --git a/platform/script-debugger/debugger-ui/src/DebugProcessImpl.kt b/platform/script-debugger/debugger-ui/src/DebugProcessImpl.kt index 6477896ac148..6fcdb2ee5eae 100644 --- a/platform/script-debugger/debugger-ui/src/DebugProcessImpl.kt +++ b/platform/script-debugger/debugger-ui/src/DebugProcessImpl.kt @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.debugger import com.intellij.execution.ExecutionResult @@ -205,7 +191,8 @@ abstract class DebugProcessImpl>(session: XDebugSession, } override final fun startPausing() { - activeOrMainVm!!.suspendContextManager.suspend().rejected(RejectErrorReporter(session, "Cannot pause")) + activeOrMainVm!!.suspendContextManager.suspend() + .onError(RejectErrorReporter(session, "Cannot pause")) } override final fun getCurrentStateMessage() = connection.state.message diff --git a/platform/script-debugger/debugger-ui/src/FunctionScopesValueGroup.kt b/platform/script-debugger/debugger-ui/src/FunctionScopesValueGroup.kt index bb51d9cc2d5d..164a1c4ee058 100644 --- a/platform/script-debugger/debugger-ui/src/FunctionScopesValueGroup.kt +++ b/platform/script-debugger/debugger-ui/src/FunctionScopesValueGroup.kt @@ -1,25 +1,11 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.debugger import com.intellij.xdebugger.frame.XCompositeNode import com.intellij.xdebugger.frame.XValueChildrenList import com.intellij.xdebugger.frame.XValueGroup -import org.jetbrains.concurrency.done import org.jetbrains.concurrency.errorIfNotMessage +import org.jetbrains.concurrency.onSuccess import org.jetbrains.debugger.values.FunctionValue import org.jetbrains.rpc.LOG import java.util.* @@ -29,7 +15,7 @@ internal class FunctionScopesValueGroup(private val functionValue: FunctionValue node.setAlreadySorted(true) functionValue.resolve() - .done(node) { + .onSuccess(node) { val scopes = it.scopes if (scopes == null || scopes.size == 0) { node.addChildren(XValueChildrenList.EMPTY, true) diff --git a/platform/script-debugger/debugger-ui/src/ScopeVariablesGroup.kt b/platform/script-debugger/debugger-ui/src/ScopeVariablesGroup.kt index c189d69ca515..af853b25b1c4 100644 --- a/platform/script-debugger/debugger-ui/src/ScopeVariablesGroup.kt +++ b/platform/script-debugger/debugger-ui/src/ScopeVariablesGroup.kt @@ -1,26 +1,12 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.debugger import com.intellij.xdebugger.XDebuggerBundle import com.intellij.xdebugger.frame.XCompositeNode import com.intellij.xdebugger.frame.XValueChildrenList import com.intellij.xdebugger.frame.XValueGroup -import org.jetbrains.concurrency.done -import org.jetbrains.concurrency.rejected +import org.jetbrains.concurrency.onError +import org.jetbrains.concurrency.onSuccess import org.jetbrains.concurrency.thenAsyncAccept class ScopeVariablesGroup(val scope: Scope, parentContext: VariableContext, callFrame: CallFrame?) : XValueGroup(scope.createScopeNodeName()) { @@ -42,13 +28,13 @@ class ScopeVariablesGroup(val scope: Scope, parentContext: VariableContext, call } promise - .done(node) { + .onSuccess(node) { context.memberFilter .thenAsyncAccept(node) { if (it.hasNameMappings()) { it.sourceNameToRaw(RECEIVER_NAME)?.let { return@thenAsyncAccept callFrame.evaluateContext.evaluate(it) - .done(node) { + .onSuccess(node) { VariableImpl(RECEIVER_NAME, it.value, null) node.addChildren(XValueChildrenList.singleton(VariableView( VariableImpl(RECEIVER_NAME, it.value, null), context)), true) @@ -58,7 +44,7 @@ class ScopeVariablesGroup(val scope: Scope, parentContext: VariableContext, call context.viewSupport.computeReceiverVariable(context, callFrame, node) } - .rejected(node) { + .onError(node) { context.viewSupport.computeReceiverVariable(context, callFrame, node) } } diff --git a/platform/script-debugger/debugger-ui/src/SuspendContextView.kt b/platform/script-debugger/debugger-ui/src/SuspendContextView.kt index e9755062c385..3972407c8795 100644 --- a/platform/script-debugger/debugger-ui/src/SuspendContextView.kt +++ b/platform/script-debugger/debugger-ui/src/SuspendContextView.kt @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.debugger import com.intellij.icons.AllIcons @@ -196,7 +182,7 @@ class ExecutionStackView(val suspendContext: SuspendContext<*>, override fun computeStackFrames(firstFrameIndex: Int, container: XExecutionStack.XStackFrameContainer) { // WipSuspendContextManager set context to null on resume _before_ vm.getDebugListener().resumed() call() (in any case, XFramesView can queue event to EDT), so, IDE state could be outdated compare to VM (our) state suspendContext.frames - .done(suspendContext) { frames -> + .onSuccess(suspendContext) { frames -> val count = frames.size - firstFrameIndex val result: List if (count < 1) { diff --git a/platform/script-debugger/debugger-ui/src/VariableView.kt b/platform/script-debugger/debugger-ui/src/VariableView.kt index e00abe80bcd9..e71100eb6970 100644 --- a/platform/script-debugger/debugger-ui/src/VariableView.kt +++ b/platform/script-debugger/debugger-ui/src/VariableView.kt @@ -63,7 +63,7 @@ class VariableView(override val variableName: String, private val variable: Vari if (variable !is ObjectProperty || variable.getter == null) { // it is "used" expression (WEB-6779 Debugger/Variables: Automatically show used variables) evaluateContext.evaluate(variable.name) - .done(node) { + .onSuccess(node) { if (it.wasThrown) { setEvaluatedValue(viewSupport.transformErrorOnGetUsedReferenceValue(it.value, null), null, node) } @@ -72,7 +72,7 @@ class VariableView(override val variableName: String, private val variable: Vari computePresentation(it.value, node) } } - .rejected(node) { setEvaluatedValue(viewSupport.transformErrorOnGetUsedReferenceValue(null, it.message), it.message, node) } + .onError(node) { setEvaluatedValue(viewSupport.transformErrorOnGetUsedReferenceValue(null, it.message), it.message, node) } return } @@ -90,7 +90,7 @@ class VariableView(override val variableName: String, private val variable: Vari nonProtoContext = nonProtoContext.parent } valueModifier!!.evaluateGet(variable, evaluateContext) - .done(node) { + .onSuccess(node) { callback.evaluated("") setEvaluatedValue(it, null, node) } @@ -318,9 +318,9 @@ class VariableView(override val variableName: String, private val variable: Vari override fun computeSourcePosition(navigatable: XNavigatable) { if (value is FunctionValue) { (value as FunctionValue).resolve() - .done { function -> + .onSuccess { function -> vm!!.scriptManager.getScript(function) - .done { + .onSuccess { navigatable.setSourcePosition(it?.let { viewSupport.getSourceInfo(null, it, function.openParenLine, function.openParenColumn) }?.let { object : XSourcePositionWrapper(it) { override fun createNavigatable(project: Project): Navigatable { @@ -394,12 +394,12 @@ class VariableView(override val variableName: String, private val variable: Vari val evaluated = AtomicBoolean() value.fullString - .done { + .onSuccess { if (!callback.isObsolete && evaluated.compareAndSet(false, true)) { callback.evaluated(value.valueString!!) } } - .rejected { callback.errorOccurred(it.message!!) } + .onError { callback.errorOccurred(it.message!!) } } } @@ -425,8 +425,8 @@ class VariableView(override val variableName: String, private val variable: Vari } else { context.evaluateContext.evaluate("a.length", Collections.singletonMap("a", value), false) - .done(node) { node.setPresentation(icon, null, "Array[${it.value.valueString}]", true) } - .rejected(node) { + .onSuccess(node) { node.setPresentation(icon, null, "Array[${it.value.valueString}]", true) } + .onError(node) { logger().error("Failed to evaluate array length: $it") node.setPresentation(icon, null, valueString ?: "Array", true) } diff --git a/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/RejectErrorReporter.kt b/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/RejectErrorReporter.kt index ff25b4586336..3d6ccc1e4eb3 100644 --- a/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/RejectErrorReporter.kt +++ b/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/RejectErrorReporter.kt @@ -1,27 +1,13 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.debugger -import com.intellij.util.Consumer import com.intellij.xdebugger.XDebugSession import org.jetbrains.concurrency.errorIfNotMessage import org.jetbrains.rpc.LOG +import java.util.function.Consumer class RejectErrorReporter @JvmOverloads constructor(private val session: XDebugSession, private val description: String? = null) : Consumer { - override fun consume(error: Throwable) { + override fun accept(error: Throwable) { if (LOG.errorIfNotMessage(error)) { session.reportError("${if (description == null) "" else "$description: "}${error.message}") }