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


Java Modifier.isPublic方法代码示例

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


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

示例1: findConstructor

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
/**
 * Finds public constructor
 * that is declared in public class.
 *
 * @param type  the class that can have constructor
 * @param args  parameter types that is used to find constructor
 * @return object that represents found constructor
 * @throws NoSuchMethodException if constructor could not be found
 *                               or some constructors are found
 */
public static Constructor<?> findConstructor(Class<?> type, Class<?>...args) throws NoSuchMethodException {
    if (type.isPrimitive()) {
        throw new NoSuchMethodException("Primitive wrapper does not contain constructors");
    }
    if (type.isInterface()) {
        throw new NoSuchMethodException("Interface does not contain constructors");
    }
    if (Modifier.isAbstract(type.getModifiers())) {
        throw new NoSuchMethodException("Abstract class cannot be instantiated");
    }
    if (!Modifier.isPublic(type.getModifiers()) || !isPackageAccessible(type)) {
        throw new NoSuchMethodException("Class is not accessible");
    }
    PrimitiveWrapperMap.replacePrimitivesWithWrappers(args);
    Signature signature = new Signature(type, args);

    try {
        return CACHE.get(signature);
    }
    catch (SignatureException exception) {
        throw exception.toNoSuchMethodException("Constructor is not found");
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:34,代码来源:ConstructorFinder.java

示例2: getCollectionItemClass

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
public static Class<?> getCollectionItemClass(Type fieldType){
    if(fieldType instanceof ParameterizedType){
        Class<?> itemClass;
        Type actualTypeArgument = ((ParameterizedType) fieldType).getActualTypeArguments()[0];
        if(actualTypeArgument instanceof WildcardType){
            WildcardType wildcardType = (WildcardType) actualTypeArgument;
            Type[] upperBounds = wildcardType.getUpperBounds();
            if(upperBounds.length == 1){
                actualTypeArgument = upperBounds[0];
            }
        }
        if(actualTypeArgument instanceof Class){
            itemClass = (Class<?>) actualTypeArgument;
            if(!Modifier.isPublic(itemClass.getModifiers())){
                throw new JSONException("can not create ASMParser");
            }
        } else{
            throw new JSONException("can not create ASMParser");
        }
        return itemClass;
    }
    return Object.class;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:TypeUtils.java

示例3: isMXBeanInterface

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
/**
 * <p>Test whether an interface is an MXBean interface.
 * An interface is an MXBean interface if it is public,
 * annotated {@link MXBean &#64;MXBean} or {@code @MXBean(true)}
 * or if it does not have an {@code @MXBean} annotation
 * and its name ends with "{@code MXBean}".</p>
 *
 * @param interfaceClass The candidate interface.
 *
 * @return true if {@code interfaceClass} is a
 * {@link javax.management.MXBean compliant MXBean interface}
 *
 * @throws NullPointerException if {@code interfaceClass} is null.
 */
public static boolean isMXBeanInterface(Class<?> interfaceClass) {
    if (!interfaceClass.isInterface())
        return false;
    if (!Modifier.isPublic(interfaceClass.getModifiers()) &&
        !Introspector.ALLOW_NONPUBLIC_MBEAN) {
        return false;
    }
    MXBean a = interfaceClass.getAnnotation(MXBean.class);
    if (a != null)
        return a.value();
    return interfaceClass.getName().endsWith("MXBean");
    // We don't bother excluding the case where the name is
    // exactly the string "MXBean" since that would mean there
    // was no package name, which is pretty unlikely in practice.
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:30,代码来源:JMX.java

示例4: JSJavaScriptEngine

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
protected JSJavaScriptEngine(boolean debug) {
    this.debug = debug;
  ScriptEngineManager manager = new ScriptEngineManager();
  engine = manager.getEngineByName("javascript");
  if (engine == null) {
    throw new RuntimeException("can't load JavaScript engine");
  }
  Method[] methods = getClass().getMethods();
  for (int i = 0; i < methods.length; i++) {
    Method m = methods[i];
    if (! Modifier.isPublic(m.getModifiers())) {
      continue;
    }
    Class[] argTypes = m.getParameterTypes();
    if (argTypes.length == 1 &&
        argTypes[0] == Object[].class) {
      putFunction(this, m);
    }
  }
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:21,代码来源:JSJavaScriptEngine.java

示例5: complexToLua

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
public static LuaValue complexToLua(Object o) {
	try {
		Class<?> c = o.getClass();
		Field[] fields = c.getFields();
		LuaTable table = new LuaTable();
		for (Field field : fields) {
			if (!(Modifier.isPublic(field.getModifiers()) || field.isAnnotationPresent(LuaInclude.class))
					|| field.isAnnotationPresent(LuaExclude.class))
				continue;
			String name = field.getName();
			Class<?> type = field.getType();
			Object instance = field.get(o);
			LuaValue l = convertToLua(instance);
			table.set(name, l);
		}
		return table;
	} catch (Exception e) {
		Log.warning(e);
	}
	return NIL;
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:22,代码来源:LuaConversion.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: isBeanPropertyReadMethod

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
public static boolean isBeanPropertyReadMethod(Method method) {
    return method != null
            && Modifier.isPublic(method.getModifiers())
            && !Modifier.isStatic(method.getModifiers())
            && method.getReturnType() != void.class
            && method.getDeclaringClass() != Object.class
            && method.getParameterTypes().length == 0
            && ((method.getName().startsWith("get") && method.getName()
            .length() > 3) || (method.getName().startsWith("is") && method
            .getName().length() > 2));
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:12,代码来源:ReflectUtils.java

示例8: doClone

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
private Object doClone(Object value) throws Exception {
    if (value!=null) {
        Class vClass = value.getClass();
        if (vClass.isArray()) {
            value = cloneArray(value);
        }
        else
        if (value instanceof Collection) {
            value = cloneCollection((Collection)value);
        }
        else
        if (value instanceof Map) {
            value = cloneMap((Map)value);
        }
        else
        if (isBasicType(vClass)) {
            // NOTHING SPECIAL TO DO HERE, THEY ARE INMUTABLE
        }
        else
        if (value instanceof Cloneable) {
            Method cloneMethod = vClass.getMethod("clone",NO_PARAMS_DEF);
            if (Modifier.isPublic(cloneMethod.getModifiers())) {
               value = cloneMethod.invoke(value,NO_PARAMS);
            }
            else {
                throw new CloneNotSupportedException("Cannot clone a "+value.getClass()+" object, clone() is not public");
            }
        }
        else {
            throw new CloneNotSupportedException("Cannot clone a "+vClass.getName()+" object");
        }
    }
    return value;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:35,代码来源:CloneableBean.java

示例9: ClassDescription

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
public ClassDescription(Class value) {
    this.simpleName = value.getSimpleName();
    this.name = value.getSimpleName();
    this.className = value.getName();
    if (value.getSuperclass() != null) {
        this.extend = value.getSuperclass().getName();
    }
    this.packageName = JavaUtil.getPackageName(className);
    this.lastUsed = 0;


    constructors = new ArrayList<>();
    fields = new ArrayList<>();
    methods = new ArrayList<>();

    for (Constructor constructor : value.getConstructors()) {
        if (Modifier.isPublic(constructor.getModifiers())) {
            addConstructor(new ConstructorDescription(constructor));
        }
    }
    for (Field field : value.getDeclaredFields()) {
        if (Modifier.isPublic(field.getModifiers())) {
            if (!field.getName().equals(field.getDeclaringClass().getName())) {
                addField(new FieldDescription(field));
            }
        }
    }
    for (Method method : value.getMethods()) {
        if (Modifier.isPublic(method.getModifiers())) {
            addMethod(new MethodDescription(method));
        }
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:34,代码来源:ClassDescription.java

示例10: getCollectionItemClass

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
private Class<?> getCollectionItemClass(Type fieldType) {
    if (!(fieldType instanceof ParameterizedType)) {
        return Object.class;
    }
    Type actualTypeArgument = ((ParameterizedType) fieldType).getActualTypeArguments()[0];
    if (actualTypeArgument instanceof Class) {
        Class<?> cls = (Class) actualTypeArgument;
        if (Modifier.isPublic(cls.getModifiers())) {
            return cls;
        }
        throw new ASMException("can not create ASMParser");
    }
    throw new ASMException("can not create ASMParser");
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:15,代码来源:ASMDeserializerFactory.java

示例11: validateConstraint

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
private void validateConstraint(ObjectType constraint) {
  if (constraint == null)
    throw new IllegalArgumentException(
        LocalizedStrings.ResultsCollectionWrapper_CONSTRAINT_CANNOT_BE_NULL.toLocalizedString());
  // must be public
  if (!Modifier.isPublic(constraint.resolveClass().getModifiers()))
    throw new IllegalArgumentException(
        LocalizedStrings.ResultsCollectionWrapper_CONSTRAINT_CLASS_MUST_BE_PUBLIC
            .toLocalizedString());
}
 
开发者ID:ampool,项目名称:monarch,代码行数:11,代码来源:ResultsCollectionWrapper.java

示例12: getAccessibleMethodFromInterfaceNest

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
private static Method getAccessibleMethodFromInterfaceNest(Class<?> cls,
                                                           final String methodName, final Class<?>... parameterTypes) {
    // Search up the superclass chain
    for (; cls != null; cls = cls.getSuperclass()) {

        // Check the implemented interfaces of the parent class
        final Class<?>[] interfaces = cls.getInterfaces();
        for (int i = 0; i < interfaces.length; i++) {
            // Is this interface public?
            if (!Modifier.isPublic(interfaces[i].getModifiers())) {
                continue;
            }
            // Does the method exist on this interface?
            try {
                return interfaces[i].getDeclaredMethod(methodName,
                        parameterTypes);
            } catch (final NoSuchMethodException e) { // NOPMD
                /*
                 * Swallow, if no method is found after the loop then this
                 * method returns null.
                 */
            }
            // Recursively check our parent interfaces
            Method method = getAccessibleMethodFromInterfaceNest(interfaces[i],
                    methodName, parameterTypes);
            if (method != null) {
                return method;
            }
        }
    }
    return null;
}
 
开发者ID:amikey,项目名称:DroidPlugin,代码行数:33,代码来源:MethodUtils.java

示例13: 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:amikey,项目名称:DroidPlugin,代码行数:16,代码来源:MemberUtils.java

示例14: _createInstance

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
private void _createInstance(Context context, MethodVisitor mw) {
    if (Modifier.isPublic(context.getBeanInfo().getDefaultConstructor().getModifiers())) {
        mw.visitTypeInsn(187, ASMUtils.getType(context.getClazz()));
        mw.visitInsn(89);
        mw.visitMethodInsn(183, ASMUtils.getType(context.getClazz()), "<init>", "()V");
        mw.visitVarInsn(58, context.var("instance"));
        return;
    }
    mw.visitVarInsn(25, 0);
    mw.visitVarInsn(25, 1);
    mw.visitMethodInsn(183, "com/alibaba/fastjson/parser/deserializer/ASMJavaBeanDeserializer", "createInstance", "(Lcom/alibaba/fastjson/parser/DefaultJSONParser;)Ljava/lang/Object;");
    mw.visitTypeInsn(192, ASMUtils.getType(context.getClazz()));
    mw.visitVarInsn(58, context.var("instance"));
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:15,代码来源:ASMDeserializerFactory.java

示例15: toStringImpl

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
/**
 * Provides the implementation of the toString() method. <p>
 *
 * @return a String representation of this object
 * @throws Exception if a reflection error occurs
 */
private String toStringImpl() throws Exception {

    StringBuffer sb;
    Method[]     methods;
    Method       method;
    int          count;

    sb = new StringBuffer();

    sb.append(super.toString());

    count = getParameterCount();

    if (count == 0) {
        sb.append("[parameterCount=0]");

        return sb.toString();
    }
    methods = getClass().getDeclaredMethods();

    sb.append('[');

    int len = methods.length;

    for (int i = 0; i < count; i++) {
        sb.append('\n');
        sb.append("    parameter_");
        sb.append(i + 1);
        sb.append('=');
        sb.append('[');

        for (int j = 0; j < len; j++) {
            method = methods[j];

            if (!Modifier.isPublic(method.getModifiers())) {
                continue;
            }

            if (method.getParameterTypes().length != 1) {
                continue;
            }
            sb.append(method.getName());
            sb.append('=');
            sb.append(method.invoke(this,
                                    new Object[] { Integer.valueOf(i + 1) }));

            if (j + 1 < len) {
                sb.append(',');
                sb.append(' ');
            }
        }
        sb.append(']');

        if (i + 1 < count) {
            sb.append(',');
            sb.append(' ');
        }
    }
    sb.append('\n');
    sb.append(']');

    return sb.toString();
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:70,代码来源:JDBCParameterMetaData.java


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