diff --git a/platform/core-api/src/org/jetbrains/concurrency/InternalPromiseUtil.java b/platform/core-api/src/org/jetbrains/concurrency/InternalPromiseUtil.java index 3693942fc7cf..3f9e5e2a81ad 100644 --- a/platform/core-api/src/org/jetbrains/concurrency/InternalPromiseUtil.java +++ b/platform/core-api/src/org/jetbrains/concurrency/InternalPromiseUtil.java @@ -90,6 +90,10 @@ public class InternalPromiseUtil { return result; } + if (error == OBSOLETE_ERROR) { + return null; + } + ExceptionUtil.rethrowUnchecked(error); if (error instanceof ExecutionException) { throw ((ExecutionException)error); diff --git a/platform/core-api/src/org/jetbrains/concurrency/Promise.java b/platform/core-api/src/org/jetbrains/concurrency/Promise.java index a8d45c2908fc..f67c958e1e28 100644 --- a/platform/core-api/src/org/jetbrains/concurrency/Promise.java +++ b/platform/core-api/src/org/jetbrains/concurrency/Promise.java @@ -132,6 +132,7 @@ public interface Promise { @Nullable T blockingGet(int timeout, @NotNull TimeUnit timeUnit) throws TimeoutException, ExecutionException; + @Nullable default T blockingGet(int timeout) throws TimeoutException, ExecutionException { return blockingGet(timeout, TimeUnit.MILLISECONDS); } diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/DelayCommand.java b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/DelayCommand.java index 1d555826f1c4..792642663e9b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/DelayCommand.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/DelayCommand.java @@ -21,7 +21,7 @@ public class DelayCommand extends AbstractCommand { } catch (NumberFormatException e) { dumpError(context, "Invalid delay value: " + s); - return Promises.rejectedPromise(); + return Promises.rejectedPromise(e); } return Promises.resolvedPromise(); diff --git a/platform/platform-tests/testSrc/org/jetbrains/concurrency/AsyncPromiseTest.kt b/platform/platform-tests/testSrc/org/jetbrains/concurrency/AsyncPromiseTest.kt index de1c09663ff7..b2ba1f6002a4 100644 --- a/platform/platform-tests/testSrc/org/jetbrains/concurrency/AsyncPromiseTest.kt +++ b/platform/platform-tests/testSrc/org/jetbrains/concurrency/AsyncPromiseTest.kt @@ -23,6 +23,7 @@ class AsyncPromiseTest { assertThat(promise.isCancelled).isTrue() assertThat(promise.cancel(true)).isFalse() assertThat(promise.isCancelled).isTrue() + assertThat(promise.blockingGet(1)).isNull() } @Test diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerUtilImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerUtilImpl.java index 29d2e0523eb9..f128b79b3e08 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerUtilImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerUtilImpl.java @@ -141,10 +141,7 @@ public class XDebuggerUtilImpl extends XDebuggerUtil { final int line, final boolean temporary) { XSourcePositionImpl position = XSourcePositionImpl.create(file, line); - if (position != null) { - return toggleAndReturnLineBreakpoint(project, type, position, temporary, null, true); - } - return rejectedPromise(); + return toggleAndReturnLineBreakpoint(project, type, position, temporary, null, true); } @NotNull @@ -337,8 +334,8 @@ public class XDebuggerUtilImpl extends XDebuggerUtil { @Override @Nullable - public XSourcePosition createPosition(final VirtualFile file, final int line, final int column) { - return XSourcePositionImpl.create(file, line, column); + public XSourcePosition createPosition(@Nullable VirtualFile file, final int line, final int column) { + return file == null ? null : XSourcePositionImpl.create(file, line, column); } @Override diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XSourcePositionImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XSourcePositionImpl.java index 1c64b6f137fc..e150c3efa834 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XSourcePositionImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XSourcePositionImpl.java @@ -1,6 +1,4 @@ -/* - * Copyright 2000-2017 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. - */ +// 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.xdebugger.impl; import com.intellij.openapi.application.ReadAction; @@ -131,20 +129,16 @@ public abstract class XSourcePositionImpl implements XSourcePosition { /** * do not call this method from plugins, use {@link XDebuggerUtil#createPosition(VirtualFile, int)} instead */ - @Nullable - public static XSourcePositionImpl create(@Nullable VirtualFile file, int line) { + @NotNull + public static XSourcePositionImpl create(@NotNull VirtualFile file, int line) { return create(file, line, 0); } /** * do not call this method from plugins, use {@link XDebuggerUtil#createPosition(VirtualFile, int, int)} instead */ - @Nullable - public static XSourcePositionImpl create(@Nullable VirtualFile file, final int line, final int column) { - if (file == null) { - return null; - } - + @NotNull + public static XSourcePositionImpl create(@NotNull VirtualFile file, final int line, final int column) { return new XSourcePositionImpl(file) { private final AtomicNotNullLazyValue myOffset = new AtomicNotNullLazyValue() { @NotNull diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointUtil.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointUtil.java index b07d81d0c356..dc7495c219c8 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointUtil.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointUtil.java @@ -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 com.intellij.xdebugger.impl.breakpoints; import com.intellij.codeInsight.folding.impl.FoldingUtil; @@ -124,11 +110,11 @@ public class XBreakpointUtil { */ @NotNull public static Promise toggleLineBreakpoint(@NotNull Project project, - @NotNull XSourcePosition position, - @Nullable Editor editor, - boolean temporary, - boolean moveCaret, - boolean canRemove) { + @NotNull XSourcePosition position, + @Nullable Editor editor, + boolean temporary, + boolean moveCaret, + boolean canRemove) { int lineStart = position.getLine(); VirtualFile file = position.getFile(); // for folded text check each line and find out type with the biggest priority @@ -161,23 +147,21 @@ public class XBreakpointUtil { } } - if (typeWinner != null) { - XSourcePosition winPosition = (lineStart == lineWinner) ? position : XSourcePositionImpl.create(file, lineWinner); - if (winPosition != null) { - Promise res = - XDebuggerUtilImpl.toggleAndReturnLineBreakpoint(project, typeWinner, winPosition, temporary, editor, canRemove); - - if (editor != null && lineStart != lineWinner) { - int offset = editor.getDocument().getLineStartOffset(lineWinner); - ExpandRegionAction.expandRegionAtOffset(project, editor, offset); - if (moveCaret) { - editor.getCaretModel().moveToOffset(offset); - } - } - return res; - } + if (typeWinner == null) { + return rejectedPromise(new RuntimeException("Cannot find appropriate type")); } - return rejectedPromise(); + XSourcePosition winPosition = (lineStart == lineWinner) ? position : XSourcePositionImpl.create(file, lineWinner); + Promise res = + XDebuggerUtilImpl.toggleAndReturnLineBreakpoint(project, typeWinner, winPosition, temporary, editor, canRemove); + + if (editor != null && lineStart != lineWinner) { + int offset = editor.getDocument().getLineStartOffset(lineWinner); + ExpandRegionAction.expandRegionAtOffset(project, editor, offset); + if (moveCaret) { + editor.getCaretModel().moveToOffset(offset); + } + } + return res; } }