mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cheaper UIUtil.dispatchAllInvocationEvents
avoid reflection and assertions on each event
This commit is contained in:
+2
-2
@@ -2360,14 +2360,14 @@ public class DaemonRespondToChangesTest extends DaemonAnalyzerTestCase {
|
||||
long deadline = System.currentTimeMillis() + 60_000;
|
||||
while (!daemonIsWorkingOrPending()) {
|
||||
if (System.currentTimeMillis() > deadline) fail("Too long waiting for daemon to start");
|
||||
UIUtil.dispatchInvocationEvent();
|
||||
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue();
|
||||
}
|
||||
while (daemonIsWorkingOrPending()) {
|
||||
if (System.currentTimeMillis() > deadline) {
|
||||
dumpThreadsToConsole();
|
||||
fail("Too long waiting for daemon to finish");
|
||||
}
|
||||
UIUtil.dispatchInvocationEvent();
|
||||
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2321,12 +2321,36 @@ public class UIUtil {
|
||||
g.setComposite(X_RENDER_ACTIVE.getValue() ? AlphaComposite.SrcOver : AlphaComposite.Src);
|
||||
}
|
||||
|
||||
/** @see #pump() */
|
||||
/**
|
||||
* In tests, consider using {@link com.intellij.testFramework.PlatformTestUtil#dispatchAllInvocationEventsInIdeEventQueue()}
|
||||
* @see #pump()
|
||||
*/
|
||||
@TestOnly
|
||||
public static void dispatchAllInvocationEvents() {
|
||||
assert EdtInvocationManager.getInstance().isEventDispatchThread() : Thread.currentThread() + "; EDT: "+getEventQueueThread();
|
||||
EventQueue eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue();
|
||||
Method dispatchEventMethod;
|
||||
try {
|
||||
dispatchEventMethod = eventQueue.getClass().getDeclaredMethod("dispatchEvent", AWTEvent.class);
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
for (int i = 1; ; i++) {
|
||||
AWTEvent event = dispatchInvocationEvent();
|
||||
AWTEvent event = eventQueue.peekEvent();
|
||||
if (event == null) break;
|
||||
try {
|
||||
event = eventQueue.getNextEvent();
|
||||
if (event instanceof InvocationEvent) {
|
||||
dispatchEventMethod.invoke(eventQueue, event);
|
||||
}
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
ExceptionUtil.rethrowAllAsUnchecked(e.getCause());
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
|
||||
if (i % 10000 == 0) {
|
||||
//noinspection UseOfSystemOutOrSystemErr
|
||||
@@ -2335,27 +2359,6 @@ public class UIUtil {
|
||||
}
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
public static AWTEvent dispatchInvocationEvent() {
|
||||
assert EdtInvocationManager.getInstance().isEventDispatchThread() : Thread.currentThread() + "; EDT: "+getEventQueueThread();
|
||||
final EventQueue eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue();
|
||||
AWTEvent event = eventQueue.peekEvent();
|
||||
if (event == null) return null;
|
||||
try {
|
||||
event = eventQueue.getNextEvent();
|
||||
if (event instanceof InvocationEvent) {
|
||||
eventQueue.getClass().getDeclaredMethod("dispatchEvent", AWTEvent.class).invoke(eventQueue, event);
|
||||
}
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
ExceptionUtil.rethrowAllAsUnchecked(e.getCause());
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
||||
private static Thread getEventQueueThread() {
|
||||
EventQueue eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user