List of usage examples for java.lang.reflect Method setAccessible
@Override @CallerSensitive public void setAccessible(boolean flag)
From source file:$.Reflections.java
/** * ?private/protectedpublic?????JDKSecurityManager *//* w w w .j a v a2 s . c o m*/ public static void makeAccessible(Method method) { if ((!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers())) && !method.isAccessible()) { method.setAccessible(true); } }
From source file:com.kangyonggan.cms.util.Reflections.java
/** * ?private/protectedpublic?????JDKSecurityManager *///from ww w . java 2 s . com public static void makeAccessible(Method method) { boolean temp = (!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers())) && !method.isAccessible(); if (temp) { method.setAccessible(true); } }
From source file:com.googlecode.dex2jar.test.TestUtils.java
public static byte[] testDexASMifier(Class<?> clz, String methodName, String generateClassName) throws Exception { final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC, generateClassName, null, "java/lang/Object", null); EmptyVisitor em = new EmptyVisitor() { public DexMethodVisitor visitMethod(int accessFlags, com.googlecode.dex2jar.Method method) { return new V3MethodAdapter(accessFlags, method, null, V3.OPTIMIZE_SYNCHRONIZED | V3.TOPOLOGICAL_SORT) { @Override/* w w w.j ava 2 s . c o m*/ public void visitEnd() { super.visitEnd(); methodNode.accept(cw); } }; } @Override public DexFieldVisitor visitField(int accessFlags, com.googlecode.dex2jar.Field field, Object value) { FieldVisitor fv = cw.visitField(accessFlags, field.getName(), field.getType(), null, value); fv.visitEnd(); return null; } }; Method m = clz.getMethod(methodName, DexClassVisitor.class); if (m == null) { throw new java.lang.NoSuchMethodException(methodName); } m.setAccessible(true); m.invoke(null, em); byte[] data = cw.toByteArray(); ClassReader cr = new ClassReader(data); TestUtils.verify(cr); return data; }
From source file:com.cnksi.core.tools.utils.Reflections.java
/** * ?private/protectedpublic?????JDKSecurityManager */// www . ja v a 2 s. c o m public static void makeAccessible(Method method) { if ((!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers())) && !method.isAccessible()) { method.setAccessible(true); } }
From source file:com.dwdesign.tweetings.util.WebViewProxySettings.java
public static boolean setProxy(WebView webView, String host, int port) { final Context context = webView.getContext(); // PSIPHON: added support for Android 4.x WebView proxy try {//from www. jav a 2 s . c o m final Class<?> webViewCoreClass = Class.forName("android.webkit.WebViewCore"); final Class<?> proxyPropertiesClass = Class.forName("android.net.ProxyProperties"); if (webViewCoreClass != null && proxyPropertiesClass != null) { final Method m = webViewCoreClass.getDeclaredMethod("sendStaticMessage", Integer.TYPE, Object.class); final Constructor<?> c = proxyPropertiesClass.getConstructor(String.class, Integer.TYPE, String.class); if (m != null && c != null) { m.setAccessible(true); c.setAccessible(true); final Object properties = c.newInstance(host, port, null); // android.webkit.WebViewCore.EventHub.PROXY_CHANGED = 193; m.invoke(null, 193, properties); return true; } } } catch (final Exception e) { Log.e("ProxySettings", "Exception setting WebKit proxy through android.net.ProxyProperties: " + e.toString()); } try { final Object requestQueueObject = getRequestQueue(context); if (requestQueueObject != null) { // Create Proxy config object and set it into request Q final HttpHost httpHost = new HttpHost(host, port, "http"); setDeclaredField(requestQueueObject, "mProxyHost", httpHost); // Log.d("Webkit Setted Proxy to: " + host + ":" + port); return true; } } catch (final Exception e) { Log.e("ProxySettings", "Exception setting WebKit proxy through android.webkit.Network: " + e.toString()); } return false; }
From source file:com.ekingsoft.core.utils.ReflectionUtils.java
/** * ,private/protected./*from w w w . ja va2 s . c o m*/ */ public static Object invokeMethod(final Object object, final String methodName, final Class<?>[] parameterTypes, final Object[] parameters) throws InvocationTargetException { Method method = getDeclaredMethod(object, methodName, parameterTypes); if (method == null) throw new IllegalArgumentException( "Could not find method [" + methodName + "] on target [" + object + "]"); method.setAccessible(true); try { return method.invoke(object, parameters); } catch (IllegalAccessException e) { logger.error("??:{}", e.getMessage()); } return null; }
From source file:ca.psiphon.tunneledwebview.WebViewProxySettings.java
@SuppressWarnings("rawtypes") private static boolean setWebkitProxyICS(Context ctx, String host, int port) { try {// w w w . ja v a 2 s . c o m Class webViewCoreClass = Class.forName("android.webkit.WebViewCore"); Class proxyPropertiesClass = Class.forName("android.net.ProxyProperties"); if (webViewCoreClass != null && proxyPropertiesClass != null) { Method m = webViewCoreClass.getDeclaredMethod("sendStaticMessage", Integer.TYPE, Object.class); Constructor c = proxyPropertiesClass.getConstructor(String.class, Integer.TYPE, String.class); if (m != null && c != null) { m.setAccessible(true); c.setAccessible(true); Object properties = c.newInstance(host, port, null); // android.webkit.WebViewCore.EventHub.PROXY_CHANGED = 193; m.invoke(null, 193, properties); return true; } } } catch (Exception e) { } catch (Error e) { } return false; }
From source file:com.open.cas.shiro.util.ReflectionUtils.java
/** * ?, ?DeclaredMethod,?./*from w w w.j a v a 2 s . c om*/ * ?Object?, null. * * ?. ?Method,?Method.invoke(Object obj, Object... args) */ public static Method getAccessibleStaticMethod(final Class<?> clazz, final String methodName, final Class<?>... parameterTypes) { for (Class<?> superClass = clazz; superClass != Object.class; superClass = superClass.getSuperclass()) { try { Method method = superClass.getMethod(methodName, parameterTypes); method.setAccessible(true); return method; } catch (NoSuchMethodException e) {//NOSONAR // Method??,? } } return null; }
From source file:com.haulmont.bali.util.ReflectionHelper.java
/** * Searches for a method by its name and arguments. * @param c class// w ww . j av a2s . com * @param name method name * @param params method arguments * @return method reference or null if a suitable method not found */ @Nullable public static Method findMethod(Class c, String name, Object... params) { Class[] paramTypes = getParamTypes(params); Method method = null; try { method = c.getDeclaredMethod(name, paramTypes); } catch (NoSuchMethodException e) { try { method = c.getMethod(name, paramTypes); } catch (NoSuchMethodException e1) { // } } if (method != null) method.setAccessible(true); return method; }
From source file:com.xyz.util.ReflectionUtil.java
/** * ,private/protected.//w ww .j a va 2 s . co m */ public static Object invokeMethod(final Object object, final String methodName, final Class<?>[] parameterTypes, final Object[] parameters) throws InvocationTargetException { Method method = getDeclaredMethod(object, methodName, parameterTypes); if (method == null) throw new IllegalArgumentException( "Could not find method [" + methodName + "] on target [" + object + "]"); method.setAccessible(true); try { return method.invoke(object, parameters); } catch (IllegalAccessException e) { logger.error("??:" + e.getMessage()); } return null; }