List of usage examples for java.lang.reflect Method setAccessible
@Override @CallerSensitive public void setAccessible(boolean flag)
From source file:io.github.seleniumquery.by.DriverVersionUtils.java
private static String getEmulatedBrowser(HtmlUnitDriver htmlUnitDriver) { try {//from w w w . j a v a 2 s . com // #HtmlUnit #reflection #hack Method getWebClientMethod = HtmlUnitDriver.class.getDeclaredMethod("getWebClient"); boolean wasAccessibleBefore = getWebClientMethod.isAccessible(); getWebClientMethod.setAccessible(true); WebClient webClient = (WebClient) getWebClientMethod.invoke(htmlUnitDriver); getWebClientMethod.setAccessible(wasAccessibleBefore); return webClient.getBrowserVersion().toString(); } catch (Exception e) { LOGGER.debug("Error while inspecting HtmlUnitDriver version.", e); return ""; } }
From source file:com.github.hibatis.ReflectionUtils.java
/** * ?, ?DeclaredMethod,?./*from ww w. j a v a 2 s. co m*/ * ?Object?, null. * * ?. ?Method,?Method.invoke(Object obj, Object... args) */ public static Method getAccessibleMethod(final Object obj, final String methodName, final Class<?>... parameterTypes) { for (Class<?> superClass = obj.getClass(); superClass != Object.class; superClass = superClass .getSuperclass()) { try { Method method = superClass.getDeclaredMethod(methodName, parameterTypes); method.setAccessible(true); return method; } catch (NoSuchMethodException e) {// NOSONAR // Method??,? } } return null; }
From source file:cn.geobeans.web.common.utils.ReflectionUtils.java
/** * ?, ?DeclaredMethod,?.//from ww w. j a v a 2 s. c om * ?Object?, null. * * ?. ?Method,?Method.invoke(Object obj, Object... args) */ public static Method getAccessibleMethod(final Object obj, final String methodName, final Class<?>... parameterTypes) { Assert.notNull(obj, "object?"); for (Class<?> superClass = obj.getClass(); superClass != Object.class; superClass = superClass .getSuperclass()) { try { Method method = superClass.getDeclaredMethod(methodName, parameterTypes); method.setAccessible(true); return method; } catch (NoSuchMethodException e) {//NOSONAR // Method??,? } } return null; }
From source file:jp.terasoluna.fw.batch.unit.util.ClassLoaderUtils.java
private static Method getAddURLMethod() { try {// w w w. j ava 2 s . c om Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class<?>[] { URL.class }); method.setAccessible(true); return method; } catch (Exception e) { throw new UTRuntimeException(e); } }
From source file:com.fizzed.rocker.bin.ConstantPoolMain.java
static public boolean isClassLoaded(String className) throws Exception { System.out.print("Is " + className + " loaded? "); java.lang.reflect.Method m = ClassLoader.class.getDeclaredMethod("findLoadedClass", new Class[] { String.class }); m.setAccessible(true); ClassLoader cl = ConstantPoolMain.class.getClassLoader(); Object loadedClass = m.invoke(cl, className); boolean b = (loadedClass != null); System.out.println(b + ""); return b;/*from w ww . j ava2 s. co m*/ }
From source file:com.stargis.pipe.util.ReflectionUtils.java
/** * ?, ?DeclaredMethod,?./*from w ww .ja v a2 s .c o m*/ * ?Object?, null. * * ?. ?Method,?Method.invoke(Object obj, Object... args) */ public static Method getAccessibleMethod(final Object obj, final String methodName, final Class<?>... parameterTypes) { // Assert.notNull(obj, "object?"); for (Class<?> superClass = obj.getClass(); superClass != Object.class; superClass = superClass .getSuperclass()) { try { Method method = superClass.getDeclaredMethod(methodName, parameterTypes); method.setAccessible(true); return method; } catch (NoSuchMethodException e) {//NOSONAR // Method??,? } } return null; }
From source file:SigningProcess.java
private static Object invokeGetter(Object instance, String methodName) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { Method getAlias = instance.getClass().getDeclaredMethod(methodName); getAlias.setAccessible(true); return getAlias.invoke(instance); }
From source file:com.google.gdt.eclipse.designer.mac.BrowserShellMacImplCocoa.java
private static Image createImageFromHandle(long imageHandle, int width, int height) throws Exception { if (imageHandle != 0) { Class<?> nsImageClass = Class.forName("org.eclipse.swt.internal.cocoa.NSImage"); Object handleObject;/* www. j a va 2s . c o m*/ Class<?> handleClass; if (SystemUtils.OS_ARCH.indexOf("64") != -1) { handleClass = long.class; handleObject = new Long(imageHandle); } else { handleClass = int.class; handleObject = new Integer((int) imageHandle); } Constructor<?> constructor = nsImageClass.getConstructor(handleClass); Object nsImage = constructor.newInstance(handleObject); // Create a temporary image using the captured image's handle Class<?> NSImageClass = Class.forName("org.eclipse.swt.internal.cocoa.NSImage"); Method method = Image.class.getDeclaredMethod("cocoa_new", new Class[] { Device.class, int.class, NSImageClass }); method.setAccessible(true); Image tempImage = (Image) method.invoke(null, new Object[] { Display.getCurrent(), new Integer(SWT.BITMAP), nsImage }); // Create the result image Image image = new Image(Display.getCurrent(), width, height); // Manually copy because the image's data handle isn't available GC gc = new GC(tempImage); gc.copyArea(image, 0, 0); gc.dispose(); // Dispose of the temporary image allocated in the native call tempImage.dispose(); return image; } // prevent failing return new Image(Display.getCurrent(), 1, 1); }
From source file:com.lily.dap.util.ReflectionUtils.java
/** * , DeclaredMethod,.// w w w.jav a 2 s.c om * Object, null. * * . Method,Method.invoke(Object obj, Object... args) */ public static Method getAccessibleMethod(final Object obj, final String methodName, final Class<?>... parameterTypes) { for (Class<?> superClass = obj.getClass(); superClass != Object.class; superClass = superClass .getSuperclass()) { try { Method method = superClass.getDeclaredMethod(methodName, parameterTypes); method.setAccessible(true); return method; } catch (NoSuchMethodException e) {//NOSONAR // Method, } } return null; }
From source file:com.jdy.ddj.common.utils.Reflections.java
/** * ?, ?DeclaredMethod,?./*from w w w . ja va2s . c o m*/ * ?Object?, null. * * ?. ?Method,?Method.invoke(Object obj, Object... args) */ public static Method getAccessibleMethod(final Object obj, final String methodName, final Class<?>... parameterTypes) { Validate.notNull(obj, "object can't be null"); for (Class<?> superClass = obj.getClass(); superClass != Object.class; superClass = superClass .getSuperclass()) { try { Method method = superClass.getDeclaredMethod(methodName, parameterTypes); method.setAccessible(true); return method; } catch (NoSuchMethodException e) {//NOSONAR // Method??,? } } return null; }