Skip to content

Commit 09bc3a7

Browse files
committed
migrated from legacy notification api
1 parent 7e2c33d commit 09bc3a7

3 files changed

Lines changed: 110 additions & 142 deletions

File tree

‎java-coverage-impl/src/main/java/com/intellij/java/coverage/CoverageJavaRunConfigurationExtension.java‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@
3636
import consulo.project.Project;
3737
import consulo.project.ui.notification.Notification;
3838
import consulo.project.ui.notification.NotificationGroup;
39+
import consulo.project.ui.notification.NotificationService;
3940
import consulo.project.ui.notification.NotificationType;
40-
import consulo.project.ui.notification.Notifications;
4141
import consulo.util.collection.ArrayUtil;
4242
import consulo.util.xml.serializer.InvalidDataException;
4343
import consulo.util.xml.serializer.WriteExternalException;
44-
import org.jspecify.annotations.Nullable;
4544
import org.jdom.Element;
45+
import org.jspecify.annotations.Nullable;
4646

4747
import java.util.ArrayList;
4848
import java.util.List;
@@ -90,14 +90,13 @@ public void updateJavaParameters(RunConfigurationBase configuration, OwnJavaPara
9090
Sdk jdk = params.getJdk();
9191
if (jdk != null && JavaSdkTypeUtil.isOfVersionOrHigher(jdk, JavaSdkVersion.JDK_1_7)
9292
&& coverageRunner instanceof JavaCoverageRunner javaCoverageRunner && !javaCoverageRunner.isJdk7Compatible()) {
93-
Notifications.Bus.notify(new Notification(
94-
NotificationGroup.balloonGroup("Coverage"),
95-
"Coverage instrumentation is not fully compatible with JDK 7",
96-
coverageRunner.getPresentableName() +
93+
NotificationService.getInstance()
94+
.newWarn(NotificationGroup.balloonGroup("Coverage"))
95+
.title(LocalizeValue.localizeTODO("Coverage instrumentation is not fully compatible with JDK 7"))
96+
.content(LocalizeValue.localizeTODO(coverageRunner.getPresentableName() +
9797
" coverage instrumentation can lead to java.lang.VerifyError errors with JDK 7. " +
98-
"If so, please try IDEA coverage runner.",
99-
NotificationType.WARNING
100-
));
98+
"If so, please try IDEA coverage runner."))
99+
.notify(configuration.getProject());
101100
}
102101
}
103102
}

‎java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/DebuggerSession.java‎

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -544,21 +544,20 @@ public void paused(SuspendContextImpl suspendContext) {
544544
JavaDebuggerLocalize.statusBreakpointReachedInThreadSwitch().get(),
545545
NotificationType.INFORMATION,
546546
(notification, event) -> {
547-
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
548-
notification.expire();
549-
getProcess().getManagerThread().schedule(new SuspendContextCommandImpl(suspendContext) {
550-
@Override
551-
public void contextAction() throws Exception {
552-
DebuggerContextImpl debuggerContext =
553-
DebuggerContextUtil.createDebuggerContext(DebuggerSession.this, suspendContext);
554-
555-
DebuggerInvocationUtil.invokeLater(
556-
getProject(),
557-
() -> getContextManager().setState(debuggerContext, State.PAUSED, Event.PAUSE)
558-
);
559-
}
560-
});
561-
}
547+
notification.expire();
548+
549+
getProcess().getManagerThread().schedule(new SuspendContextCommandImpl(suspendContext) {
550+
@Override
551+
public void contextAction(SuspendContextImpl suspendContext) throws Exception {
552+
DebuggerContextImpl debuggerContext =
553+
DebuggerContextUtil.createDebuggerContext(DebuggerSession.this, suspendContext);
554+
555+
DebuggerInvocationUtil.invokeLater(
556+
getProject(),
557+
() -> getContextManager().setState(debuggerContext, State.PAUSED, Event.PAUSE)
558+
);
559+
}
560+
});
562561
}
563562
).notify(getProject());
564563
}

‎java-debugger-impl/src/main/java/com/intellij/java/debugger/impl/engine/ThreadBlockedMonitor.java‎

Lines changed: 88 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
import consulo.project.ui.notification.Notification;
3232
import consulo.project.ui.notification.NotificationType;
3333
import consulo.project.ui.notification.event.NotificationListener;
34-
3534
import org.jspecify.annotations.Nullable;
35+
3636
import javax.swing.event.HyperlinkEvent;
3737
import java.util.Collection;
3838
import java.util.HashSet;
@@ -42,130 +42,100 @@
4242
/**
4343
* @author egor
4444
*/
45-
public class ThreadBlockedMonitor
46-
{
47-
private static final Logger LOG = Logger.getInstance(ThreadBlockedMonitor.class);
45+
public class ThreadBlockedMonitor {
46+
private static final Logger LOG = Logger.getInstance(ThreadBlockedMonitor.class);
4847

49-
private final Collection<ThreadReferenceProxy> myWatchedThreads = new HashSet<ThreadReferenceProxy>();
48+
private final Collection<ThreadReferenceProxy> myWatchedThreads = new HashSet<ThreadReferenceProxy>();
5049

51-
private ScheduledFuture<?> myTask;
52-
private final DebugProcessImpl myProcess;
50+
private ScheduledFuture<?> myTask;
51+
private final DebugProcessImpl myProcess;
5352

54-
public ThreadBlockedMonitor(DebugProcessImpl process, Disposable disposable)
55-
{
56-
myProcess = process;
57-
Disposer.register(disposable, this::cancelTask);
58-
}
53+
public ThreadBlockedMonitor(DebugProcessImpl process, Disposable disposable) {
54+
myProcess = process;
55+
Disposer.register(disposable, this::cancelTask);
56+
}
5957

60-
public void startWatching(@Nullable ThreadReferenceProxy thread)
61-
{
62-
DebuggerManagerThreadImpl.assertIsManagerThread();
63-
if(thread != null)
64-
{
65-
myWatchedThreads.add(thread);
66-
if(myTask == null)
67-
{
68-
myTask = AppExecutorUtil.getAppScheduledExecutorService().scheduleWithFixedDelay(this::checkBlockingThread, 5, 5, TimeUnit.SECONDS);
69-
}
70-
}
71-
}
58+
public void startWatching(@Nullable ThreadReferenceProxy thread) {
59+
DebuggerManagerThreadImpl.assertIsManagerThread();
60+
if (thread != null) {
61+
myWatchedThreads.add(thread);
62+
if (myTask == null) {
63+
myTask = AppExecutorUtil.getAppScheduledExecutorService().scheduleWithFixedDelay(this::checkBlockingThread, 5, 5, TimeUnit.SECONDS);
64+
}
65+
}
66+
}
7267

73-
public void stopWatching(@Nullable ThreadReferenceProxy thread)
74-
{
75-
DebuggerManagerThreadImpl.assertIsManagerThread();
76-
if(thread != null)
77-
{
78-
myWatchedThreads.remove(thread);
79-
}
80-
else
81-
{
82-
myWatchedThreads.clear();
83-
}
84-
if(myWatchedThreads.isEmpty())
85-
{
86-
cancelTask();
87-
}
88-
}
68+
public void stopWatching(@Nullable ThreadReferenceProxy thread) {
69+
DebuggerManagerThreadImpl.assertIsManagerThread();
70+
if (thread != null) {
71+
myWatchedThreads.remove(thread);
72+
}
73+
else {
74+
myWatchedThreads.clear();
75+
}
76+
if (myWatchedThreads.isEmpty()) {
77+
cancelTask();
78+
}
79+
}
8980

90-
private void cancelTask()
91-
{
92-
if(myTask != null)
93-
{
94-
myTask.cancel(true);
95-
myTask = null;
96-
}
97-
}
81+
private void cancelTask() {
82+
if (myTask != null) {
83+
myTask.cancel(true);
84+
myTask = null;
85+
}
86+
}
9887

99-
private static void onThreadBlocked(final ThreadReference blockedThread, final ThreadReference blockingThread, final DebugProcessImpl process)
100-
{
101-
XDebuggerUIConstants.NOTIFICATION_GROUP.createNotification(DebuggerBundle.message("status.thread.blocked.by", blockedThread.name(), blockingThread.name()), DebuggerBundle.message("status" + ""
102-
+ ".thread" + ".blocked.by.resume", blockingThread.name()), NotificationType.INFORMATION, new NotificationListener()
103-
{
104-
@Override
105-
public void hyperlinkUpdate(Notification notification, HyperlinkEvent event)
106-
{
107-
if(event.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
108-
{
109-
notification.expire();
110-
process.getManagerThread().schedule(new DebuggerCommandImpl()
111-
{
112-
@Override
113-
protected void action() throws Exception
114-
{
115-
ThreadReferenceProxyImpl threadProxy = process.getVirtualMachineProxy().getThreadReferenceProxy(blockingThread);
116-
SuspendContextImpl suspendingContext = SuspendManagerUtil.getSuspendingContext(process.getSuspendManager(), threadProxy);
117-
process.getManagerThread().invoke(process.createResumeThreadCommand(suspendingContext, threadProxy));
118-
}
119-
});
120-
}
121-
}
122-
}).notify(process.getProject());
123-
}
88+
private static void onThreadBlocked(final ThreadReference blockedThread, final ThreadReference blockingThread, final DebugProcessImpl process) {
89+
XDebuggerUIConstants.NOTIFICATION_GROUP.createNotification(DebuggerBundle.message("status.thread.blocked.by", blockedThread.name(), blockingThread.name()), DebuggerBundle.message("status" + ""
90+
+ ".thread" + ".blocked.by.resume", blockingThread.name()), NotificationType.INFORMATION, new NotificationListener() {
91+
@Override
92+
public void hyperlinkActivated(Notification notification, consulo.ui.event.HyperlinkEvent event) {
93+
notification.expire();
94+
process.getManagerThread().schedule(new DebuggerCommandImpl() {
95+
@Override
96+
protected void action() throws Exception {
97+
ThreadReferenceProxyImpl threadProxy = process.getVirtualMachineProxy().getThreadReferenceProxy(blockingThread);
98+
SuspendContextImpl suspendingContext = SuspendManagerUtil.getSuspendingContext(process.getSuspendManager(), threadProxy);
99+
process.getManagerThread().invoke(process.createResumeThreadCommand(suspendingContext, threadProxy));
100+
}
101+
});
102+
}
103+
}).notify(process.getProject());
104+
}
124105

125-
private ThreadReference getCurrentThread()
126-
{
127-
ThreadReferenceProxyImpl threadProxy = myProcess.getDebuggerContext().getThreadProxy();
128-
return threadProxy != null ? threadProxy.getThreadReference() : null;
129-
}
106+
private ThreadReference getCurrentThread() {
107+
ThreadReferenceProxyImpl threadProxy = myProcess.getDebuggerContext().getThreadProxy();
108+
return threadProxy != null ? threadProxy.getThreadReference() : null;
109+
}
130110

131-
private void checkBlockingThread()
132-
{
133-
myProcess.getManagerThread().schedule(new DebuggerCommandImpl()
134-
{
135-
@Override
136-
protected void action() throws Exception
137-
{
138-
if(myWatchedThreads.isEmpty())
139-
{
140-
return;
141-
}
142-
VirtualMachineProxyImpl vmProxy = myProcess.getVirtualMachineProxy();
143-
//TODO: can we do fast check without suspending all
144-
vmProxy.getVirtualMachine().suspend();
145-
try
146-
{
147-
for(ThreadReferenceProxy thread : myWatchedThreads)
148-
{
149-
ObjectReference waitedMonitor = vmProxy.canGetCurrentContendedMonitor() ? thread.getThreadReference().currentContendedMonitor() : null;
150-
if(waitedMonitor != null && vmProxy.canGetMonitorInfo())
151-
{
152-
ThreadReference blockingThread = waitedMonitor.owningThread();
153-
if(blockingThread != null && blockingThread.suspendCount() > 1 && getCurrentThread() != blockingThread)
154-
{
155-
onThreadBlocked(thread.getThreadReference(), blockingThread, myProcess);
156-
}
157-
}
158-
}
159-
}
160-
catch(IncompatibleThreadStateException e)
161-
{
162-
LOG.info(e);
163-
}
164-
finally
165-
{
166-
vmProxy.getVirtualMachine().resume();
167-
}
168-
}
169-
});
170-
}
111+
private void checkBlockingThread() {
112+
myProcess.getManagerThread().schedule(new DebuggerCommandImpl() {
113+
@Override
114+
protected void action() throws Exception {
115+
if (myWatchedThreads.isEmpty()) {
116+
return;
117+
}
118+
VirtualMachineProxyImpl vmProxy = myProcess.getVirtualMachineProxy();
119+
//TODO: can we do fast check without suspending all
120+
vmProxy.getVirtualMachine().suspend();
121+
try {
122+
for (ThreadReferenceProxy thread : myWatchedThreads) {
123+
ObjectReference waitedMonitor = vmProxy.canGetCurrentContendedMonitor() ? thread.getThreadReference().currentContendedMonitor() : null;
124+
if (waitedMonitor != null && vmProxy.canGetMonitorInfo()) {
125+
ThreadReference blockingThread = waitedMonitor.owningThread();
126+
if (blockingThread != null && blockingThread.suspendCount() > 1 && getCurrentThread() != blockingThread) {
127+
onThreadBlocked(thread.getThreadReference(), blockingThread, myProcess);
128+
}
129+
}
130+
}
131+
}
132+
catch (IncompatibleThreadStateException e) {
133+
LOG.info(e);
134+
}
135+
finally {
136+
vmProxy.getVirtualMachine().resume();
137+
}
138+
}
139+
});
140+
}
171141
}

0 commit comments

Comments
 (0)