當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。