当前位置: 首页>>代码示例>>Java>>正文


Java Method.isAccessible方法代码示例

本文整理汇总了Java中java.lang.reflect.Method.isAccessible方法的典型用法代码示例。如果您正苦于以下问题:Java Method.isAccessible方法的具体用法?Java Method.isAccessible怎么用?Java Method.isAccessible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.reflect.Method的用法示例。


在下文中一共展示了Method.isAccessible方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
private Method getMethod(final Class<?> type, final String name, final Class<?>... parameterTypes) {
    if (type == null) {
        return null;
    }
    final FastField method = new FastField(type, name);
    Method result = cache.get(method);

    if (result == null) {
        try {
            result = type.getDeclaredMethod(name, parameterTypes);
            if (!result.isAccessible()) {
                result.setAccessible(true);
            }
        } catch (final NoSuchMethodException e) {
            result = getMethod(type.getSuperclass(), name, parameterTypes);
        }
        cache.put(method, result);
    }
    return result;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:SerializationMethodInvoker.java

示例2: findMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Locates a given method anywhere in the class inheritance hierarchy.
 *
 * @param instance       an object to search the method into.
 * @param name           method name
 * @param parameterTypes method parameter types
 * @return a method object
 * @throws NoSuchMethodException if the method cannot be located
 */
public static Method findMethod(Object instance, String name, Class<?>... parameterTypes)
    throws NoSuchMethodException {
    for (Class<?> clazz = instance.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
        try {
            Method method = clazz.getDeclaredMethod(name, parameterTypes);

            if (!method.isAccessible()) {
                method.setAccessible(true);
            }

            return method;
        } catch (NoSuchMethodException e) {
            // ignore and search next
        }
    }

    throw new NoSuchMethodException("Method "
        + name
        + " with parameters "
        + Arrays.asList(parameterTypes)
        + " not found in " + instance.getClass());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:32,代码来源:ShareReflectUtil.java

示例3: invokeMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
public static Object invokeMethod(Method method, Object methodReceiver, Object... methodParamValues) throws
        InvocationTargetException, IllegalAccessException {

    if (method != null) {
        boolean acc = method.isAccessible();

        if (!acc) {
            method.setAccessible(true);
        }

        Object ret = method.invoke(methodReceiver, methodParamValues);

        if (!acc) {
            method.setAccessible(false);
        }

        return ret;
    }

    return null;
}
 
开发者ID:wangyupeng1-iri,项目名称:springreplugin,代码行数:22,代码来源:ReflectUtils.java

示例4: defineClass

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * 定义类
 *
 * @param loader         目标ClassLoader
 * @param javaClassName  类名称
 * @param classByteArray 类字节码数组
 * @return 定义的类
 * @throws InvocationTargetException 目标方法调用发生异常
 * @throws IllegalAccessException    目标方法不可进入
 */
public static Class<?> defineClass(final ClassLoader loader,
                                   final String javaClassName,
                                   final byte[] classByteArray) throws InvocationTargetException, IllegalAccessException {

    final Method defineClassMethod =
            unCaughtGetClassDeclaredJavaMethod(ClassLoader.class, "defineClass", String.class, byte[].class, int.class, int.class);

    synchronized (defineClassMethod) {
        final boolean acc = defineClassMethod.isAccessible();
        try {
            defineClassMethod.setAccessible(true);
            return (Class<?>) defineClassMethod.invoke(
                    loader,
                    javaClassName,
                    classByteArray,
                    0,
                    classByteArray.length
            );
        } finally {
            defineClassMethod.setAccessible(acc);
        }
    }

}
 
开发者ID:alibaba,项目名称:jvm-sandbox,代码行数:35,代码来源:SandboxReflectUtils.java

示例5: getValue

import java.lang.reflect.Method; //导入方法依赖的package包/类
public static Object getValue(Object object, Method method, Object... params) throws ReflectorException, IllegalAccessException {
    boolean originalAccessibility = method.isAccessible();
    method.setAccessible(true);

    try {
        Object value = null;

        if (params != null && params.length > 0) {
            value = method.invoke(object, params);
        } else {
            value = method.invoke(object);
        }

        return value;
    } catch (InvocationTargetException e) {
        throw new ReflectorException("Unable to invoke selected method.", e);
    } finally {
        method.setAccessible(originalAccessibility);
    }
}
 
开发者ID:iFanie,项目名称:ChocoPie,代码行数:21,代码来源:Reflector.java

示例6: findMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
private static Method findMethod(Object instance, String name, Class<?>... parameterTypes)
        throws NoSuchMethodException {
    for (Class<?> clazz = instance.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
        try {
            Method method = clazz.getDeclaredMethod(name, parameterTypes);


            if (!method.isAccessible()) {
                method.setAccessible(true);
            }

            return method;
        } catch (NoSuchMethodException e) {
            // ignore and search next
        }
    }

    throw new NoSuchMethodException("Method " + name + " with parameters " +
            Arrays.asList(parameterTypes) + " not found in " + instance.getClass());
}
 
开发者ID:coding-dream,项目名称:TPlayer,代码行数:21,代码来源:DelegateApplication64Bit.java

示例7: findMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Locates a given method anywhere in the class inheritance hierarchy.
 *
 * @param instance an object to search the method into.
 * @param name method name
 * @param parameterTypes method parameter types
 * @return a method object
 * @throws NoSuchMethodException if the method cannot be located
 */
private static Method findMethod(Object instance, String name, Class<?>... parameterTypes)
        throws NoSuchMethodException {
    for (Class<?> clazz = instance.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
        try {
            Method method = clazz.getDeclaredMethod(name, parameterTypes);


            if (!method.isAccessible()) {
                method.setAccessible(true);
            }

            return method;
        } catch (NoSuchMethodException e) {
            // ignore and search next
        }
    }

    throw new NoSuchMethodException("Method " + name + " with parameters " +
            parameterTypes + " not found in " + instance.getClass());
}
 
开发者ID:inferjay,项目名称:r8,代码行数:30,代码来源:MultiDex.java

示例8: makeOptionalFitsSystemWindows

import java.lang.reflect.Method; //导入方法依赖的package包/类
public static void makeOptionalFitsSystemWindows(View view) {
    if (VERSION.SDK_INT >= 16) {
        try {
            Method method = view.getClass().getMethod("makeOptionalFitsSystemWindows", new Class[0]);
            if (!method.isAccessible()) {
                method.setAccessible(true);
            }
            method.invoke(view, new Object[0]);
        } catch (NoSuchMethodException e) {
            Log.d(TAG, "Could not find method makeOptionalFitsSystemWindows. Oh well...");
        } catch (InvocationTargetException e2) {
            Log.d(TAG, "Could not invoke makeOptionalFitsSystemWindows", e2);
        } catch (IllegalAccessException e3) {
            Log.d(TAG, "Could not invoke makeOptionalFitsSystemWindows", e3);
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:18,代码来源:ViewUtils.java

示例9: setProperty

import java.lang.reflect.Method; //导入方法依赖的package包/类
static void setProperty(PropertyDescriptor pd, Object value, Object source)
        throws IllegalAccessException, InvocationTargetException, TransformException {
    if (pd != null && pd.getWriteMethod() != null) {
        Method m = pd.getWriteMethod();
        if (!m.isAccessible())
            m.setAccessible(true);
        Class tClass = m.getParameterTypes()[0];
        if (value == null || tClass.isAssignableFrom(value.getClass())) {
            m.invoke(source, new Object[]{value});
            if (log.isDebugEnabled())
                log.debug("Set property '" + pd.getName() + '=' + value + "' on object '" + source.getClass().getName() + '\'');
        } else if (DataTypeMapper.instance().isMappable(value.getClass(), tClass)) {
            // See if there is a datatype mapper for these classes
            value = DataTypeMapper.instance().map(value, tClass);
            m.invoke(source, new Object[]{value});
            if (log.isDebugEnabled())
                log.debug("Translate+Set property '" + pd.getName() + '=' + value + "' on object '" + source.getClass().getName() + '\'');
        } else {
            // Data type mismatch
            throw new TransformException(TransformException.DATATYPE_MISMATCH, source.getClass().getName() + '.' + m.getName(), tClass.getName(), value.getClass().getName());
        }
    } else {
        TransformException me = new TransformException(TransformException.NO_SETTER, null,
                pd == null ? "???" : pd.getName(), source.getClass().getName());
        log.error(me.getLocalizedMessage());
        throw me;
    }
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:29,代码来源:TransformerUtils.java

示例10: makeAccessible

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * 改变private/protected的方法为public,尽量不调用实际改动的语句,避免JDK的SecurityManager抱怨。
 */
public static void makeAccessible(Method method) {
	if ((!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers()))
			&& !method.isAccessible()) {
		method.setAccessible(true);
	}
}
 
开发者ID:zhangjunfang,项目名称:util,代码行数:10,代码来源:ClassUtil.java

示例11: getTreeItemForMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
private AssertionTreeItem getTreeItemForMethod(Object object, Method method) {
	boolean accessible = method.isAccessible();
	try {
		method.setAccessible(true);
		return new AssertionTreeItem(method.invoke(object, new Object[] {}), getPropertyName(method.getName()));
	} catch (Throwable t) {
	} finally {
		method.setAccessible(accessible);
	}
	return null;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:12,代码来源:AssertionTreeView.java

示例12: allMethodsThrowISE

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * All the methods of Disconnect should throw ISE.
 * @throws Exception If something goes wrong.
 */
@Test
public void allMethodsThrowISE() throws Exception {
    for(final Method method : Disconnected.class.getDeclaredMethods()) {
        try {
            if(!method.isAccessible()) {
                continue;
            }
            Object[] params = new Object[method.getParameterCount()];
            for(int i=0; i < method.getParameters().length; i++) {
                if(method.getParameters()[i].getType().equals(int.class)) {
                    params[i] = 0;
                } else if(method.getParameters()[i].getType().equals(boolean.class)) {
                    params[i] = false;
                } else {
                    params[i] = null;   
                }
            }
            method.invoke(new Disconnected(), params);
            Assert.fail("ISE should have been thrown by now!");
        } catch (final InvocationTargetException ex) {
            MatcherAssert.assertThat(
                ex.getCause().getMessage(),
                Matchers.equalTo(
                    "Not connected. Don't forget to "
                    + "get a connected instance by calling #connect()"
                )
            );
        }
    }
}
 
开发者ID:amihaiemil,项目名称:comdor,代码行数:35,代码来源:DisconnectedTestCase.java

示例13: makeAccessible

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * 改变private/protected的方法为public,尽量不调用实际改动的语句,避免JDK的SecurityManager抱怨。
 * @param method 要设置的方法
 */
public static void makeAccessible(Method method) {
	if ((!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers()))
			&& !method.isAccessible()) {
		method.setAccessible(true);
	}
}
 
开发者ID:javahaohao,项目名称:gen_code,代码行数:11,代码来源:AnalysisObject.java

示例14: invokeMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
protected Object invokeMethod(Method method, Object[] args) throws Throwable {
  try {
    if (!method.isAccessible()) {
      method.setAccessible(true);
    }
    return method.invoke(currentProxy.proxy, args);
  } catch (InvocationTargetException e) {
    throw e.getCause();
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:11,代码来源:RetryInvocationHandler.java

示例15: JavaMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
private JavaMethod(Method m) {
	super( m.getParameterTypes(), m.getModifiers() );
	this.method = m;
	try {
		if (!m.isAccessible())
			m.setAccessible(true);
	} catch (SecurityException s) {
	}
}
 
开发者ID:nekocode,项目名称:Hubs,代码行数:10,代码来源:JavaMethod.java


注:本文中的java.lang.reflect.Method.isAccessible方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。