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


Java Modifier类代码示例

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


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

示例1: isStaticallyNameable

import java.lang.reflect.Modifier; //导入依赖的package包/类
static boolean isStaticallyNameable(Class<?> cls) {
    if (cls == Object.class)
        return true;
    while (cls.isArray())
        cls = cls.getComponentType();
    if (cls.isPrimitive())
        return true;  // int[].class, for example
    if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
        return false;
    // could use VerifyAccess.isClassAccessible but the following is a safe approximation
    if (cls.getClassLoader() != Object.class.getClassLoader())
        return false;
    if (VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;
    if (!Modifier.isPublic(cls.getModifiers()))
        return false;
    for (Class<?> pkgcls : STATICALLY_INVOCABLE_PACKAGES) {
        if (VerifyAccess.isSamePackage(pkgcls, cls))
            return true;
    }
    return false;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:InvokerBytecodeGenerator.java

示例2: run

import java.lang.reflect.Modifier; //导入依赖的package包/类
public void run() throws Exception {
    boolean hasAccess = loader != null || hasAccess();
    try {
        proxyClass = Proxy.getProxyClass(loader, interfaces);
        if (!hasAccess) {
            throw new RuntimeException("should have no permission to create proxy class");
        }
    } catch (AccessControlException e) {
        if (hasAccess) {
            throw e;
        }
        if (e.getPermission().getClass() != RuntimePermission.class ||
                !e.getPermission().getName().equals("getClassLoader")) {
            throw e;
        }
        return;
    }

    if (Modifier.isPublic(proxyClass.getModifiers())) {
        throw new RuntimeException(proxyClass + " must be non-public");
    }
    newProxyInstance();
    newInstanceFromConstructor(proxyClass);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:NonPublicProxyClass.java

示例3: testPrivateConstructor

import java.lang.reflect.Modifier; //导入依赖的package包/类
@NoDriver
@Test(expectedExceptions = {AssertionError.class},
        expectedExceptionsMessageRegExp = "JsUtility is a static utility class that cannot be instantiated")
public void testPrivateConstructor() throws Throwable {
    
    Constructor<?>[] ctors;
    ctors = JsUtility.class.getDeclaredConstructors();
    assertEquals(ctors.length, 1, "JsUtility must have exactly one constructor");
    assertEquals(ctors[0].getModifiers() & Modifier.PRIVATE, Modifier.PRIVATE,
                    "JsUtility constructor must be private");
    assertEquals(ctors[0].getParameterTypes().length, 0, "JsUtility constructor must have no arguments");
    
    try {
        ctors[0].setAccessible(true);
        ctors[0].newInstance();
    } catch (InvocationTargetException e) {
        throw e.getCause();
    }
}
 
开发者ID:Nordstrom,项目名称:Selenium-Foundation,代码行数:20,代码来源:JsUtilityTest.java

示例4: mapping

import java.lang.reflect.Modifier; //导入依赖的package包/类
public static LuaTable mapping(Class<?> c) {
  try {
    LuaTable luaTable = new LuaTable();
    for (Field field : c.getFields()) {
      if (!Modifier.isStatic(field.getModifiers())) continue;
      if (LuaValue.class.isAssignableFrom(field.getType())) {
        luaTable.set(field.getName(), (LuaValue) field.get(null));
      }
      if (field.getType().equals(Class.class)) {
        luaTable.set(field.getName(), mapping((Class<?>) field.get(null)));
      }
    }
    return new ReadOnlyLuaTable(luaTable);
  } catch (Exception e) {
    throw new CubesException("Failed to create lua api", e);
  }
}
 
开发者ID:RedTroop,项目名称:Cubes,代码行数:18,代码来源:LuaMapping.java

示例5: getPrivateMethod

import java.lang.reflect.Modifier; //导入依赖的package包/类
/**
 * Returns non-static private method with given signature defined by given
 * class, or null if none found.  Access checks are disabled on the
 * returned method (if any).
 */
private static Method getPrivateMethod(Class<?> cl, String name,
                                       Class<?>[] argTypes,
                                       Class<?> returnType)
{
    try {
        Method meth = cl.getDeclaredMethod(name, argTypes);
        meth.setAccessible(true);
        int mods = meth.getModifiers();
        return ((meth.getReturnType() == returnType) &&
                ((mods & Modifier.STATIC) == 0) &&
                ((mods & Modifier.PRIVATE) != 0)) ? meth : null;
    } catch (NoSuchMethodException ex) {
        return null;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:ObjectStreamClass.java

示例6: getBeanPropertyFields

import java.lang.reflect.Modifier; //导入依赖的package包/类
public static Map<String, Field> getBeanPropertyFields(Class cl) {
    Map<String, Field> properties = new HashMap<String, Field>();
    for(; cl != null; cl = cl.getSuperclass()) {
        Field[] fields = cl.getDeclaredFields();
        for(Field field : fields) {
            if (Modifier.isTransient(field.getModifiers())
                || Modifier.isStatic(field.getModifiers())) {
                continue;
            }

            field.setAccessible(true);

            properties.put(field.getName(), field);
        }
    }

    return properties;
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:19,代码来源:ReflectUtils.java

示例7: resolve

import java.lang.reflect.Modifier; //导入依赖的package包/类
public String resolve(IObject obj) throws SnapshotException {
    StringBuilder r = new StringBuilder();
    ISnapshot snapshot = obj.getSnapshot();
    Object val = obj.resolveValue("modifiers");
    if (val instanceof Integer) {
        r.append(Modifier.toString(((Integer) val).intValue()));
        if (r.length() > 0) {
            r.append(' ');
        }
    }
    IObject ref = (IObject) obj.resolveValue("clazz");
    if (ref == null) {
        return null;
    }
    addClassName(snapshot, ref.getObjectAddress(), r);
    return r.toString();
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:18,代码来源:CommonNameResolver$AccessibleObjectResolver.java

示例8: setAccessibleWorkaround

import java.lang.reflect.Modifier; //导入依赖的package包/类
static boolean setAccessibleWorkaround(final AccessibleObject o) {
    if (o == null || o.isAccessible()) {
        return false;
    }
    final Member m = (Member) o;
    if (!o.isAccessible() && Modifier.isPublic(m.getModifiers()) && isPackageAccess(m
            .getDeclaringClass().getModifiers())) {
        try {
            o.setAccessible(true);
            return true;
        } catch (final SecurityException e) { // NOPMD
            // ignore in favor of subsequent IllegalAccessException
        }
    }
    return false;
}
 
开发者ID:zkwlx,项目名称:DroidTelescope,代码行数:17,代码来源:MemberUtils.java

示例9: createGenericKInstance

import java.lang.reflect.Modifier; //导入依赖的package包/类
/**
 * try to create Generic K instance
 *
 * @param z
 * @param view
 * @return
 */
@SuppressWarnings("unchecked")
private K createGenericKInstance(Class z, View view) {
    try {
        Constructor constructor;
        // inner and unstatic class
        if (z.isMemberClass() && !Modifier.isStatic(z.getModifiers())) {
            constructor = z.getDeclaredConstructor(getClass(), View.class);
            constructor.setAccessible(true);
            return (K) constructor.newInstance(this, view);
        } else {
            constructor = z.getDeclaredConstructor(View.class);
            constructor.setAccessible(true);
            return (K) constructor.newInstance(view);
        }
    } catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
        Timber.e(e);
    }
    return null;
}
 
开发者ID:alphater,项目名称:garras,代码行数:27,代码来源:BaseQuickAdapter.java

示例10: testPatchingPublic

import java.lang.reflect.Modifier; //导入依赖的package包/类
public void testPatchingPublic() throws Exception {
    Class<?> c = new L().loadClass(C.class.getName());
    assertNotSame(c, C.class);
    Member m;
    m = c.getDeclaredConstructor(boolean.class);
    assertEquals(0, m.getModifiers() & Modifier.PUBLIC);
    assertEquals(Modifier.PRIVATE, m.getModifiers() & Modifier.PRIVATE);
    m = c.getDeclaredConstructor(int.class);
    assertEquals(Modifier.PUBLIC, m.getModifiers() & Modifier.PUBLIC);
    assertEquals(0, m.getModifiers() & Modifier.PRIVATE);
    m = c.getDeclaredMethod("m1");
    assertEquals(0, m.getModifiers() & Modifier.PUBLIC);
    assertEquals(Modifier.PRIVATE, m.getModifiers() & Modifier.PRIVATE);
    m = c.getDeclaredMethod("m2");
    assertEquals(Modifier.PUBLIC, m.getModifiers() & Modifier.PUBLIC);
    assertEquals(0, m.getModifiers() & Modifier.PRIVATE);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:PatchByteCodeTest.java

示例11: buildGson

import java.lang.reflect.Modifier; //导入依赖的package包/类
public static Gson buildGson() {

        final GsonBuilder gson = new GsonBuilder();

        //gson.setPrettyPrinting();
        gson.serializeNulls();
        gson.excludeFieldsWithModifiers(Modifier.STATIC, Modifier.TRANSIENT, Modifier.VOLATILE);

        // register the type adapter factories
        final TypeAdapterFactoryCreator creator = new TypeAdapterFactoryCreator();
        for (final TypeAdapterFactory factory : creator.getAdapters()) {
            gson.registerTypeAdapterFactory(factory);
        }

        return gson.create();
    }
 
开发者ID:MikeFot,项目名称:Java--Steam-Loader,代码行数:17,代码来源:SteamGson.java

示例12: invoke

import java.lang.reflect.Modifier; //导入依赖的package包/类
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    try {
        if(method.getDeclaringClass()==Locatable.class)
            return method.invoke(this,args);
        if(Modifier.isStatic(method.getModifiers()))
            // malicious code can pass in a static Method object.
            // doing method.invoke() would end up executing it,
            // so we need to protect against it.
            throw new IllegalArgumentException();

        return method.invoke(core,args);
    } catch (InvocationTargetException e) {
        if(e.getTargetException()!=null)
            throw e.getTargetException();
        throw e;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:LocatableAnnotation.java

示例13: checkArgMatch

import java.lang.reflect.Modifier; //导入依赖的package包/类
private Map<String,String> checkArgMatch(Invocation v, Object[] args){
	Map<String, String> result = new HashMap<String, String>();
	String argsType[] = v.getArgsType();
	if(argsType == null || argsType.length == 0){
		return result;
	}
	Class<?> argClasses[] = v.getArgClasses();
	for(int i = 0; i < argsType.length; i++){
		if(args[i] == null || (argClasses != null && (argClasses[i].isPrimitive() || Modifier.isFinal(argClasses[i].getModifiers())))){
			continue;
		}
		Class<?> realClass = args[i].getClass();
		if(!argClasses[i].equals(realClass)){
    		String argType = ClassTypeUtils.getTypeStr(realClass);
			result.put(String.valueOf(i), argType);
		}
	}
	return result;
}
 
开发者ID:tiglabs,项目名称:jsf-sdk,代码行数:20,代码来源:InvocationTemplate.java

示例14: scan

import java.lang.reflect.Modifier; //导入依赖的package包/类
/**
 * Scans the fields in a class hierarchy.
 *
 * @param clazz the class at which to start scanning
 * @param endClazz scanning stops when this class is encountered (i.e. {@code endClazz} is not
 *            scanned)
 */
public void scan(Class<?> clazz, Class<?> endClazz, boolean includeTransient) {
    Class<?> currentClazz = clazz;
    while (currentClazz != endClazz) {
        for (Field field : currentClazz.getDeclaredFields()) {
            if (Modifier.isStatic(field.getModifiers())) {
                continue;
            }
            if (!includeTransient && Modifier.isTransient(field.getModifiers())) {
                continue;
            }
            long offset = calc.getOffset(field);
            scanField(field, offset);
        }
        currentClazz = currentClazz.getSuperclass();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:FieldsScanner.java

示例15: getFieldValue

import java.lang.reflect.Modifier; //导入依赖的package包/类
/**
 * Returns the value of the field with the specified name in the specified object instance.
 */
protected Object getFieldValue(Object obj, String fieldname) {
  Object value = null;

  if (obj != null && fieldname != null) {
    Field field = getField(obj, fieldname);

    try {
      if (field != null) {
        if (Modifier.isPublic(field.getModifiers())) {
          value = field.get(obj);
        } else {
          value = getFieldValueWithAccessor(obj, field);
        }
      }
    } catch (IllegalAccessException e1) {
      value = getFieldValueWithAccessor(obj, field);
    } catch (Exception e) {
      // ignore
    }
  }

  return value;
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:27,代码来源:mxObjectCodec.java


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