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


Java Method.setAccessible方法代码示例

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


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

示例1: getRSScriptCCreateMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
private Method getRSScriptCCreateMethod() {
    if (nScriptCCreate == null)

        try {
            Method method = RenderScript.class.getDeclaredMethod("nScriptCCreate", String.class, String.class, byte[].class, int.class);
            method.setAccessible(true);

            nScriptCCreate = method;

            return method;
        } catch (NoSuchMethodException e) {
            throw new RuntimeException("nScriptCCreate method does not exists");
        }

    return nScriptCCreate;
}
 
开发者ID:csarron,项目名称:renderscript_examples,代码行数:17,代码来源:RenderScriptHolder.java

示例2: convertActivityToTranslucentBeforeL

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Calling the convertToTranslucent method on platforms before Android 5.0
 */
public static void convertActivityToTranslucentBeforeL(Activity activity) {
    try {
        Class<?>[] classes = Activity.class.getDeclaredClasses();
        Class<?> translucentConversionListenerClazz = null;
        for (Class clazz : classes) {
            if (clazz.getSimpleName().contains("TranslucentConversionListener")) {
                translucentConversionListenerClazz = clazz;
            }
        }
        Method method = Activity.class.getDeclaredMethod("convertToTranslucent",
                translucentConversionListenerClazz);
        method.setAccessible(true);
        method.invoke(activity, new Object[] {
            null
        });
    } catch (Throwable t) {
    }
}
 
开发者ID:longtaoge,项目名称:SelectName,代码行数:22,代码来源:Utils.java

示例3: getAccessibleMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
public static Method getAccessibleMethod(final Class<?> cls, final String methodName,
                                         final Class<?>... parameterTypes) throws NoSuchMethodException {
    String key = getKey(cls, methodName, parameterTypes);
    Method method;
    synchronized (sMethodCache) {
        method = sMethodCache.get(key);
    }
    if (method != null) {
        if (!method.isAccessible()) {
            method.setAccessible(true);
        }
        return method;
    }

    Method accessibleMethod = getAccessibleMethod(cls.getMethod(methodName,
            parameterTypes));
    synchronized (sMethodCache) {
        sMethodCache.put(key, accessibleMethod);
    }
    return accessibleMethod;

}
 
开发者ID:amikey,项目名称:DroidPlugin,代码行数:23,代码来源:MethodUtils.java

示例4: validate

import java.lang.reflect.Method; //导入方法依赖的package包/类
private static void validate() throws Exception {
    Method getSelectedUIMethod = SynthLookAndFeel.class.getDeclaredMethod("getSelectedUI");

    getSelectedUIMethod.setAccessible(true);

    Method getSelectedUIStateMethod = SynthLookAndFeel.class.getDeclaredMethod("getSelectedUIState");

    getSelectedUIStateMethod.setAccessible(true);

    if (getSelectedUIMethod.invoke(null) != componentUI) {
        throw new RuntimeException("getSelectedUI returns invalid value");
    }
    if (((Integer) getSelectedUIStateMethod.invoke(null)).intValue() !=
            (SynthConstants.SELECTED | SynthConstants.FOCUSED)) {
        throw new RuntimeException("getSelectedUIState returns invalid value");
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:bug7143614.java

示例5: findMethodHierarchically

import java.lang.reflect.Method; //导入方法依赖的package包/类
public static Method findMethodHierarchically(final Class<?> clazz,
                                              final String name, final Class<?>... parameterTypes) {
    Method m = null;
    Class<?> c = clazz;
    do {
        try {
            m = c.getDeclaredMethod(name, parameterTypes);
        } catch (final NoSuchMethodException e) {
            c = c.getSuperclass();
            if (c == null)
                break;
        }
    } while (m == null);
    if (m != null) {
        m.setAccessible(true);
    } else {
        Log.e(AndHook.LOG_TAG, "failed to find method " + name
                + " of class " + clazz.getName());
    }
    return m;
}
 
开发者ID:rrrfff,项目名称:AndHook,代码行数:22,代码来源:AndHook.java

示例6: getBlPrompt

import java.lang.reflect.Method; //导入方法依赖的package包/类
private boolean getBlPrompt(String packet) {
    ByteArrayInputStream stream = new ByteArrayInputStream(packet.getBytes());
    ZigBeePort port = new TestPort(stream);
    EmberFirmwareUpdateHandler firmwareHandler = new EmberFirmwareUpdateHandler(null, null, port, null);

    Method privateMethod;
    try {
        privateMethod = EmberFirmwareUpdateHandler.class.getDeclaredMethod("getBlPrompt");
        privateMethod.setAccessible(true);

        return (boolean) privateMethod.invoke(firmwareHandler);
    } catch (NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException
            | InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return false;
}
 
开发者ID:zsmartsystems,项目名称:com.zsmartsystems.zigbee,代码行数:20,代码来源:EmberFirmwareUpdateHandlerTest.java

示例7: setScrollViewColor

import java.lang.reflect.Method; //导入方法依赖的package包/类
public void setScrollViewColor(ScrollView scr){
	try
	{
		Field mScrollCacheField = View.class.getDeclaredField("mScrollCache");
		mScrollCacheField.setAccessible(true);
		Object mScrollCache = mScrollCacheField.get(scr); // scr is your Scroll View

		Field scrollBarField = mScrollCache.getClass().getDeclaredField("scrollBar");
		scrollBarField.setAccessible(true);
		Object scrollBar = scrollBarField.get(mScrollCache);

		Method method = scrollBar.getClass().getDeclaredMethod("setVerticalThumbDrawable", Drawable.class);
		method.setAccessible(true);

		ColorDrawable ColorDraw = new ColorDrawable(getPrimaryColor());
		method.invoke(scrollBar, ColorDraw);
	} catch(Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:HoraApps,项目名称:Liz,代码行数:21,代码来源:ThemeHelper.java

示例8: force

import java.lang.reflect.Method; //导入方法依赖的package包/类
@Override
public void force() {
  try {
    final Method method = MappedByteBuffer.class.getDeclaredMethod("force0",
            FileDescriptor.class, long.class, long.class);
    method.setAccessible(true);
    method.invoke(super.state.getMappedByteBuffer(), super.state.getRandomAccessFile().getFD(),
            super.state.getNativeBaseOffset(), super.state.getCapacity());
  } catch (final Exception e) {
    throw new RuntimeException(String.format("Encountered %s exception in force", e.getClass()));
  }
}
 
开发者ID:DataSketches,项目名称:memory,代码行数:13,代码来源:AllocateDirectWritableMap.java

示例9: invokeMethodByClass

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Invokes the static method of the given clazz, name, paramTypes, params
 *
 * @param clazz      clazz
 * @param name       name
 * @param paramTypes paramTypes
 * @param params     params
 * @param <T>        returnType
 * @return returnValue
 * @throws NoSuchMethodException     exception
 * @throws InvocationTargetException exception
 * @throws IllegalAccessException    exception
 */
public static <T> T invokeMethodByClass(Class<?> clazz, String name, Class<?>[] paramTypes, Object[] params) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    if (clazz == null)
        throw new IllegalArgumentException("Class cannot be null!");
    if (name == null)
        throw new IllegalArgumentException("Name cannot be null!");
    if (paramTypes == null)
        throw new IllegalArgumentException("ParamTypes cannot be null");
    if (params == null)
        throw new IllegalArgumentException("Params cannot be null!");
    final Method method = clazz.getDeclaredMethod(name, paramTypes);
    method.setAccessible(true);
    return (T) method.invoke(null, params);
}
 
开发者ID:Shynixn,项目名称:AstralEdit,代码行数:27,代码来源:ReflectionUtils.java

示例10: invoke

import java.lang.reflect.Method; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static Object invoke(Class clazz, Object target, String name, Object... args)
        throws Exception {
    Class[] parameterTypes = null;
    if (args != null) {
        parameterTypes = new Class[args.length];
        for (int i = 0; i < args.length; i++) {
            parameterTypes[i] = args[i].getClass();
        }
    }

    Method method = clazz.getDeclaredMethod(name, parameterTypes);
    method.setAccessible(true);
    return method.invoke(target, args);
}
 
开发者ID:didi,项目名称:VirtualAPK,代码行数:16,代码来源:ReflectUtil.java

示例11: mapObject

import java.lang.reflect.Method; //导入方法依赖的package包/类
private Object mapObject(Object toConvert, int maxDepth, boolean skipNulls) throws Exception {
    if (maxDepth < 1) {
        return null;
    }

    // Raw object via reflection? Nope, not needed
    JSONObject mapped = new JSONObject();
    for (SimplePropertyDescriptor pd : SimplePropertyDescriptor.getPropertyDescriptors(toConvert.getClass())) {
        if ("class".equals(pd.getName())) {
            mapped.put("class", toConvert.getClass().getName());
            continue;
        }

        Method readMethod = pd.getReadMethod();
        if (readMethod == null) {
            continue;
        }

        if (readMethod.getParameterTypes().length > 0) {
            continue;
        }

        readMethod.setAccessible(true);

        Object result = readMethod.invoke(toConvert);
        result = convertObject(result, maxDepth - 1);
        if (!skipNulls || result != JSONObject.NULL) {
            mapped.put(pd.getName(), result);
        }
    }

    return mapped;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:34,代码来源:BeanToJsonConverter.java

示例12: setupReflectionStatics

import java.lang.reflect.Method; //导入方法依赖的package包/类
private static void setupReflectionStatics() throws Throwable {
    Class<?> liveStackFrameClass = Class.forName("java.lang.LiveStackFrame");
    primitiveValueClass = Class.forName("java.lang.LiveStackFrame$PrimitiveSlot");

    getLocals = liveStackFrameClass.getDeclaredMethod("getLocals");
    getLocals.setAccessible(true);

    longValue = primitiveValueClass.getDeclaredMethod("longValue");
    longValue.setAccessible(true);

    Class<?> stackFrameInfoClass = Class.forName("java.lang.StackFrameInfo");
    memberName = stackFrameInfoClass.getDeclaredField("memberName");
    memberName.setAccessible(true);
    offset = stackFrameInfoClass.getDeclaredField("bci");
    offset.setAccessible(true);
    getMethodType = Class.forName("java.lang.invoke.MemberName").getDeclaredMethod("getMethodType");
    getMethodType.setAccessible(true);

    Class<?> extendedOptionClass = Class.forName("java.lang.StackWalker$ExtendedOption");
    Method ewsNI = StackWalker.class.getDeclaredMethod("newInstance", Set.class, extendedOptionClass);
    ewsNI.setAccessible(true);
    Field f = extendedOptionClass.getDeclaredField("LOCALS_AND_OPERANDS");
    f.setAccessible(true);
    Object localsAndOperandsOption = f.get(null);

    primitiveSize = primitiveValueClass.getDeclaredMethod("size");
    primitiveSize.setAccessible(true);
    sw = (StackWalker) ewsNI.invoke(null, java.util.Collections.emptySet(), localsAndOperandsOption);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:LocalLongHelper.java

示例13: of

import java.lang.reflect.Method; //导入方法依赖的package包/类
public static ReflectiveProperty of(Method method, Inspectable.Inspect annotation) {
    if(method.getParameterTypes().length > 0) {
        throw new IllegalArgumentException("Can't inspect a method with parameters");
    }

    method.setAccessible(true);
    return new ReflectiveProperty(
        annotation.name().length() > 0 ? annotation.name()
                                       : Methods.removeBeanPrefix(method.getName()),
        TypeToken.of(method.getGenericReturnType()),
        new Inspection(annotation),
        MethodHandleUtils.privateUnreflect(method)
    );
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:15,代码来源:ReflectiveProperty.java

示例14: loadJarToClassPath

import java.lang.reflect.Method; //导入方法依赖的package包/类
private void loadJarToClassPath( File file ) throws IOException {
    URL url = file.toURI().toURL();
    ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
    try {
        Method method = URLClassLoader.class.getDeclaredMethod( "addURL", URL.class );
        if( !method.isAccessible() ) {
            method.setAccessible( true );
        }
        method.invoke( systemClassLoader, url );
    } catch ( NoSuchMethodException | InvocationTargetException | IllegalAccessException e ) {
        throw new RuntimeException( e );
    }
}
 
开发者ID:lukas81298,项目名称:FlexMC,代码行数:14,代码来源:LibraryManager.java

示例15: injectNativeLoader

import java.lang.reflect.Method; //导入方法依赖的package包/类
private static Class<?> injectNativeLoader() {
  try {
    ClassLoader e = getRootClassLoader();
    byte[] libLoaderByteCode = getByteCode("/com/mapr/fs/shim/LibraryLoader.bytecode");
    ArrayList preloadClassByteCode = new ArrayList(PRELOAD_CLASSES.length);
    String[] classLoader = PRELOAD_CLASSES;
    int defineClass = classLoader.length;

    for(int pd = 0; pd < defineClass; ++pd) {
      String ex = classLoader[pd];
      preloadClassByteCode.add(getByteCode(String.format("/%s.class", new Object[]{ex.replaceAll("\\.", "/")})));
    }

    Class var15 = Class.forName("java.lang.ClassLoader");
    Method var16 = var15.getDeclaredMethod("defineClass", new Class[]{String.class, byte[].class, Integer.TYPE, Integer.TYPE, ProtectionDomain.class});
    ProtectionDomain var17 = System.class.getProtectionDomain();
    var16.setAccessible(true);

    try {
      trace("injectNativeLoader: Loading MapR native classes", new Object[0]);
      var16.invoke(e, new Object[]{"com.mapr.fs.shim.LibraryLoader", libLoaderByteCode, Integer.valueOf(0), Integer.valueOf(libLoaderByteCode.length), var17});

      for(int var18 = 0; var18 < PRELOAD_CLASSES.length; ++var18) {
        byte[] b = (byte[])preloadClassByteCode.get(var18);
        var16.invoke(e, new Object[]{PRELOAD_CLASSES[var18], b, Integer.valueOf(0), Integer.valueOf(b.length), var17});
      }
    } catch (InvocationTargetException var12) {
      throw var12;
    } finally {
      var16.setAccessible(false);
    }

    return e.loadClass("com.mapr.fs.shim.LibraryLoader");
  } catch (Exception var14) {
    var14.printStackTrace(System.err);
    throw new RuntimeException("Failure loading MapRClient. ", var14);
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:39,代码来源:ShimLoader.java


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