IDEA-CR-30725 reduce rejectPromise() without explicit error

This commit is contained in:
Vladimir Krivosheev
2018-03-19 16:19:00 +01:00
parent f5002ec244
commit 45649108c1
7 changed files with 35 additions and 54 deletions
@@ -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);
@@ -132,6 +132,7 @@ public interface Promise<T> {
@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);
}
@@ -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();
@@ -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
@@ -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
@@ -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<Integer> myOffset = new AtomicNotNullLazyValue<Integer>() {
@NotNull
@@ -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<XLineBreakpoint> 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<XLineBreakpoint> 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<XLineBreakpoint> 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;
}
}