From 2e82d598cc36209921f08826e17020e9da3787cd Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Fri, 10 Jul 2015 18:34:37 +0300 Subject: [PATCH] show notification if breakpoint is reached in another thread --- .../debugger/impl/DebuggerSession.java | 36 +++++++++++++++++++ .../src/messages/DebuggerBundle.properties | 2 ++ 2 files changed, 38 insertions(+) diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerSession.java b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerSession.java index eb0867dbf7da..bccc7caa8f51 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerSession.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerSession.java @@ -38,6 +38,9 @@ import com.intellij.execution.configurations.RunProfileState; import com.intellij.execution.process.ProcessHandler; import com.intellij.execution.process.ProcessOutputTypes; import com.intellij.idea.ActionsBundle; +import com.intellij.notification.Notification; +import com.intellij.notification.NotificationListener; +import com.intellij.notification.NotificationType; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.diagnostic.Logger; @@ -60,6 +63,7 @@ import com.intellij.util.ui.UIUtil; import com.intellij.xdebugger.AbstractDebuggerSession; import com.intellij.xdebugger.XDebugSession; import com.intellij.xdebugger.XSourcePosition; +import com.intellij.xdebugger.impl.XDebugSessionImpl; import com.intellij.xdebugger.impl.actions.XDebuggerActions; import com.intellij.xdebugger.impl.evaluate.quick.common.ValueLookupManager; import com.sun.jdi.ObjectCollectedException; @@ -70,6 +74,7 @@ import com.sun.jdi.request.StepRequest; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import javax.swing.event.HyperlinkEvent; import java.util.Collection; import java.util.List; import java.util.Set; @@ -451,6 +456,37 @@ public class DebuggerSession implements AbstractDebuggerSession { getContextManager().fireStateChanged(getContextManager().getContext(), EVENT_THREADS_REFRESH); } }); + final ThreadReferenceProxyImpl thread = suspendContext.getThread(); + if (thread != null) { + List> descriptors = DebuggerUtilsEx.getEventDescriptors(suspendContext); + if (!descriptors.isEmpty()) { + XDebugSessionImpl.NOTIFICATION_GROUP.createNotification( + DebuggerBundle.message("status.breakpoint.reached.in.thread", thread.name()), + DebuggerBundle.message("status.breakpoint.reached.in.thread.switch"), + NotificationType.INFORMATION, new NotificationListener() { + @Override + public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { + if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { + notification.expire(); + getProcess().getManagerThread().schedule(new SuspendContextCommandImpl(suspendContext) { + @Override + public void contextAction() throws Exception { + final DebuggerContextImpl debuggerContext = + DebuggerContextImpl.createDebuggerContext(DebuggerSession.this, suspendContext, thread, null); + + DebuggerInvocationUtil.invokeLater(getProject(), new Runnable() { + @Override + public void run() { + getContextManager().setState(debuggerContext, STATE_PAUSED, EVENT_PAUSE, null); + } + }); + } + }); + } + } + }).notify(getProject()); + } + } return; } diff --git a/resources-en/src/messages/DebuggerBundle.properties b/resources-en/src/messages/DebuggerBundle.properties index 27a21049be93..4e8f16a937b5 100644 --- a/resources-en/src/messages/DebuggerBundle.properties +++ b/resources-en/src/messages/DebuggerBundle.properties @@ -49,6 +49,8 @@ status.line.breakpoint.reached=Breakpoint reached at {0}({1}:{2,number,#}) status.line.breakpoint.reached.full.trace=Breakpoint reached at {0} export.threads.stackframe.format=at {0}({1}:{2,number,#}) status.generic.breakpoint.reached=Breakpoint reached +status.breakpoint.reached.in.thread=Breakpoint reached in thread {0} +status.breakpoint.reached.in.thread.switch=Switch thread status.method.entry.breakpoint.reached=Method ''{0}'' entered at {1}({2}:{3,number,#}) status.method.exit.breakpoint.reached=Method breakpoint reached. Method ''{0}'' is about to exit at {1}({2}:{3,number,#}) status.exception.breakpoint.reached=Exception breakpoint reached