diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/ForceEarlyReturnAction.java b/java/debugger/impl/src/com/intellij/debugger/actions/ForceEarlyReturnAction.java index a98594a00f53..e7ee10684b40 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/ForceEarlyReturnAction.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/ForceEarlyReturnAction.java @@ -13,24 +13,21 @@ import com.intellij.debugger.engine.evaluation.EvaluateException; import com.intellij.debugger.engine.events.DebuggerCommandImpl; import com.intellij.debugger.engine.events.DebuggerContextCommandImpl; import com.intellij.debugger.impl.DebuggerContextImpl; +import com.intellij.debugger.impl.DebuggerUtilsEx; import com.intellij.debugger.jdi.StackFrameProxyImpl; import com.intellij.debugger.jdi.ThreadReferenceProxyImpl; import com.intellij.idea.ActionsBundle; import com.intellij.openapi.actionSystem.ActionPlaces; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; -import com.intellij.openapi.ui.Messages; import com.intellij.util.ui.UIUtil; import com.intellij.xdebugger.XDebuggerBundle; import com.intellij.xdebugger.XExpression; -import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider; import com.intellij.xdebugger.evaluation.XDebuggerEvaluator; import com.intellij.xdebugger.frame.XValue; -import com.intellij.xdebugger.impl.breakpoints.XExpressionImpl; -import com.intellij.xdebugger.impl.ui.XDebuggerExpressionEditor; +import com.intellij.xdebugger.impl.evaluate.XExpressionDialog; import com.sun.jdi.Method; import com.sun.jdi.Value; import org.jetbrains.annotations.NotNull; @@ -66,12 +63,18 @@ public class ForceEarlyReturnAction extends DebuggerAction { return; } - if ("void".equals(method.returnTypeName())) { + if (DebuggerUtilsEx.isVoid(method)) { forceEarlyReturnWithFinally(thread.getVirtualMachine().mirrorOfVoid(), stackFrame, debugProcess, null); } else { ApplicationManager.getApplication().invokeLater( - () -> new ReturnExpressionDialog(project, debugProcess.getXdebugProcess().getEditorsProvider(), debugProcess, stackFrame).show()); + () -> new XExpressionDialog(project, debugProcess.getXdebugProcess().getEditorsProvider(), "forceReturnValue", + "Return Value", stackFrame.getSourcePosition(), null) { + @Override + protected void doOKAction() { + evaluateAndReturn(project, stackFrame, debugProcess, getExpression(), this); + } + }.show()); } } }); @@ -178,45 +181,4 @@ public class ForceEarlyReturnAction extends DebuggerAction { e.getPresentation().setVisible(enable); } } - - private static class ReturnExpressionDialog extends DialogWrapper { - private final Project myProject; - private final XDebuggerEditorsProvider myEditorsProvider; - private final DebugProcessImpl myProcess; - private final JavaStackFrame myFrame; - private final XDebuggerExpressionEditor myEditor; - - public ReturnExpressionDialog(@NotNull Project project, - XDebuggerEditorsProvider provider, - DebugProcessImpl process, - JavaStackFrame frame) { - super(project); - myProject = project; - myEditorsProvider = provider; - myProcess = process; - myFrame = frame; - myEditor = new XDebuggerExpressionEditor(myProject, myEditorsProvider, "forceReturnValue", myFrame.getSourcePosition(), - XExpressionImpl.EMPTY_EXPRESSION, false, true, false); - - setTitle("Return Value"); - init(); - } - - @Nullable - @Override - protected JComponent createCenterPanel() { - return myEditor.getComponent(); - } - - @Nullable - @Override - public JComponent getPreferredFocusedComponent() { - return myEditor.getPreferredFocusedComponent(); - } - - @Override - protected void doOKAction() { - evaluateAndReturn(myProject, myFrame, myProcess, myEditor.getExpression(), this); - } - } } diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/ThrowExceptionAction.java b/java/debugger/impl/src/com/intellij/debugger/actions/ThrowExceptionAction.java index 50692cb131f6..ed1acc074d42 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/ThrowExceptionAction.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/ThrowExceptionAction.java @@ -17,16 +17,15 @@ import com.intellij.debugger.jdi.ThreadReferenceProxyImpl; import com.intellij.idea.ActionsBundle; import com.intellij.openapi.actionSystem.ActionPlaces; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.util.ui.UIUtil; import com.intellij.xdebugger.XDebuggerBundle; import com.intellij.xdebugger.XExpression; -import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider; import com.intellij.xdebugger.evaluation.XDebuggerEvaluator; import com.intellij.xdebugger.frame.XValue; -import com.intellij.xdebugger.impl.breakpoints.XExpressionImpl; -import com.intellij.xdebugger.impl.ui.XDebuggerExpressionEditor; +import com.intellij.xdebugger.impl.evaluate.XExpressionDialog; import com.sun.jdi.ObjectReference; import com.sun.jdi.Value; import org.jetbrains.annotations.NotNull; @@ -53,9 +52,14 @@ public class ThrowExceptionAction extends DebuggerAction { debugProcess.getManagerThread().schedule(new DebuggerContextCommandImpl(debuggerContext, thread) { @Override public void threadAction(@NotNull SuspendContextImpl suspendContext) { - //noinspection SSBasedInspection - SwingUtilities.invokeLater( - () -> new ReturnExpressionDialog(project, debugProcess.getXdebugProcess().getEditorsProvider(), debugProcess, stackFrame).show()); + ApplicationManager.getApplication().invokeLater( + () -> new XExpressionDialog(project, debugProcess.getXdebugProcess().getEditorsProvider(), "throwExceptionValue", + "Exception To Throw", stackFrame.getSourcePosition(), null) { + @Override + protected void doOKAction() { + evaluateAndReturn(project, stackFrame, debugProcess, getExpression(), this); + } + }.show()); } }); } @@ -71,7 +75,7 @@ public class ThrowExceptionAction extends DebuggerAction { thread.stop((ObjectReference)value); } catch (Exception e) { - showError(debugProcess.getProject(), DebuggerBundle.message("error.early.return", e.getLocalizedMessage())); + showError(debugProcess.getProject(), DebuggerBundle.message("error.throw.exception", e.getLocalizedMessage())); return; } //noinspection SSBasedInspection @@ -127,45 +131,4 @@ public class ThrowExceptionAction extends DebuggerAction { e.getPresentation().setVisible(enable); } } - - private static class ReturnExpressionDialog extends DialogWrapper { - private final Project myProject; - private final XDebuggerEditorsProvider myEditorsProvider; - private final DebugProcessImpl myProcess; - private final JavaStackFrame myFrame; - private final XDebuggerExpressionEditor myEditor; - - public ReturnExpressionDialog(@NotNull Project project, - XDebuggerEditorsProvider provider, - DebugProcessImpl process, - JavaStackFrame frame) { - super(project); - myProject = project; - myEditorsProvider = provider; - myProcess = process; - myFrame = frame; - myEditor = new XDebuggerExpressionEditor(myProject, myEditorsProvider, "throwExceptionValue", myFrame.getSourcePosition(), - XExpressionImpl.EMPTY_EXPRESSION, false, true, false); - - setTitle("Exception"); - init(); - } - - @Nullable - @Override - protected JComponent createCenterPanel() { - return myEditor.getComponent(); - } - - @Nullable - @Override - public JComponent getPreferredFocusedComponent() { - return myEditor.getPreferredFocusedComponent(); - } - - @Override - protected void doOKAction() { - evaluateAndReturn(myProject, myFrame, myProcess, myEditor.getExpression(), this); - } - } } diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/requests/MethodReturnValueWatcher.java b/java/debugger/impl/src/com/intellij/debugger/engine/requests/MethodReturnValueWatcher.java index 469aebb543e9..0a488bae4bcf 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/requests/MethodReturnValueWatcher.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/requests/MethodReturnValueWatcher.java @@ -6,6 +6,7 @@ package com.intellij.debugger.engine.requests; import com.intellij.debugger.DebuggerBundle; import com.intellij.debugger.engine.DebugProcess; import com.intellij.debugger.engine.DebuggerManagerThreadImpl; +import com.intellij.debugger.impl.DebuggerUtilsEx; import com.intellij.debugger.settings.DebuggerSettings; import com.intellij.debugger.ui.overhead.OverheadProducer; import com.intellij.debugger.ui.overhead.OverheadTimings; @@ -60,7 +61,7 @@ public class MethodReturnValueWatcher implements OverheadProducer { final Method method = event.method(); final Value retVal = event.returnValue(); - if (method == null || !"void".equals(method.returnTypeName())) { + if (method == null || !DebuggerUtilsEx.isVoid(method)) { // remember methods with non-void return types only myLastExecutedMethod = method; myLastMethodReturnValue = retVal; diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsEx.java b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsEx.java index 45cd372eff64..b5e94982446b 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsEx.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsEx.java @@ -1,17 +1,5 @@ /* - * 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-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. */ /* @@ -625,6 +613,10 @@ public abstract class DebuggerUtilsEx extends DebuggerUtils { } } + public static boolean isVoid(@NotNull Method method) { + return "void".equals(method.returnTypeName()); + } + @Nullable public static Method getMethod(Location location) { try { diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/XExpressionDialog.kt b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/XExpressionDialog.kt index b9fd1d97e91d..6b8c43b69553 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/XExpressionDialog.kt +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/XExpressionDialog.kt @@ -1,17 +1,5 @@ /* - * 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-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. */ package com.intellij.xdebugger.impl.evaluate @@ -25,12 +13,12 @@ import javax.swing.JComponent /** * @author egor */ -class XExpressionDialog(project: Project, +open class XExpressionDialog(project: Project, editorsProvider: XDebuggerEditorsProvider, historyId: String, title: String, sourcePosition: XSourcePosition?, - expression: XExpression) : DialogWrapper(project) { + expression: XExpression?) : DialogWrapper(project) { private val myInputComponent: EvaluationInputComponent init { diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebuggerExpressionComboBox.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebuggerExpressionComboBox.java index 869a6be6ab28..284d79243bb1 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebuggerExpressionComboBox.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebuggerExpressionComboBox.java @@ -1,4 +1,6 @@ -// 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-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. + */ package com.intellij.xdebugger.impl.ui; import com.intellij.openapi.editor.Document; @@ -76,7 +78,7 @@ public class XDebuggerExpressionComboBox extends XDebuggerEditorBase { myComboBox.setMinimumSize(minimumSize); initEditor(showEditor, languageInside); fillComboBox(); - myComponent = JBUI.Panels.simplePanel(myComboBox); + myComponent = JBUI.Panels.simplePanel().addToTop(myComboBox); } public ComboBox getComboBox() { diff --git a/resources-en/src/messages/DebuggerBundle.properties b/resources-en/src/messages/DebuggerBundle.properties index 6b9ed4a85cb5..bc62a95740cc 100644 --- a/resources-en/src/messages/DebuggerBundle.properties +++ b/resources-en/src/messages/DebuggerBundle.properties @@ -30,6 +30,7 @@ error.modification.watchpoints.not.supported=Target VM does not support modifica error.native.method.exception=None of the frames through and including frame may be native error.executing.finally=Error while executing finally blocks: {0} error.early.return=Error while doing early return: {0} +error.throw.exception=Error while throwing exception: {0} warning.finally.block.detected=Non-empty finally blocks detected: button.drop.anyway=Do Not Execute button.execute.finally=Execute Finally Blocks