From 0169adef02a74558f5d91b8557a2376a17fe06ee Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Wed, 18 Apr 2018 12:46:21 +0200 Subject: [PATCH] deprecate processed (use onProcessed) and rejected (use onError) --- .../jetbrains/builtInWebServer/NetService.kt | 2 +- .../org/jetbrains/ide/OpenFileHttpService.kt | 2 +- .../jetbrains/ide/BinaryRequestHandlerTest.kt | 4 +- .../src/ExportSettingsAction.kt | 8 ++- .../org/jetbrains/concurrency/Promise.java | 5 +- .../diff/impl/dir/DirDiffTableModel.java | 6 +-- .../execution/impl/ExecutionManagerKtImpl.kt | 2 +- .../impl/AsyncProjectViewSupport.java | 50 +++++++++---------- .../ide/scopeView/ScopeViewTreeModel.java | 28 +++-------- .../StructureViewComponent.java | 4 +- .../intellij/ide/util/FileStructurePopup.java | 12 ++--- .../intellij/ide/util/treeView/TreeState.java | 6 +-- .../com/intellij/util/ui/tree/TreeUtil.java | 10 ++-- .../com/intellij/ui/tree/AsyncTreeModel.java | 2 +- .../concurrency/AsyncValueLoader.java | 2 +- .../intellij/ui/tree/AsyncTreeModelTest.java | 4 +- .../util/concurrency/AsyncPromiseTest2.kt | 2 +- .../src/org/jetbrains/concurrency/promise.kt | 12 ++--- .../src/debugger/BreakpointManagerBase.kt | 18 +------ .../src/debugger/StandaloneVmHelper.kt | 18 +------ .../src/FunctionScopesValueGroup.kt | 2 +- .../debugger-ui/src/LineBreakpointManager.kt | 18 +------ .../debugger-ui/src/ProcessHandlerWrapper.kt | 4 +- .../debugger-ui/src/RemoteVmConnection.kt | 2 +- .../debugger-ui/src/VariableView.kt | 2 +- 25 files changed, 85 insertions(+), 140 deletions(-) diff --git a/platform/built-in-server/src/org/jetbrains/builtInWebServer/NetService.kt b/platform/built-in-server/src/org/jetbrains/builtInWebServer/NetService.kt index 1ff6ddd3f756..f2f823d5d0fc 100644 --- a/platform/built-in-server/src/org/jetbrains/builtInWebServer/NetService.kt +++ b/platform/built-in-server/src/org/jetbrains/builtInWebServer/NetService.kt @@ -40,7 +40,7 @@ abstract class NetService @JvmOverloads protected constructor(protected val proj return promise } - promise.rejected { + promise.onError { processHandler.destroyProcess() LOG.errorIfNotMessage(it) } 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 f486622c481f..14b92be3c6ae 100644 --- a/platform/built-in-server/src/org/jetbrains/ide/OpenFileHttpService.kt +++ b/platform/built-in-server/src/org/jetbrains/ide/OpenFileHttpService.kt @@ -105,7 +105,7 @@ internal class OpenFileHttpService : RestService() { val promise = openFile(apiRequest, context, request) ?: return null promise.onSuccess { sendStatus(HttpResponseStatus.OK, keepAlive, channel) } - .rejected { + .onError { if (it === NOT_FOUND) { // don't expose file status sendStatus(HttpResponseStatus.NOT_FOUND.orInSafeMode(HttpResponseStatus.OK), keepAlive, channel) diff --git a/platform/built-in-server/testSrc/org/jetbrains/ide/BinaryRequestHandlerTest.kt b/platform/built-in-server/testSrc/org/jetbrains/ide/BinaryRequestHandlerTest.kt index 78e57d2c27a4..e4931db3d91e 100644 --- a/platform/built-in-server/testSrc/org/jetbrains/ide/BinaryRequestHandlerTest.kt +++ b/platform/built-in-server/testSrc/org/jetbrains/ide/BinaryRequestHandlerTest.kt @@ -59,12 +59,12 @@ internal class BinaryRequestHandlerTest { channel.writeAndFlush(message).await(5, TimeUnit.SECONDS) try { - result.rejected { error -> TestCase.fail(error.message) } + result.onError { error -> TestCase.fail(error.message) } if (result.state == Promise.State.PENDING) { val semaphore = Semaphore() semaphore.down() - result.processed { semaphore.up() } + result.onProcessed { semaphore.up() } if (!semaphore.waitForUnsafe(5000)) { TestCase.fail("Time limit exceeded") return diff --git a/platform/configuration-store-impl/src/ExportSettingsAction.kt b/platform/configuration-store-impl/src/ExportSettingsAction.kt index abed2eaf4448..944fdd342bd7 100644 --- a/platform/configuration-store-impl/src/ExportSettingsAction.kt +++ b/platform/configuration-store-impl/src/ExportSettingsAction.kt @@ -41,12 +41,11 @@ import java.util.zip.ZipOutputStream // for Rider purpose open class ExportSettingsAction : AnAction(), DumbAware { - protected open fun getExportableComponents() = getExportableComponentsMap(true, true) protected open fun exportSettings(saveFile: Path, markedComponents: Set) { - val exportFiles = markedComponents.mapTo(THashSet()) { it.file } - exportSettings(exportFiles, saveFile.outputStream(), FileUtilRt.toSystemIndependentName(PathManager.getConfigPath())) + val exportFiles = markedComponents.mapTo(THashSet()) { it.file } + exportSettings(exportFiles, saveFile.outputStream(), FileUtilRt.toSystemIndependentName(PathManager.getConfigPath())) } override fun actionPerformed(e: AnActionEvent) { @@ -82,7 +81,6 @@ open class ExportSettingsAction : AnAction(), DumbAware { } } -// not internal only to test fun exportSettings(exportFiles: Set, out: OutputStream, configPath: String) { ZipOutputStream(out).use { val writtenItemRelativePaths = THashSet() @@ -243,7 +241,7 @@ private fun getComponentPresentableName(state: State, aClass: Class<*>, pluginDe if (pluginDescriptor.vendor == "JetBrains") { resourceBundleName = OptionsBundle.PATH_TO_BUNDLE } - else { + else { return trimDefaultName() } } diff --git a/platform/core-api/src/org/jetbrains/concurrency/Promise.java b/platform/core-api/src/org/jetbrains/concurrency/Promise.java index f67c958e1e28..c66bb576081f 100644 --- a/platform/core-api/src/org/jetbrains/concurrency/Promise.java +++ b/platform/core-api/src/org/jetbrains/concurrency/Promise.java @@ -84,6 +84,7 @@ public interface Promise { * Execute passed handler on promise resolve. * @deprecated Use {@link #onSuccess(java.util.function.Consumer)} */ + @Deprecated @NotNull default Promise done(@NotNull Consumer done) { return onSuccess(it -> done.consume(it)); @@ -96,8 +97,9 @@ public interface Promise { Promise onError(@NotNull java.util.function.Consumer rejected); /** - * Execute passed handler on promise reject. + * @deprecated Use {@link #onError(java.util.function.Consumer)} */ + @Deprecated @NotNull default Promise rejected(@NotNull Consumer rejected) { return onError(it -> rejected.consume(it)); @@ -119,6 +121,7 @@ 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). */ + @Deprecated default Promise processed(@NotNull Consumer action) { return onProcessed(it -> action.consume(it)); } diff --git a/platform/diff-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java b/platform/diff-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java index ae0d17cb54b0..0197f8a36b68 100644 --- a/platform/diff-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java +++ b/platform/diff-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java @@ -607,7 +607,7 @@ public class DirDiffTableModel extends AbstractTableModel implements DirDiffMode if (source instanceof AsyncDiffElement) { ((AsyncDiffElement)source).copyToAsync(myTarget, element.getTarget(), path) - .rejected(error -> reportException(error == null ? null : error.getMessage())) + .onError(error -> reportException(error == null ? null : error.getMessage())) .onSuccess(newElement -> { ApplicationManager.getApplication().assertIsDispatchThread(); if (myDisposed) return; @@ -652,7 +652,7 @@ public class DirDiffTableModel extends AbstractTableModel implements DirDiffMode if (target instanceof AsyncDiffElement) { ((AsyncDiffElement)target).copyToAsync(mySource, element.getSource(), path) - .rejected(error -> reportException(error == null ? null : error.getMessage())) + .onError(error -> reportException(error == null ? null : error.getMessage())) .onSuccess(newElement -> { if (myDisposed) return; ApplicationManager.getApplication().assertIsDispatchThread(); @@ -715,7 +715,7 @@ public class DirDiffTableModel extends AbstractTableModel implements DirDiffMode LOG.assertTrue(source == null || target == null); if (source instanceof AsyncDiffElement || target instanceof AsyncDiffElement) { ((AsyncDiffElement)(source != null ? source : target)).deleteAsync() - .rejected(error -> reportException(error != null ? error.getMessage() : null)) + .onError(error -> reportException(error != null ? error.getMessage() : null)) .onSuccess(result -> { if (!myDisposed && myElements.indexOf(element) != -1) { removeElement(element, true); diff --git a/platform/lang-impl/src/com/intellij/execution/impl/ExecutionManagerKtImpl.kt b/platform/lang-impl/src/com/intellij/execution/impl/ExecutionManagerKtImpl.kt index 7961f59a8d2d..0a761d42f589 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/ExecutionManagerKtImpl.kt +++ b/platform/lang-impl/src/com/intellij/execution/impl/ExecutionManagerKtImpl.kt @@ -100,7 +100,7 @@ class ExecutionManagerKtImpl(project: Project) : ExecutionManagerImpl(project) { environment.contentToReuse = descriptor } } - .rejected(::handleError) + .onError(::handleError) } catch (e: Throwable) { handleError(e) 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 bbd1b6b2ed2d..a0e69d30b7c6 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 @@ -24,18 +24,13 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.problems.WolfTheProblemSolver; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiManager; -import com.intellij.ui.tree.AsyncTreeModel; -import com.intellij.ui.tree.RestoreSelectionListener; -import com.intellij.ui.tree.StructureTreeModel; -import com.intellij.ui.tree.TreeCollector; -import com.intellij.ui.tree.TreeVisitor; -import com.intellij.ui.tree.ProjectFileChangeListener; +import com.intellij.ui.tree.*; import com.intellij.util.SmartList; import com.intellij.util.messages.MessageBusConnection; import com.intellij.util.ui.tree.TreeUtil; import org.jetbrains.annotations.NotNull; -import javax.swing.JTree; +import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; import java.util.Collections; @@ -48,7 +43,6 @@ import static com.intellij.openapi.vfs.VirtualFileManager.VFS_CHANGES; class AsyncProjectViewSupport { private static final Logger LOG = Logger.getInstance(AsyncProjectViewSupport.class); private final TreeCollector myFileRoots = TreeCollector.createFileRootsCollector(); - private final ProjectFileChangeListener myChangeListener; private final StructureTreeModel myStructureTreeModel; private final AsyncTreeModel myAsyncTreeModel; @@ -62,14 +56,13 @@ class AsyncProjectViewSupport { myStructureTreeModel.setComparator(comparator); myAsyncTreeModel = new AsyncTreeModel(myStructureTreeModel, true, parent); myAsyncTreeModel.setRootImmediately(myStructureTreeModel.getRootImmediately()); - myChangeListener = new ProjectFileChangeListener(project, (module, file) -> { + setModel(tree, myAsyncTreeModel); + MessageBusConnection connection = project.getMessageBus().connect(parent); + connection.subscribe(VFS_CHANGES, new ProjectFileChangeListener(project, (module, file) -> { if (myFileRoots.add(file)) { myFileRoots.processLater(myStructureTreeModel.getInvoker(), roots -> roots.forEach(root -> updateByFile(root, true))); } - }); - setModel(tree, myAsyncTreeModel); - MessageBusConnection connection = project.getMessageBus().connect(parent); - connection.subscribe(VFS_CHANGES, myChangeListener); + })); connection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() { @Override public void rootsChanged(ModuleRootEvent event) { @@ -158,19 +151,26 @@ class AsyncProjectViewSupport { LOG.debug("select object: ", object, " in file: ", file); TreeVisitor visitor = AbstractProjectViewPane.createVisitor(element, file); if (visitor != null) { - expand(tree, promise -> myAsyncTreeModel.accept(visitor).processed(path -> { - if (selectPath(tree, path) || element == null || file == null || Registry.is("async.project.view.support.extra.select.disabled")) { - promise.setResult(null); - } - else { - // try to search the specified file instead of element, - // because Kotlin files cannot represent containing functions - myAsyncTreeModel.accept(AbstractProjectViewPane.createVisitor(file)).processed(path2 -> { - selectPath(tree, path2); - promise.setResult(null); + //noinspection CodeBlock2Expr + expand(tree, promise -> { + myAsyncTreeModel + .accept(visitor) + .onProcessed(path -> { + if (selectPath(tree, path) || element == null || file == null || Registry.is("async.project.view.support.extra.select.disabled")) { + promise.setResult(null); + } + else { + // try to search the specified file instead of element, + // because Kotlin files cannot represent containing functions + myAsyncTreeModel + .accept(AbstractProjectViewPane.createVisitor(file)) + .onProcessed(path2 -> { + selectPath(tree, path2); + promise.setResult(null); + }); + } }); - } - })); + }); } } diff --git a/platform/lang-impl/src/com/intellij/ide/scopeView/ScopeViewTreeModel.java b/platform/lang-impl/src/com/intellij/ide/scopeView/ScopeViewTreeModel.java index fd25f628113e..48d858b5ffb6 100644 --- a/platform/lang-impl/src/com/intellij/ide/scopeView/ScopeViewTreeModel.java +++ b/platform/lang-impl/src/com/intellij/ide/scopeView/ScopeViewTreeModel.java @@ -2,11 +2,7 @@ package com.intellij.ide.scopeView; import com.intellij.icons.AllIcons; -import com.intellij.ide.projectView.PresentationData; -import com.intellij.ide.projectView.ProjectViewNode; -import com.intellij.ide.projectView.ProjectViewNodeDecorator; -import com.intellij.ide.projectView.TreeStructureProvider; -import com.intellij.ide.projectView.ViewSettings; +import com.intellij.ide.projectView.*; import com.intellij.ide.projectView.impl.nodes.PsiFileNode; import com.intellij.ide.util.treeView.AbstractTreeNode; import com.intellij.ide.util.treeView.NodeDescriptor; @@ -44,12 +40,7 @@ import com.intellij.psi.search.scope.ProblemsScope; import com.intellij.psi.search.scope.ProjectFilesScope; import com.intellij.ui.SimpleTextAttributes; import com.intellij.ui.stripe.ErrorStripe; -import com.intellij.ui.tree.AbstractTreeWalker; -import com.intellij.ui.tree.BaseTreeModel; -import com.intellij.ui.tree.ProjectFileNode; -import com.intellij.ui.tree.ProjectFileTreeModel; -import com.intellij.ui.tree.TreePathUtil; -import com.intellij.ui.tree.TreeVisitor; +import com.intellij.ui.tree.*; import com.intellij.util.Consumer; import com.intellij.util.SmartList; import com.intellij.util.concurrency.Invoker; @@ -58,14 +49,11 @@ import com.intellij.util.ui.tree.TreeModelAdapter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import javax.swing.Icon; +import javax.swing.*; import javax.swing.event.TreeModelEvent; import javax.swing.tree.TreePath; -import java.awt.Color; -import java.util.ArrayDeque; -import java.util.Collection; -import java.util.Comparator; -import java.util.HashMap; +import java.awt.*; +import java.util.*; import java.util.List; import java.util.function.BiFunction; import java.util.stream.Collectors; @@ -73,9 +61,7 @@ import java.util.stream.Collectors; import static com.intellij.ide.projectView.impl.ProjectRootsUtil.findSourceFolder; import static com.intellij.openapi.roots.ui.configuration.SourceRootPresentation.getSourceRootIcon; import static com.intellij.openapi.util.io.FileUtil.getLocationRelativeToUserHome; -import static com.intellij.openapi.vfs.VfsUtilCore.getRelativePath; -import static com.intellij.openapi.vfs.VfsUtilCore.isAncestor; -import static com.intellij.openapi.vfs.VfsUtilCore.VFS_SEPARATOR_CHAR; +import static com.intellij.openapi.vfs.VfsUtilCore.*; import static java.util.Collections.emptyList; public final class ScopeViewTreeModel extends BaseTreeModel implements InvokerSupplier { @@ -282,7 +268,7 @@ public final class ScopeViewTreeModel extends BaseTreeModel im } }; walker.start(root); - walker.promise().processed(path -> consumer.consume(path == null ? null : path.getLastPathComponent())); + walker.promise().onProcessed(path -> consumer.consume(path == null ? null : path.getLastPathComponent())); } }); } diff --git a/platform/lang-impl/src/com/intellij/ide/structureView/newStructureView/StructureViewComponent.java b/platform/lang-impl/src/com/intellij/ide/structureView/newStructureView/StructureViewComponent.java index 322ad2ab1e03..e2272a460227 100644 --- a/platform/lang-impl/src/com/intellij/ide/structureView/newStructureView/StructureViewComponent.java +++ b/platform/lang-impl/src/com/intellij/ide/structureView/newStructureView/StructureViewComponent.java @@ -509,7 +509,7 @@ public class StructureViewComponent extends SimpleToolWindowPanel implements Tre else { AtomicBoolean complete = new AtomicBoolean(false); //noinspection TestOnlyProblems - Promise promise = rebuildAndUpdate().processed(ignore -> complete.set(true)); + Promise promise = rebuildAndUpdate().onProcessed(ignore -> complete.set(true)); while (!complete.get()) { //noinspection TestOnlyProblems UIUtil.dispatchAllInvocationEvents(); @@ -674,7 +674,7 @@ public class StructureViewComponent extends SimpleToolWindowPanel implements Tre if (node != null) node.update(); return TreeVisitor.Action.CONTINUE; }; - myAsyncTreeModel.accept(visitor).processed(ignore -> result.setResult(null)); + myAsyncTreeModel.accept(visitor).onProcessed(ignore -> result.setResult(null)); return result; } diff --git a/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java b/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java index f3a27fbaa5c5..a28aa2f1da52 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java +++ b/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java @@ -316,7 +316,7 @@ public class FileStructurePopup implements Disposable, TreeActionsOwner { window.addWindowFocusListener(windowFocusListener); Disposer.register(myPopup, () -> window.removeWindowFocusListener(windowFocusListener)); - rebuildAndSelect(false, myInitialElement).processed(path -> UIUtil.invokeLaterIfNeeded(() -> { + rebuildAndSelect(false, myInitialElement).onProcessed(path -> UIUtil.invokeLaterIfNeeded(() -> { TreeUtil.ensureSelection(myTree); myTreeHasBuilt.setDone(); installUpdater(); @@ -341,7 +341,7 @@ public class FileStructurePopup implements Disposable, TreeActionsOwner { if (!filter.equals(prefix)) { boolean isBackspace = prefix.length() < filter.length(); filter = prefix; - rebuild(true).processed(ignore -> UIUtil.invokeLaterIfNeeded(() -> { + rebuild(true).onProcessed(ignore -> UIUtil.invokeLaterIfNeeded(() -> { if (isDisposed()) return; TreeUtil.promiseExpandAll(myTree); if (isBackspace && handleBackspace(filter)) { @@ -453,7 +453,7 @@ public class FileStructurePopup implements Disposable, TreeActionsOwner { if (node != null) node.update(); return TreeVisitor.Action.CONTINUE; }; - rebuild(false).processed(ignore1 -> myAsyncTreeModel.accept(visitor).processed(ignore2 -> result.setResult(null))); + rebuild(false).onProcessed(ignore1 -> myAsyncTreeModel.accept(visitor).onProcessed(ignore2 -> result.setResult(null))); return result; } @@ -735,7 +735,7 @@ public class FileStructurePopup implements Disposable, TreeActionsOwner { boolean actionState = TreeModelWrapper.shouldRevert(myAction) ? !state : state; myTreeActionsOwner.setActionIncluded(myAction, actionState); saveState(myAction, state); - rebuild(false).processed(ignore -> { + rebuild(false).onProcessed(ignore -> { if (mySpeedSearch.isPopupActive()) { mySpeedSearch.refreshSelection(); } @@ -807,7 +807,7 @@ public class FileStructurePopup implements Disposable, TreeActionsOwner { saveState(action, state); } myTreeActionsOwner.setActionIncluded(action, isRevertedStructureFilter != state); - rebuild(false).processed(ignore -> { + rebuild(false).onProcessed(ignore -> { if (mySpeedSearch.isPopupActive()) { mySpeedSearch.refreshSelection(); } @@ -843,7 +843,7 @@ public class FileStructurePopup implements Disposable, TreeActionsOwner { myStructureTreeModel.invalidate( () -> (selection == null ? myAsyncTreeModel.accept(o -> TreeVisitor.Action.CONTINUE) : select(selection)) - .rejected(ignore2 -> result.setError("rejected")) + .onError(ignore2 -> result.setError("rejected")) .onSuccess(p -> UIUtil.invokeLaterIfNeeded( () -> { TreeUtil.expand(getTree(), myTreeModel instanceof StructureViewCompositeModel ? 3 : 2); diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/TreeState.java b/platform/platform-api/src/com/intellij/ide/util/treeView/TreeState.java index 433ca025d426..71c913c10d5e 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/TreeState.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/TreeState.java @@ -445,7 +445,7 @@ public class TreeState implements JDOMExternalizable { Promise expanding = UIUtil.getClientProperty(tree, EXPANDING); LOG.debug("EXPANDING: ", expanding); if (expanding == null) expanding = Promises.resolvedPromise(); - expanding.processed(value -> { + expanding.onProcessed(value -> { AsyncPromise promise = new AsyncPromise<>(); UIUtil.putClientProperty(tree, EXPANDING, promise); consumer.accept(promise); @@ -470,9 +470,9 @@ public class TreeState implements JDOMExternalizable { TreeModel model = tree.getModel(); if (!(model instanceof TreeVisitor.Acceptor)) return false; - expand(tree, promise -> expand(tree).processed(expanded -> { + expand(tree, promise -> expand(tree).onProcessed(expanded -> { if (isSelectionNeeded(expanded, tree, promise)) { - select(tree).processed(selected -> { + select(tree).onProcessed(selected -> { if (isSelectionNeeded(selected, tree, promise)) { for (TreePath path : selected) { tree.addSelectionPath(path); diff --git a/platform/platform-api/src/com/intellij/util/ui/tree/TreeUtil.java b/platform/platform-api/src/com/intellij/util/ui/tree/TreeUtil.java index e96d284595d4..761f7f045ccb 100644 --- a/platform/platform-api/src/com/intellij/util/ui/tree/TreeUtil.java +++ b/platform/platform-api/src/com/intellij/util/ui/tree/TreeUtil.java @@ -806,7 +806,7 @@ public final class TreeUtil { * @param onDone a task to run after expanding nodes */ public static void expandAll(@NotNull JTree tree, @NotNull Runnable onDone) { - promiseExpandAll(tree).processed(path -> onDone.run()); + promiseExpandAll(tree).onProcessed(path -> onDone.run()); } /** @@ -836,7 +836,7 @@ public final class TreeUtil { * @param onDone a task to run after expanding nodes */ public static void expand(@NotNull JTree tree, int depth, @NotNull Runnable onDone) { - promiseExpand(tree, depth).processed(path -> onDone.run()); + promiseExpand(tree, depth).onProcessed(path -> onDone.run()); } /** @@ -1104,7 +1104,7 @@ public final class TreeUtil { * @param consumer a path consumer called on done */ public static void expand(@NotNull JTree tree, @NotNull TreeVisitor visitor, @NotNull Consumer consumer) { - promiseExpand(tree, visitor).processed(path -> consumer.accept(path)); + promiseExpand(tree, visitor).onProcessed(path -> consumer.accept(path)); } /** @@ -1128,7 +1128,7 @@ public final class TreeUtil { * @param consumer a path consumer called on done */ public static void makeVisible(@NotNull JTree tree, @NotNull TreeVisitor visitor, @NotNull Consumer consumer) { - promiseMakeVisible(tree, visitor).processed(path -> consumer.accept(path)); + promiseMakeVisible(tree, visitor).onProcessed(path -> consumer.accept(path)); } /** @@ -1158,7 +1158,7 @@ public final class TreeUtil { * @param consumer a path consumer called on done */ public static void visit(@NotNull JTree tree, @NotNull TreeVisitor visitor, @NotNull Consumer consumer) { - promiseVisit(tree, visitor).processed(path -> consumer.accept(path)); + promiseVisit(tree, visitor).onProcessed(path -> consumer.accept(path)); } /** 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 d83b4f0aff6b..f0ee226b8722 100644 --- a/platform/platform-impl/src/com/intellij/ui/tree/AsyncTreeModel.java +++ b/platform/platform-impl/src/com/intellij/ui/tree/AsyncTreeModel.java @@ -256,7 +256,7 @@ public final class AsyncTreeModel extends AbstractTreeModel implements Identifia }; if (allowLoading) { // start visiting on the background thread to ensure that root node is already invalidated - processor.background.invokeLater(() -> onValidThread(() -> promiseRootEntry().onSuccess(walker::start).rejected(walker::setError))); + processor.background.invokeLater(() -> onValidThread(() -> promiseRootEntry().onSuccess(walker::start).onError(walker::setError))); } else { onValidThread(() -> walker.start(tree.root)); diff --git a/platform/platform-impl/src/org/jetbrains/concurrency/AsyncValueLoader.java b/platform/platform-impl/src/org/jetbrains/concurrency/AsyncValueLoader.java index f6901efb59ee..7ee64bb2315d 100644 --- a/platform/platform-impl/src/org/jetbrains/concurrency/AsyncValueLoader.java +++ b/platform/platform-impl/src/org/jetbrains/concurrency/AsyncValueLoader.java @@ -137,7 +137,7 @@ public abstract class AsyncValueLoader { effectivePromise.onSuccess(doneHandler); if (isCancelOnReject()) { - effectivePromise.rejected(throwable -> ref.compareAndSet(effectivePromise, null)); + effectivePromise.onError(throwable -> ref.compareAndSet(effectivePromise, null)); } if (effectivePromise != promise) { diff --git a/platform/platform-tests/testSrc/com/intellij/ui/tree/AsyncTreeModelTest.java b/platform/platform-tests/testSrc/com/intellij/ui/tree/AsyncTreeModelTest.java index df5a431add7f..016e4612d8cf 100644 --- a/platform/platform-tests/testSrc/com/intellij/ui/tree/AsyncTreeModelTest.java +++ b/platform/platform-tests/testSrc/com/intellij/ui/tree/AsyncTreeModelTest.java @@ -478,12 +478,12 @@ public final class AsyncTreeModelTest { private void resolve(@NotNull TreePath path, @NotNull Consumer consumer) { AsyncTreeModel model = (AsyncTreeModel)tree.getModel(); - model.resolve(path).rejected(promise::setError).onSuccess(consumer); + model.resolve(path).onError(promise::setError).onSuccess(consumer); } private void visit(@NotNull TreeVisitor visitor, boolean allowLoading, @NotNull Consumer consumer) { AsyncTreeModel model = (AsyncTreeModel)tree.getModel(); - model.accept(visitor, allowLoading).rejected(promise::setError).onSuccess(consumer); + model.accept(visitor, allowLoading).onError(promise::setError).onSuccess(consumer); } @Override diff --git a/platform/platform-tests/testSrc/com/intellij/util/concurrency/AsyncPromiseTest2.kt b/platform/platform-tests/testSrc/com/intellij/util/concurrency/AsyncPromiseTest2.kt index a6efff1ad181..d91715521c14 100644 --- a/platform/platform-tests/testSrc/com/intellij/util/concurrency/AsyncPromiseTest2.kt +++ b/platform/platform-tests/testSrc/com/intellij/util/concurrency/AsyncPromiseTest2.kt @@ -43,7 +43,7 @@ private fun promise(state: AsyncPromiseTest2.State, `when`: When): AsyncPromise< } AsyncPromiseTest2.State.ERROR -> { log("notify promise about error to preserve a cause") - promise.rejected { /* add empty error handler to ensure that promise will not call LOG.error */ } + promise.onError { /* add empty error handler to ensure that promise will not call LOG.error */ } promise.setError(CheckedException()) } } diff --git a/platform/projectModel-api/src/org/jetbrains/concurrency/promise.kt b/platform/projectModel-api/src/org/jetbrains/concurrency/promise.kt index b86c45ab5062..774bd8211fac 100644 --- a/platform/projectModel-api/src/org/jetbrains/concurrency/promise.kt +++ b/platform/projectModel-api/src/org/jetbrains/concurrency/promise.kt @@ -6,13 +6,13 @@ import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.progress.ProcessCanceledException import com.intellij.openapi.util.ActionCallback -import com.intellij.util.Consumer import com.intellij.util.Function import com.intellij.util.SmartList import com.intellij.util.ThreeState import com.intellij.util.concurrency.AppExecutorUtil import org.jetbrains.concurrency.InternalPromiseUtil.MessageError import java.util.* +import java.util.function.Consumer val Promise<*>.isRejected: Boolean get() = state == Promise.State.REJECTED @@ -62,7 +62,7 @@ abstract class ValueNodeAsyncFunction(private val node: Obsolesce override fun isObsolete() = node.isObsolete } -abstract class ObsolescentConsumer(private val obsolescent: Obsolescent) : Obsolescent, java.util.function.Consumer { +abstract class ObsolescentConsumer(private val obsolescent: Obsolescent) : Obsolescent, Consumer { override fun isObsolete() = obsolescent.isObsolete } @@ -213,12 +213,12 @@ fun all(promises: Collection>, totalResult: T, ignoreErrors for (promise in promises) { promise.onSuccess(done) - promise.rejected(rejected) + promise.onError(rejected) } return totalPromise } -private class CountDownConsumer(@Volatile private var countDown: Int, private val promise: AsyncPromise, private val totalResult: T) : java.util.function.Consumer { +private class CountDownConsumer(@Volatile private var countDown: Int, private val promise: AsyncPromise, private val totalResult: T) : Consumer { override fun accept(t: Any?) { if (--countDown == 0) { promise.setResult(totalResult) @@ -235,8 +235,8 @@ fun any(promises: Collection>, totalError: String): Promise { } val totalPromise = AsyncPromise() - val done = java.util.function.Consumer { result -> totalPromise.setResult(result) } - val rejected = object : java.util.function.Consumer { + val done = Consumer { result -> totalPromise.setResult(result) } + val rejected = object : Consumer { @Volatile private var toConsume = promises.size override fun accept(throwable: Throwable) { diff --git a/platform/script-debugger/backend/src/debugger/BreakpointManagerBase.kt b/platform/script-debugger/backend/src/debugger/BreakpointManagerBase.kt index 9403446faa55..4f2bb6d9e130 100644 --- a/platform/script-debugger/backend/src/debugger/BreakpointManagerBase.kt +++ b/platform/script-debugger/backend/src/debugger/BreakpointManagerBase.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.concurrency.ConcurrentCollectionFactory @@ -70,7 +56,7 @@ abstract class BreakpointManagerBase> : BreakpointManager breakpoints.add(breakpoint) val promise = doSetBreakpoint(target, url, breakpoint) - .rejected { dispatcher.multicaster.errorOccurred(breakpoint, it.message ?: it.toString()) } + .onError { dispatcher.multicaster.errorOccurred(breakpoint, it.message ?: it.toString()) } return BreakpointManager.BreakpointCreated(breakpoint, promise) } diff --git a/platform/script-debugger/backend/src/debugger/StandaloneVmHelper.kt b/platform/script-debugger/backend/src/debugger/StandaloneVmHelper.kt index a84c00734c67..d7c5df3bb94a 100644 --- a/platform/script-debugger/backend/src/debugger/StandaloneVmHelper.kt +++ b/platform/script-debugger/backend/src/debugger/StandaloneVmHelper.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.util.io.addChannelListener @@ -59,7 +45,7 @@ open class StandaloneVmHelper(private val vm: Vm, private val messageProcessor: } else { messageProcessor.send(disconnectRequest) - .rejected { + .onError { if (it.message != CONNECTION_CLOSED_MESSAGE) { LOG.errorIfNotMessage(it) } diff --git a/platform/script-debugger/debugger-ui/src/FunctionScopesValueGroup.kt b/platform/script-debugger/debugger-ui/src/FunctionScopesValueGroup.kt index 164a1c4ee058..280166379868 100644 --- a/platform/script-debugger/debugger-ui/src/FunctionScopesValueGroup.kt +++ b/platform/script-debugger/debugger-ui/src/FunctionScopesValueGroup.kt @@ -24,7 +24,7 @@ internal class FunctionScopesValueGroup(private val functionValue: FunctionValue createAndAddScopeList(node, Arrays.asList(*scopes), variableContext, null) } } - .rejected { + .onError { LOG.errorIfNotMessage(it) node.setErrorMessage(it.message!!) } diff --git a/platform/script-debugger/debugger-ui/src/LineBreakpointManager.kt b/platform/script-debugger/debugger-ui/src/LineBreakpointManager.kt index 04ae099c29ef..f097cecdbb5a 100644 --- a/platform/script-debugger/debugger-ui/src/LineBreakpointManager.kt +++ b/platform/script-debugger/debugger-ui/src/LineBreakpointManager.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 @@ -56,7 +42,7 @@ abstract class LineBreakpointManager(internal val debugProcess: DebugProcessImpl if (!vmBreakpoint.enabled) { vmBreakpoint.enabled = true breakpointManager.flush(vmBreakpoint) - .rejected { debugProcess.session.updateBreakpointPresentation(breakpoint, AllIcons.Debugger.Db_invalid_breakpoint, it.message) } + .onError { debugProcess.session.updateBreakpointPresentation(breakpoint, AllIcons.Debugger.Db_invalid_breakpoint, it.message) } } } } diff --git a/platform/script-debugger/debugger-ui/src/ProcessHandlerWrapper.kt b/platform/script-debugger/debugger-ui/src/ProcessHandlerWrapper.kt index dc846e9bec56..00fd494c0c1e 100644 --- a/platform/script-debugger/debugger-ui/src/ProcessHandlerWrapper.kt +++ b/platform/script-debugger/debugger-ui/src/ProcessHandlerWrapper.kt @@ -50,8 +50,8 @@ class ProcessHandlerWrapper(private val debugProcess: XDebugProcess, private val } debugProcess.stopAsync() - .done { stopProcess(destroy) } - .rejected { + .onSuccess() { stopProcess(destroy) } + .onError { try { LOG.error(it) } diff --git a/platform/script-debugger/debugger-ui/src/RemoteVmConnection.kt b/platform/script-debugger/debugger-ui/src/RemoteVmConnection.kt index 6055d85b556d..08180c52e767 100644 --- a/platform/script-debugger/debugger-ui/src/RemoteVmConnection.kt +++ b/platform/script-debugger/debugger-ui/src/RemoteVmConnection.kt @@ -46,7 +46,7 @@ abstract class RemoteVmConnection : VmConnection() { .onSuccess { connectionSucceeded(it, address) } - .rejected { + .onError { if (it !is ConnectException) { LOG.errorIfNotMessage(it) } diff --git a/platform/script-debugger/debugger-ui/src/VariableView.kt b/platform/script-debugger/debugger-ui/src/VariableView.kt index e71100eb6970..76610fa1375b 100644 --- a/platform/script-debugger/debugger-ui/src/VariableView.kt +++ b/platform/script-debugger/debugger-ui/src/VariableView.kt @@ -306,7 +306,7 @@ class VariableView(override val variableName: String, private val variable: Vari value = null callback.valueModified() } - .rejected { callback.errorOccurred(it.message!!) } + .onError { callback.errorOccurred(it.message!!) } } } }