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


Java Modifier.isProtected方法代码示例

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


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

示例1: contract

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
/**
 * 
 * @param cls
 * @param ignoreAnnotation
 * @return
 */
protected ClassInfo contract(Class<?> cls, boolean ignoreAnnotation) {
    if (ignoreAnnotation) {
        ClassInfo<?> ci = new ClassInfo();
        ci.setCls(cls);
        ci.setClassType(ClassInfo.ClassType.INTERFACE);

        Method[] methods = cls.getDeclaredMethods();
        List<ClassInfo.MethodInfo> methodInfos = new ArrayList<ClassInfo.MethodInfo>();

        for (Method m : methods) {
            if (Modifier.isPublic(m.getModifiers()) || Modifier.isProtected(m.getModifiers())) {
                ClassInfo.MethodInfo mi = new ClassInfo.MethodInfo();
                mi.setMethod(m);
                methodInfos.add(mi);
            }
        }
        ci.setMethodList(methodInfos);

        return ci;
    } else {
        return contract(cls);
    }
}
 
开发者ID:lemonJun,项目名称:TakinRPC,代码行数:30,代码来源:Scaner.java

示例2: accessFailedMessage

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
String accessFailedMessage(Class<?> refc, MemberName m) {
    Class<?> defc = m.getDeclaringClass();
    int mods = m.getModifiers();
    // check the class first:
    boolean classOK = (Modifier.isPublic(defc.getModifiers()) &&
                       (defc == refc ||
                        Modifier.isPublic(refc.getModifiers())));
    if (!classOK && (allowedModes & PACKAGE) != 0) {
        classOK = (VerifyAccess.isClassAccessible(defc, lookupClass(), FULL_POWER_MODES) &&
                   (defc == refc ||
                    VerifyAccess.isClassAccessible(refc, lookupClass(), FULL_POWER_MODES)));
    }
    if (!classOK)
        return "class is not public";
    if (Modifier.isPublic(mods))
        return "access to public member failed";  // (how?, module not readable?)
    if (Modifier.isPrivate(mods))
        return "member is private";
    if (Modifier.isProtected(mods))
        return "member is protected";
    return "member is private to package";
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:MethodHandles.java

示例3: isOverridable

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
/**
 * Determine whether the given method is overridable in the given target class.
 * @param method the method to check
 * @param targetClass the target class to check against
 */
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));
}
 
开发者ID:Yoio,项目名称:X4J,代码行数:15,代码来源:ClassUtils.java

示例4: modifier

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
private static String modifier(int mod)
{
	if( Modifier.isPublic(mod) ) return "public";
	if( Modifier.isProtected(mod) ) return "protected";
	if( Modifier.isPrivate(mod) ) return "private";
	return "";
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:8,代码来源:ClassGenerator.java

示例5: keepPublicConcreteClasses

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
private static void keepPublicConcreteClasses(final List classes) {
    if (null != classes) {
        final Iterator<Class> itr = classes.iterator();
        while (itr.hasNext()) {
            final Class clazz = itr.next();
            if (null != clazz) {
                final int modifiers = clazz.getModifiers();
                if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers) || Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers)) {
                    itr.remove();
                }
            }
        }
    }
}
 
开发者ID:gchq,项目名称:gaffer-doc,代码行数:15,代码来源:ExampleDocRunner.java

示例6: overrides

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
/**
 * Returns true if a overrides b. Assumes signatures of a and b are the same and a's declaring
 * class is a subclass of b's declaring class.
 */
private static boolean overrides(Method a, Method b) {
  // See JLS section 8.4.8.1
  int modifiers = b.getModifiers();
  if (Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers)) {
    return true;
  }
  if (Modifier.isPrivate(modifiers)) {
    return false;
  }
  // b must be package-private
  return a.getDeclaringClass().getPackage().equals(b.getDeclaringClass().getPackage());
}
 
开发者ID:maetrive,项目名称:businessworks,代码行数:17,代码来源:InjectionPoint.java

示例7: getReplaceResolveForSerialization

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
/**
 * Lookup readResolve or writeReplace on a class with specified
 * signature constraints.
 * @param cl a serializable class
 * @param methodName the method name to find
 * @returns a MethodHandle for the method or {@code null} if not found or
 *       has the wrong signature.
 */
private MethodHandle getReplaceResolveForSerialization(Class<?> cl,
                                                       String methodName) {
    if (!Serializable.class.isAssignableFrom(cl)) {
        return null;
    }

    Class<?> defCl = cl;
    while (defCl != null) {
        try {
            Method m = defCl.getDeclaredMethod(methodName);
            if (m.getReturnType() != Object.class) {
                return null;
            }
            int mods = m.getModifiers();
            if (Modifier.isStatic(mods) | Modifier.isAbstract(mods)) {
                return null;
            } else if (Modifier.isPublic(mods) | Modifier.isProtected(mods)) {
                // fall through
            } else if (Modifier.isPrivate(mods) && (cl != defCl)) {
                return null;
            } else if (!packageEquals(cl, defCl)) {
                return null;
            }
            try {
                // Normal return
                m.setAccessible(true);
                return MethodHandles.lookup().unreflect(m);
            } catch (IllegalAccessException ex0) {
                // setAccessible should prevent IAE
                throw new InternalError("Error", ex0);
            }
        } catch (NoSuchMethodException ex) {
            defCl = defCl.getSuperclass();
        }
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:46,代码来源:ReflectionFactory.java

示例8: ensureMemberAccess

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
public static void ensureMemberAccess(Class<?> currentClass,
                                      Class<?> memberClass,
                                      Object target,
                                      int modifiers)
    throws IllegalAccessException
{
    if (target == null && Modifier.isProtected(modifiers)) {
        int mods = modifiers;
        mods = mods & (~Modifier.PROTECTED);
        mods = mods | Modifier.PUBLIC;

        /*
         * See if we fail because of class modifiers
         */
        Reflection.ensureMemberAccess(currentClass,
                                      memberClass,
                                      target,
                                      mods);
        try {
            /*
             * We're still here so class access was ok.
             * Now try with default field access.
             */
            mods = mods & (~Modifier.PUBLIC);
            Reflection.ensureMemberAccess(currentClass,
                                          memberClass,
                                          target,
                                          mods);
            /*
             * We're still here so access is ok without
             * checking for protected.
             */
            return;
        } catch (IllegalAccessException e) {
            /*
             * Access failed but we're 'protected' so
             * if the test below succeeds then we're ok.
             */
            if (isSubclassOf(currentClass, memberClass)) {
                return;
            } else {
                throw e;
            }
        }
    } else {
        Reflection.ensureMemberAccess(currentClass,
                                      memberClass,
                                      target,
                                      modifiers);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:52,代码来源:ReflectUtil.java

示例9: AtomicReferenceFieldUpdaterImpl

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
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");

    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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:48,代码来源:AtomicReferenceFieldUpdater.java

示例10: isPackagePrivate

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
private static boolean isPackagePrivate(int modifiers) {
    return !Modifier.isPrivate(modifiers) && !Modifier.isProtected(modifiers) && !Modifier.isPublic(modifiers);
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:4,代码来源:DependencyInjectingInstantiator.java

示例11: checkAccess

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
/** Check public/protected/private bits on the symbolic reference class and its member. */
void checkAccess(byte refKind, Class<?> refc, MemberName m) throws IllegalAccessException {
    assert(m.referenceKindIsConsistentWith(refKind) &&
           MethodHandleNatives.refKindIsValid(refKind) &&
           (MethodHandleNatives.refKindIsField(refKind) == m.isField()));
    int allowedModes = this.allowedModes;
    if (allowedModes == TRUSTED)  return;
    int mods = m.getModifiers();
    if (Modifier.isProtected(mods) &&
            refKind == REF_invokeVirtual &&
            m.getDeclaringClass() == Object.class &&
            m.getName().equals("clone") &&
            refc.isArray()) {
        // The JVM does this hack also.
        // (See ClassVerifier::verify_invoke_instructions
        // and LinkResolver::check_method_accessability.)
        // Because the JVM does not allow separate methods on array types,
        // there is no separate method for int[].clone.
        // All arrays simply inherit Object.clone.
        // But for access checking logic, we make Object.clone
        // (normally protected) appear to be public.
        // Later on, when the DirectMethodHandle is created,
        // its leading argument will be restricted to the
        // requested array type.
        // N.B. The return type is not adjusted, because
        // that is *not* the bytecode behavior.
        mods ^= Modifier.PROTECTED | Modifier.PUBLIC;
    }
    if (Modifier.isProtected(mods) && refKind == REF_newInvokeSpecial) {
        // cannot "new" a protected ctor in a different package
        mods ^= Modifier.PROTECTED;
    }
    if (Modifier.isFinal(mods) &&
            MethodHandleNatives.refKindIsSetter(refKind))
        throw m.makeAccessException("unexpected set of a final field", this);
    int requestedModes = fixmods(mods);  // adjust 0 => PACKAGE
    if ((requestedModes & allowedModes) != 0) {
        if (VerifyAccess.isMemberAccessible(refc, m.getDeclaringClass(),
                                            mods, lookupClass(), allowedModes))
            return;
    } else {
        // Protected members can also be checked as if they were package-private.
        if ((requestedModes & PROTECTED) != 0 && (allowedModes & PACKAGE) != 0
                && VerifyAccess.isSamePackage(m.getDeclaringClass(), lookupClass()))
            return;
    }
    throw m.makeAccessException(accessFailedMessage(refc, m), this);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:49,代码来源:MethodHandles.java

示例12: isProtectedInstanceField

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
private boolean isProtectedInstanceField(Field field) {
    int modifiers = field.getModifiers();
    return !Modifier.isStatic(modifiers) && Modifier.isProtected(modifiers);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:5,代码来源:AbstractDependencyInjectionSpringContextTests.java

示例13: AtomicIntegerFieldUpdaterImpl

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:48,代码来源:AtomicIntegerFieldUpdater.java

示例14: includeField

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
/**
 * Returns true if fields with {@code modifiers} are included in the emitted JSON.
 */
@SuppressWarnings("SimplifiableIfStatement")
private boolean includeField(boolean platformType, int modifiers) {
    if (Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers)) return false;
    return Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers) || !platformType;
}
 
开发者ID:pCloud,项目名称:pcloud-networking-java,代码行数:9,代码来源:ClassTypeAdapterFactory.java

示例15: CASUpdater

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
CASUpdater(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() != 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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:47,代码来源:AtomicLongFieldUpdater.java


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