[ui] use reflection to access internal AWTAccessor class in MacUtil
authorNikolay Chashnikov <Nikolay.Chashnikov@jetbrains.com>
Wed, 12 Aug 2020 14:49:26 +0000 (17:49 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Wed, 12 Aug 2020 17:09:05 +0000 (17:09 +0000)
This is needed to be able to compile intellij.platform.util.ui module using JDK 11 (IDEA-248086).

GitOrigin-RevId: 7ec2135f70933d75b34ef578e16adb3bce4242f1

platform/util/ui/src/com/intellij/ui/mac/foundation/MacUtil.java

index a005c8fe47ac8e5a9d2fbe81db55d7c6da0246ca..af7f1d32b595a517c72b83b2a8980700ebf0e83d 100644 (file)
@@ -9,7 +9,6 @@ import com.intellij.openapi.util.registry.Registry;
 import com.sun.jna.Pointer;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
-import sun.awt.AWTAccessor;
 
 import javax.swing.*;
 import javax.swing.text.JTextComponent;
@@ -145,14 +144,17 @@ public final class MacUtil {
     ID windowId = null;
     if (Registry.is("skip.untitled.windows.for.mac.messages")) {
       try {
-        Class <?> cWindowPeerClass  = AWTAccessor.getComponentAccessor().getPeer(w).getClass();
+        Class<?> awtAccessor = Class.forName("sun.awt.AWTAccessor");
+        Object componentAccessor = awtAccessor.getMethod("getComponentAccessor").invoke(null);
+        Object peer = componentAccessor.getClass().getMethod("getPeer", Component.class).invoke(componentAccessor, w);
+        Class<?> cWindowPeerClass  = peer.getClass();
         Method getPlatformWindowMethod = cWindowPeerClass.getDeclaredMethod("getPlatformWindow");
-        Object cPlatformWindow = getPlatformWindowMethod.invoke(AWTAccessor.getComponentAccessor().getPeer(w));
-        Class <?> cPlatformWindowClass = cPlatformWindow.getClass();
+        Object cPlatformWindow = getPlatformWindowMethod.invoke(peer);
+        Class<?> cPlatformWindowClass = cPlatformWindow.getClass();
         Method getNSWindowPtrMethod = cPlatformWindowClass.getDeclaredMethod("getNSWindowPtr");
         windowId = new ID((Long)getNSWindowPtrMethod.invoke(cPlatformWindow));
       }
-      catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
+      catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | ClassNotFoundException e) {
         LOG.debug(e);
       }
     }