java.lang.reflect.Modifier#isProtected ( )源码实例Demo

下面列出了java.lang.reflect.Modifier#isProtected ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-jdk9   文件: TypesParser.java
private static int getMethodFlags(Executable method) {
    int flags = FunctionInfo.NONE;
    int modifiers = method.getModifiers();
    if (Modifier.isAbstract(modifiers)) {
        flags |= FunctionInfo.ABSTRACT;
    }
    if (Modifier.isFinal(modifiers)) {
        flags |= FunctionInfo.FINAL;
    }
    if (Modifier.isPublic(modifiers)) {
        flags |= FunctionInfo.PUBLIC;
    } else if (Modifier.isProtected(modifiers)) {
        flags |= FunctionInfo.PROTECTED;
    } else if (Modifier.isPrivate(modifiers)) {
        flags |= FunctionInfo.PRIVATE;
    } else {
        flags |= FunctionInfo.DEFAULT;
    }
    if (Modifier.isStatic(modifiers)) {
        flags |= FunctionInfo.STATIC;
    }
    if (Modifier.isSynchronized(modifiers)) {
        flags |= FunctionInfo.SYNCHRONIZED;
    }
    return flags;
}
 
源代码2 项目: dhis2-core   文件: ReflectionUtils.java
@SuppressWarnings( "unchecked" )
public static <T> T invokeMethod( Object target, Method method, Object... args )
{
    if ( target == null || method == null )
    {
        return null;
    }

    if ( Modifier.isProtected( method.getModifiers() ) || Modifier.isPrivate( method.getModifiers() ) )
    {
        return null;
    }

    try
    {
        return (T) method.invoke( target, args );
    }
    catch ( InvocationTargetException | IllegalAccessException e )
    {
        throw new RuntimeException( e );
    }
}
 
源代码3 项目: lams   文件: Injection.java
/**
 * {@inheritDoc}
 */
public int compare(Method o1, Method o2)
{
   int m1 = o1.getModifiers();
   int m2 = o2.getModifiers();

   if (Modifier.isPublic(m1))
      return -1;

   if (Modifier.isPublic(m2))
      return 1;

   if (Modifier.isProtected(m1))
      return -1;

   if (Modifier.isProtected(m2))
      return 1;

   if (Modifier.isPrivate(m1))
      return -1;

   if (Modifier.isPrivate(m2))
      return 1;

   return 0;
}
 
源代码4 项目: iaf   文件: ApiTestBase.java
public void register(M jaxRsResource) {
	Method[] classMethods = jaxRsResource.getClass().getDeclaredMethods();
	for(Method classMethod : classMethods) {
		int modifiers = classMethod.getModifiers();
		if (Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers)) {
			Path path = AnnotationUtils.findAnnotation(classMethod, Path.class);
			HttpMethod httpMethod = AnnotationUtils.findAnnotation(classMethod, HttpMethod.class);
			if(path != null && httpMethod != null) {
				String rsResourceKey = compileKey(httpMethod.value(), path.value());

				System.out.println("adding new JAX-RS resource key ["+rsResourceKey+"] method ["+classMethod.getName()+"]");
				rsRequests.put(rsResourceKey, classMethod);
			}
			//Ignore security for now
		}
	}
}
 
源代码5 项目: xtext-extras   文件: ReflectionTypeFactory.java
protected void setVisibility(org.eclipse.xtext.common.types.JvmMember result, int modifiers) {
	if (Modifier.isPrivate(modifiers))
		result.setVisibility(JvmVisibility.PRIVATE);
	else if (Modifier.isProtected(modifiers))
		result.setVisibility(JvmVisibility.PROTECTED);
	else if (Modifier.isPublic(modifiers))
		result.setVisibility(JvmVisibility.PUBLIC);
	else
		result.setVisibility(JvmVisibility.DEFAULT);
}
 
源代码6 项目: j2objc   文件: AtomicLongFieldUpdater.java
CASUpdater(final Class<T> tclass, final String fieldName,
           final Class<?> caller) {
    final Field field;
    final int modifiers;
    try {
        field = tclass.getDeclaredField(fieldName); // android-changed
        modifiers = field.getModifiers();
        // BEGIN Android-removed
        // sun.reflect.misc.ReflectUtil.ensureMemberAccess(
        //     caller, tclass, null, modifiers);
        // ClassLoader cl = tclass.getClassLoader();
        // ClassLoader ccl = caller.getClassLoader();
        // if ((ccl != null) && (ccl != cl) &&
        //     ((cl == null) || !isAncestor(cl, ccl))) {
        //     sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
        // }
        // END Android-removed
    // BEGIN Android-removed
    // } catch (PrivilegedActionException pae) {
    //     throw new RuntimeException(pae.getException());
    // END Android-removed
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    if (field.getType() != long.class)
        throw new IllegalArgumentException("Must be long type");

    if (!Modifier.isVolatile(modifiers))
        throw new IllegalArgumentException("Must be volatile type");

    this.cclass = (Modifier.isProtected(modifiers)) ? caller : tclass;
    this.tclass = tclass;
    this.offset = U.objectFieldOffset(field);
}
 
源代码7 项目: openjdk-8   文件: AtomicIntegerFieldUpdater.java
AtomicIntegerFieldUpdaterImpl(final Class<T> tclass,
                              final String fieldName,
                              final Class<?> caller) {
    final Field field;
    final int modifiers;
    try {
        field = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Field>() {
                public Field run() throws NoSuchFieldException {
                    return tclass.getDeclaredField(fieldName);
                }
            });
        modifiers = field.getModifiers();
        sun.reflect.misc.ReflectUtil.ensureMemberAccess(
            caller, tclass, null, modifiers);
        ClassLoader cl = tclass.getClassLoader();
        ClassLoader ccl = caller.getClassLoader();
        if ((ccl != null) && (ccl != cl) &&
            ((cl == null) || !isAncestor(cl, ccl))) {
          sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
        }
    } catch (PrivilegedActionException pae) {
        throw new RuntimeException(pae.getException());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    Class<?> fieldt = field.getType();
    if (fieldt != int.class)
        throw new IllegalArgumentException("Must be integer type");

    if (!Modifier.isVolatile(modifiers))
        throw new IllegalArgumentException("Must be volatile type");

    this.cclass = (Modifier.isProtected(modifiers) &&
                   caller != tclass) ? caller : null;
    this.tclass = tclass;
    offset = unsafe.objectFieldOffset(field);
}
 
源代码8 项目: xtext-extras   文件: ReflectionTypeFactory.java
protected void setVisibility(Class<?> clazz, JvmMember result) {
	if (Modifier.isPrivate(clazz.getModifiers()))
		result.setVisibility(JvmVisibility.PRIVATE);
	else if (Modifier.isProtected(clazz.getModifiers()))
		result.setVisibility(JvmVisibility.PROTECTED);
	else if (Modifier.isPublic(clazz.getModifiers()))
		result.setVisibility(JvmVisibility.PUBLIC);
}
 
源代码9 项目: dolphin   文件: ClassUtils.java
private static boolean isOverridable(Method method, Class<?> targetClass) {
	if (Modifier.isPrivate(method.getModifiers())) {
		return false;
	}
	if (Modifier.isPublic(method.getModifiers()) || Modifier.isProtected(method.getModifiers())) {
		return true;
	}
	return getPackageName(method.getDeclaringClass()).equals(getPackageName(targetClass));
}
 
源代码10 项目: quarkus   文件: AbstractGenerator.java
protected boolean isReflectionFallbackNeeded(FieldInfo field, String targetPackage) {
    // Reflection fallback is needed for private fields and non-public fields declared on superclasses located in a different package
    if (Modifier.isPrivate(field.flags())) {
        return true;
    }
    if (Modifier.isProtected(field.flags()) || isPackagePrivate(field.flags())) {
        return !DotNames.packageName(field.declaringClass().name()).equals(targetPackage);
    }
    return false;
}
 
源代码11 项目: groovy   文件: AstToTextHelper.java
public static String getModifiersText(int modifiers) {
    StringBuilder result = new StringBuilder();
    if (Modifier.isPrivate(modifiers)) {
        result.append("private ");
    }
    if (Modifier.isProtected(modifiers)) {
        result.append("protected ");
    }
    if (Modifier.isPublic(modifiers)) {
        result.append("public ");
    }
    if (Modifier.isStatic(modifiers)) {
        result.append("static ");
    }
    if (Modifier.isAbstract(modifiers)) {
        result.append("abstract ");
    }
    if (Modifier.isFinal(modifiers)) {
        result.append("final ");
    }
    if (Modifier.isInterface(modifiers)) {
        result.append("interface ");
    }
    if (Modifier.isNative(modifiers)) {
        result.append("native ");
    }
    if (Modifier.isSynchronized(modifiers)) {
        result.append("synchronized ");
    }
    if (Modifier.isTransient(modifiers)) {
        result.append("transient ");
    }
    if (Modifier.isVolatile(modifiers)) {
        result.append("volatile ");
    }
    return result.toString().trim();
}
 
AtomicIntegerFieldUpdaterImpl(final Class<T> tclass,
                              final String fieldName,
                              final Class<?> caller) {
    final Field field;
    final int modifiers;
    try {
        field = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Field>() {
                public Field run() throws NoSuchFieldException {
                    return tclass.getDeclaredField(fieldName);
                }
            });
        modifiers = field.getModifiers();
        sun.reflect.misc.ReflectUtil.ensureMemberAccess(
            caller, tclass, null, modifiers);
        ClassLoader cl = tclass.getClassLoader();
        ClassLoader ccl = caller.getClassLoader();
        if ((ccl != null) && (ccl != cl) &&
            ((cl == null) || !isAncestor(cl, ccl))) {
          sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
        }
    } catch (PrivilegedActionException pae) {
        throw new RuntimeException(pae.getException());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    Class<?> fieldt = field.getType();
    if (fieldt != int.class)
        throw new IllegalArgumentException("Must be integer type");

    if (!Modifier.isVolatile(modifiers))
        throw new IllegalArgumentException("Must be volatile type");

    this.cclass = (Modifier.isProtected(modifiers) &&
                   caller != tclass) ? caller : null;
    this.tclass = tclass;
    offset = unsafe.objectFieldOffset(field);
}
 
源代码13 项目: baratine   文件: JConstructorWrapper.java
/**
 * Returns true for a protected method.
 */
public boolean isProtected()
{
  return Modifier.isProtected(_method.getModifiers());
}
 
@Override
public boolean isVisible(Field field) {
    return Modifier.isProtected(field.getModifiers());
}
 
源代码15 项目: jdk8u-jdk   文件: AtomicReferenceFieldUpdater.java
AtomicReferenceFieldUpdaterImpl(final Class<T> tclass,
                                final Class<V> vclass,
                                final String fieldName,
                                final Class<?> caller) {
    final Field field;
    final Class<?> fieldClass;
    final int modifiers;
    try {
        field = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Field>() {
                public Field run() throws NoSuchFieldException {
                    return tclass.getDeclaredField(fieldName);
                }
            });
        modifiers = field.getModifiers();
        sun.reflect.misc.ReflectUtil.ensureMemberAccess(
            caller, tclass, null, modifiers);
        ClassLoader cl = tclass.getClassLoader();
        ClassLoader ccl = caller.getClassLoader();
        if ((ccl != null) && (ccl != cl) &&
            ((cl == null) || !isAncestor(cl, ccl))) {
            sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
        }
        fieldClass = field.getType();
    } catch (PrivilegedActionException pae) {
        throw new RuntimeException(pae.getException());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    if (vclass != fieldClass)
        throw new ClassCastException();
    if (vclass.isPrimitive())
        throw new IllegalArgumentException("Must be reference type");

    if (!Modifier.isVolatile(modifiers))
        throw new IllegalArgumentException("Must be volatile type");

    // Access to protected field members is restricted to receivers only
    // of the accessing class, or one of its subclasses, and the
    // accessing class must in turn be a subclass (or package sibling)
    // of the protected member's defining class.
    // If the updater refers to a protected field of a declaring class
    // outside the current package, the receiver argument will be
    // narrowed to the type of the accessing class.
    this.cclass = (Modifier.isProtected(modifiers) &&
                   tclass.isAssignableFrom(caller) &&
                   !isSamePackage(tclass, caller))
                  ? caller : tclass;
    this.tclass = tclass;
    this.vclass = vclass;
    this.offset = U.objectFieldOffset(field);
}
 
源代码16 项目: jdk1.8-source-analysis   文件: MemberName.java
/** Utility method to query the modifier flags of this member. */
public boolean isProtected() {
    return Modifier.isProtected(flags);
}
 
LockedUpdater(final Class<T> tclass, final String fieldName,
              final Class<?> caller) {
    Field field = null;
    int modifiers = 0;
    try {
        field = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Field>() {
                public Field run() throws NoSuchFieldException {
                    return tclass.getDeclaredField(fieldName);
                }
            });
        modifiers = field.getModifiers();
        sun.reflect.misc.ReflectUtil.ensureMemberAccess(
            caller, tclass, null, modifiers);
        ClassLoader cl = tclass.getClassLoader();
        ClassLoader ccl = caller.getClassLoader();
        if ((ccl != null) && (ccl != cl) &&
            ((cl == null) || !isAncestor(cl, ccl))) {
            sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
        }
    } catch (PrivilegedActionException pae) {
        throw new RuntimeException(pae.getException());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    if (field.getType() != long.class)
        throw new IllegalArgumentException("Must be long type");

    if (!Modifier.isVolatile(modifiers))
        throw new IllegalArgumentException("Must be volatile type");

    // Access to protected field members is restricted to receivers only
    // of the accessing class, or one of its subclasses, and the
    // accessing class must in turn be a subclass (or package sibling)
    // of the protected member's defining class.
    // If the updater refers to a protected field of a declaring class
    // outside the current package, the receiver argument will be
    // narrowed to the type of the accessing class.
    this.cclass = (Modifier.isProtected(modifiers) &&
                   tclass.isAssignableFrom(caller) &&
                   !isSamePackage(tclass, caller))
                  ? caller : tclass;
    this.tclass = tclass;
    this.offset = U.objectFieldOffset(field);
}
 
源代码18 项目: openjdk-8   文件: AtomicReferenceFieldUpdater.java
AtomicReferenceFieldUpdaterImpl(final Class<T> tclass,
                                final Class<V> vclass,
                                final String fieldName,
                                final Class<?> caller) {
    final Field field;
    final Class<?> fieldClass;
    final int modifiers;
    try {
        field = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Field>() {
                public Field run() throws NoSuchFieldException {
                    return tclass.getDeclaredField(fieldName);
                }
            });
        modifiers = field.getModifiers();
        sun.reflect.misc.ReflectUtil.ensureMemberAccess(
            caller, tclass, null, modifiers);
        ClassLoader cl = tclass.getClassLoader();
        ClassLoader ccl = caller.getClassLoader();
        if ((ccl != null) && (ccl != cl) &&
            ((cl == null) || !isAncestor(cl, ccl))) {
          sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
        }
        fieldClass = field.getType();
    } catch (PrivilegedActionException pae) {
        throw new RuntimeException(pae.getException());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    if (vclass != fieldClass)
        throw new ClassCastException();

    if (!Modifier.isVolatile(modifiers))
        throw new IllegalArgumentException("Must be volatile type");

    this.cclass = (Modifier.isProtected(modifiers) &&
                   caller != tclass) ? caller : null;
    this.tclass = tclass;
    if (vclass == Object.class)
        this.vclass = null;
    else
        this.vclass = vclass;
    offset = unsafe.objectFieldOffset(field);
}
 
源代码19 项目: Bytecoder   文件: AtomicIntegerFieldUpdater.java
AtomicIntegerFieldUpdaterImpl(final Class<T> tclass,
                              final String fieldName,
                              final Class<?> caller) {
    final Field field;
    final int modifiers;
    try {
        field = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Field>() {
                public Field run() throws NoSuchFieldException {
                    return tclass.getDeclaredField(fieldName);
                }
            });
        modifiers = field.getModifiers();
        sun.reflect.misc.ReflectUtil.ensureMemberAccess(
            caller, tclass, null, modifiers);
        ClassLoader cl = tclass.getClassLoader();
        ClassLoader ccl = caller.getClassLoader();
        if ((ccl != null) && (ccl != cl) &&
            ((cl == null) || !isAncestor(cl, ccl))) {
            sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
        }
    } catch (PrivilegedActionException pae) {
        throw new RuntimeException(pae.getException());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    if (field.getType() != int.class)
        throw new IllegalArgumentException("Must be integer type");

    if (!Modifier.isVolatile(modifiers))
        throw new IllegalArgumentException("Must be volatile type");

    // Access to protected field members is restricted to receivers only
    // of the accessing class, or one of its subclasses, and the
    // accessing class must in turn be a subclass (or package sibling)
    // of the protected member's defining class.
    // If the updater refers to a protected field of a declaring class
    // outside the current package, the receiver argument will be
    // narrowed to the type of the accessing class.
    this.cclass = (Modifier.isProtected(modifiers) &&
                   tclass.isAssignableFrom(caller) &&
                   !isSamePackage(tclass, caller))
                  ? caller : tclass;
    this.tclass = tclass;
    this.offset = U.objectFieldOffset(field);
}
 
源代码20 项目: brooklyn-server   文件: ReflectionPredicates.java
@Override public boolean apply(Integer modifiers) { return Modifier.isProtected(modifiers); }