From 62396e7f197b93c20522ab3007183e0650d01964 Mon Sep 17 00:00:00 2001 From: Alexander Kurtakov Date: Wed, 6 Jan 2016 15:03:44 +0200 Subject: Bug 484699 - Use vararg reflection methods in SWT_AWT Get Cocoa/Win32 in sync with GTK. While at it drop SuppressWarnings("rawtypes") and fixes the warnings too. Change-Id: I8d07194c7d52017d4e48a7f05935dee7756c2ecb Signed-off-by: Alexander Kurtakov --- .../cocoa/org/eclipse/swt/awt/SWT_AWT.java | 33 ++++++++++------------ .../win32/org/eclipse/swt/awt/SWT_AWT.java | 33 ++++++++++------------ 2 files changed, 30 insertions(+), 36 deletions(-) (limited to 'bundles/org.eclipse.swt/Eclipse SWT AWT') diff --git a/bundles/org.eclipse.swt/Eclipse SWT AWT/cocoa/org/eclipse/swt/awt/SWT_AWT.java b/bundles/org.eclipse.swt/Eclipse SWT AWT/cocoa/org/eclipse/swt/awt/SWT_AWT.java index 29fad5854f..d75ca4eaba 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT AWT/cocoa/org/eclipse/swt/awt/SWT_AWT.java +++ b/bundles/org.eclipse.swt/Eclipse SWT AWT/cocoa/org/eclipse/swt/awt/SWT_AWT.java @@ -32,7 +32,6 @@ import org.eclipse.swt.widgets.Event; * * @since 3.0 */ -@SuppressWarnings("rawtypes") public class SWT_AWT { /** @@ -84,11 +83,9 @@ public class SWT_AWT { swingInitialized = true; try { /* Initialize the default focus traversal policy */ - Class[] emptyClass = new Class[0]; - Object[] emptyObject = new Object[0]; - Class clazz = Class.forName("javax.swing.UIManager"); - Method method = clazz.getMethod("getDefaults", emptyClass); - if (method != null) method.invoke(clazz, emptyObject); + Class clazz = Class.forName("javax.swing.UIManager"); + Method method = clazz.getMethod("getDefaults"); + if (method != null) method.invoke(clazz); } catch (Throwable e) {} } @@ -142,7 +139,7 @@ public static Frame new_Frame(final Composite parent) { final long /*int*/ handle = parent.view.id; - final Class [] clazz = new Class [1]; + final Class [] clazz = new Class [1]; try { String className = embeddedFrameClass != null ? embeddedFrameClass : JDK16_FRAME; if (embeddedFrameClass == null) { @@ -170,10 +167,10 @@ public static Frame new_Frame(final Composite parent) { public void run() { if (run) return; run = true; - Constructor constructor = null; + Constructor constructor = null; try { - constructor = clazz[0].getConstructor (new Class [] {long.class}); - result [0] = (Frame) (constructor.newInstance (new Object [] {new Long(handle)})); + constructor = clazz[0].getConstructor (long.class); + result [0] = (Frame) (constructor.newInstance (new Long(handle))); result [0].addNotify(); } catch (Throwable e) { exception[0] = e; @@ -280,9 +277,9 @@ public static Frame new_Frame(final Composite parent) { public void run () { if (frame.isActive()) return; try { - Class clazz = frame.getClass(); - Method method = clazz.getMethod("synthesizeWindowActivation", new Class[]{boolean.class}); - if (method != null) method.invoke(frame, new Object[]{Boolean.TRUE}); + Class clazz = frame.getClass(); + Method method = clazz.getMethod("synthesizeWindowActivation", boolean.class); + if (method != null) method.invoke(frame, Boolean.TRUE); } catch (Throwable e) {e.printStackTrace();} } }); @@ -293,9 +290,9 @@ public static Frame new_Frame(final Composite parent) { public void run () { if (!frame.isActive()) return; try { - Class clazz = frame.getClass(); - Method method = clazz.getMethod("synthesizeWindowActivation", new Class[]{boolean.class}); - if (method != null) method.invoke(frame, new Object[]{Boolean.FALSE}); + Class clazz = frame.getClass(); + Method method = clazz.getMethod("synthesizeWindowActivation", boolean.class); + if (method != null) method.invoke(frame, Boolean.FALSE); } catch (Throwable e) {e.printStackTrace();} } }); @@ -321,8 +318,8 @@ public static Frame new_Frame(final Composite parent) { final Rectangle clientArea = parent.getClientArea(); if (isJDK17) { try { - Method method = frame.getClass().getMethod("validateWithBounds", new Class[] {int.class, int.class, int.class, int.class}); - if (method != null) method.invoke(frame, new Object[]{new Integer(clientArea.x), new Integer(clientArea.y), new Integer(clientArea.width), new Integer(clientArea.height)}); + Method method = frame.getClass().getMethod("validateWithBounds", int.class, int.class, int.class, int.class); + if (method != null) method.invoke(frame, new Integer(clientArea.x), new Integer(clientArea.y), new Integer(clientArea.width), new Integer(clientArea.height)); } catch (Throwable e) {e.printStackTrace();} } else { EventQueue.invokeLater(new Runnable () { diff --git a/bundles/org.eclipse.swt/Eclipse SWT AWT/win32/org/eclipse/swt/awt/SWT_AWT.java b/bundles/org.eclipse.swt/Eclipse SWT AWT/win32/org/eclipse/swt/awt/SWT_AWT.java index 3d12f1b96a..7a815ee1db 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT AWT/win32/org/eclipse/swt/awt/SWT_AWT.java +++ b/bundles/org.eclipse.swt/Eclipse SWT AWT/win32/org/eclipse/swt/awt/SWT_AWT.java @@ -34,7 +34,6 @@ import org.eclipse.swt.widgets.Event; * * @since 3.0 */ -@SuppressWarnings("rawtypes") public class SWT_AWT { /** @@ -74,11 +73,9 @@ static synchronized void initializeSwing() { swingInitialized = true; try { /* Initialize the default focus traversal policy */ - Class[] emptyClass = new Class[0]; - Object[] emptyObject = new Object[0]; - Class clazz = Class.forName("javax.swing.UIManager"); - Method method = clazz.getMethod("getDefaults", emptyClass); - if (method != null) method.invoke(clazz, emptyObject); + Class clazz = Class.forName("javax.swing.UIManager"); + Method method = clazz.getMethod("getDefaults"); + if (method != null) method.invoke(clazz); } catch (Throwable e) {} } @@ -140,7 +137,7 @@ public static Frame new_Frame (final Composite parent) { * and other JREs take a long. To handle this binary incompatibility, use * reflection to create the embedded frame. */ - Class clazz = null; + Class clazz = null; try { String className = embeddedFrameClass != null ? embeddedFrameClass : "sun.awt.windows.WEmbeddedFrame"; clazz = Class.forName(className); @@ -150,14 +147,14 @@ public static Frame new_Frame (final Composite parent) { } initializeSwing (); Object value = null; - Constructor constructor = null; + Constructor constructor = null; try { - constructor = clazz.getConstructor (new Class [] {int.class}); - value = constructor.newInstance (new Object [] {new Integer ((int)/*64*/handle)}); + constructor = clazz.getConstructor (int.class); + value = constructor.newInstance (new Integer ((int)/*64*/handle)); } catch (Throwable e1) { try { - constructor = clazz.getConstructor (new Class [] {long.class}); - value = constructor.newInstance (new Object [] {new Long (handle)}); + constructor = clazz.getConstructor (long.class); + value = constructor.newInstance (new Long (handle)); } catch (Throwable e2) { exception[0] = e2; return; @@ -275,9 +272,9 @@ public static Frame new_Frame (final Composite parent) { } else { if (frame.isActive()) return; try { - Class clazz = frame.getClass(); - Method method = clazz.getMethod("synthesizeWindowActivation", new Class[]{boolean.class}); - if (method != null) method.invoke(frame, new Object[]{Boolean.TRUE}); + Class clazz = frame.getClass(); + Method method = clazz.getMethod("synthesizeWindowActivation", boolean.class); + if (method != null) method.invoke(frame, Boolean.TRUE); } catch (Throwable e) {} } } @@ -295,9 +292,9 @@ public static Frame new_Frame (final Composite parent) { } else { if (!frame.isActive()) return; try { - Class clazz = frame.getClass(); - Method method = clazz.getMethod("synthesizeWindowActivation", new Class[]{boolean.class}); - if (method != null) method.invoke(frame, new Object[]{Boolean.FALSE}); + Class clazz = frame.getClass(); + Method method = clazz.getMethod("synthesizeWindowActivation", boolean.class); + if (method != null) method.invoke(frame, Boolean.FALSE); } catch (Throwable e) {} } } -- cgit v1.2.3