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

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

源代码1 项目: dremio-oss   文件: ConnectionReaderImpl.java
/**
 * Returns a collection of candidate sources -- i.e., any class that has the @SourceType annotation
 */
protected static Collection<Class<? extends ConnectionConf<?, ?>>> getCandidateSources(ScanResult scanResult) {
  ImmutableList.Builder<Class<? extends ConnectionConf<?, ?>>> candidates = new ImmutableList.Builder<>();
  for(Class<?> input : scanResult.getAnnotatedClasses(SourceType.class)) {
    try {
      if (Modifier.isAbstract(input.getModifiers())
        || Modifier.isInterface(input.getModifiers())
        || !ConnectionConf.class.isAssignableFrom(input)) {
        logger.warn("Failure trying to recognize SourceConf for {}. Expected a concrete implementation of SourceConf.", input.getName());
        continue;
      }
    } catch (Exception e) {
      logger.warn("Failure trying to recognize SourceConf for {}", input.getName(), e);
      continue;
    }
    // Check done just above
    candidates.add((Class<? extends ConnectionConf<?, ?>>) input);
  }
  return candidates.build();
}
 
private void emitSuperCall(final InstructionAdapter mv, final Class<?> owner, final String name, final String methodDesc) {
    mv.visitVarInsn(ALOAD, 0);
    int nextParam = 1;
    final Type methodType = Type.getMethodType(methodDesc);
    for(final Type t: methodType.getArgumentTypes()) {
        mv.load(nextParam, t);
        nextParam += t.getSize();
    }

    // default method - non-abstract, interface method
    if (Modifier.isInterface(owner.getModifiers())) {
        // we should call default method on the immediate "super" type - not on (possibly)
        // the indirectly inherited interface class!
        mv.invokespecial(Type.getInternalName(findInvokespecialOwnerFor(owner)), name, methodDesc, false);
    } else {
        mv.invokespecial(superClassName, name, methodDesc, false);
    }
    mv.areturn(methodType.getReturnType());
}
 
private void emitSuperCall(final InstructionAdapter mv, final Class<?> owner, final String name, final String methodDesc) {
    mv.visitVarInsn(ALOAD, 0);
    int nextParam = 1;
    final Type methodType = Type.getMethodType(methodDesc);
    for(final Type t: methodType.getArgumentTypes()) {
        mv.load(nextParam, t);
        nextParam += t.getSize();
    }

    // default method - non-abstract, interface method
    if (Modifier.isInterface(owner.getModifiers())) {
        // we should call default method on the immediate "super" type - not on (possibly)
        // the indirectly inherited interface class!
        mv.invokespecial(Type.getInternalName(findInvokespecialOwnerFor(owner)), name, methodDesc, false);
    } else {
        mv.invokespecial(superClassName, name, methodDesc, false);
    }
    mv.areturn(methodType.getReturnType());
}
 
源代码4 项目: android-classyshark   文件: JavaTranslator.java
private static void fillClassDecl(MetaObject.InterfaceInfo[] interfaces,
                                  MetaObject metaObject,
                                  List<ELEMENT> words,
                                  QualifiedTypesMap namesMapper) {
    MetaObject.AnnotationInfo[] annotations = metaObject.getAnnotations();
    for (MetaObject.AnnotationInfo annot : annotations) {
        words.add(new ELEMENT("@" + annot.annotationStr + " \n", TAG.ANNOTATION));
    }

    int mod = metaObject.getModifiers();
    words.add(new ELEMENT(Modifier.toString(mod), TAG.MODIFIER));

    if (!Modifier.isInterface(mod)) {
        words.add(new ELEMENT(" class", TAG.MODIFIER));
    }

    words.add(new ELEMENT(" " + namesMapper.getTypeNull(metaObject.getName()),
            TAG.IDENTIFIER));
    words.add(new ELEMENT(metaObject.getClassGenerics(metaObject.getName()),
            TAG.IDENTIFIER));

    if (metaObject.getSuperclass() != null) {
        words.add(new ELEMENT(" extends ", TAG.MODIFIER));
        words.add(new ELEMENT(namesMapper.getType(metaObject.getSuperclass()),
                TAG.IDENTIFIER));
        words.add(new ELEMENT(metaObject.getSuperclassGenerics(), TAG.IDENTIFIER));
    }

    if (interfaces.length != 0) {
        words.add(new ELEMENT(" implements ", TAG.MODIFIER));
        for (MetaObject.InterfaceInfo iface : interfaces) {
            words.add(new ELEMENT(namesMapper.getType(iface.interfaceStr),
                    TAG.IDENTIFIER));
            words.add(new ELEMENT(iface.genericsStr, TAG.IDENTIFIER));
            words.add(new ELEMENT(", ", TAG.IDENTIFIER));
        }
        words.remove(words.size() - 1);
    }
    words.add(new ELEMENT("\n{", TAG.IDENTIFIER));
}
 
源代码5 项目: Flink-CEPplus   文件: KryoSerializer.java
@Override
public T createInstance() {
	if(Modifier.isAbstract(type.getModifiers()) || Modifier.isInterface(type.getModifiers()) ) {
		return null;
	} else {
		checkKryoInitialized();
		try {
			return kryo.newInstance(type);
		} catch(Throwable e) {
			return null;
		}
	}
}
 
源代码6 项目: openjdk-jdk9   文件: Introspector.java
/**
 * Basic method for testing that a MBean of a given class can be
 * instantiated by the MBean server.<p>
 * This method checks that:
 * <ul><li>The given class is a concrete class.</li>
 *     <li>The given class exposes at least one public constructor.</li>
 * </ul>
 * If these conditions are not met, throws a NotCompliantMBeanException.
 * @param c The class of the MBean we want to create.
 * @exception NotCompliantMBeanException if the MBean class makes it
 *            impossible to instantiate the MBean from within the
 *            MBeanServer.
 *
 **/
public static void testCreation(Class<?> c)
    throws NotCompliantMBeanException {
    // Check if the class is a concrete class
    final int mods = c.getModifiers();
    if (Modifier.isAbstract(mods) || Modifier.isInterface(mods)) {
        throw new NotCompliantMBeanException("MBean class must be concrete");
    }

    // Check if the MBean has a public constructor
    final Constructor<?>[] consList = c.getConstructors();
    if (consList.length == 0) {
        throw new NotCompliantMBeanException("MBean class must have public constructor");
    }
}
 
源代码7 项目: jdk1.8-source-analysis   文件: Introspector.java
/**
 * Basic method for testing that a MBean of a given class can be
 * instantiated by the MBean server.<p>
 * This method checks that:
 * <ul><li>The given class is a concrete class.</li>
 *     <li>The given class exposes at least one public constructor.</li>
 * </ul>
 * If these conditions are not met, throws a NotCompliantMBeanException.
 * @param c The class of the MBean we want to create.
 * @exception NotCompliantMBeanException if the MBean class makes it
 *            impossible to instantiate the MBean from within the
 *            MBeanServer.
 *
 **/
public static void testCreation(Class<?> c)
    throws NotCompliantMBeanException {
    // Check if the class is a concrete class
    final int mods = c.getModifiers();
    if (Modifier.isAbstract(mods) || Modifier.isInterface(mods)) {
        throw new NotCompliantMBeanException("MBean class must be concrete");
    }

    // Check if the MBean has a public constructor
    final Constructor<?>[] consList = c.getConstructors();
    if (consList.length == 0) {
        throw new NotCompliantMBeanException("MBean class must have public constructor");
    }
}
 
源代码8 项目: openjdk-jdk8u   文件: Introspector.java
/**
 * Basic method for testing that a MBean of a given class can be
 * instantiated by the MBean server.<p>
 * This method checks that:
 * <ul><li>The given class is a concrete class.</li>
 *     <li>The given class exposes at least one public constructor.</li>
 * </ul>
 * If these conditions are not met, throws a NotCompliantMBeanException.
 * @param c The class of the MBean we want to create.
 * @exception NotCompliantMBeanException if the MBean class makes it
 *            impossible to instantiate the MBean from within the
 *            MBeanServer.
 *
 **/
public static void testCreation(Class<?> c)
    throws NotCompliantMBeanException {
    // Check if the class is a concrete class
    final int mods = c.getModifiers();
    if (Modifier.isAbstract(mods) || Modifier.isInterface(mods)) {
        throw new NotCompliantMBeanException("MBean class must be concrete");
    }

    // Check if the MBean has a public constructor
    final Constructor<?>[] consList = c.getConstructors();
    if (consList.length == 0) {
        throw new NotCompliantMBeanException("MBean class must have public constructor");
    }
}
 
源代码9 项目: sagetv   文件: UnsafeAllocator.java
/**
 * Check if the class can be instantiated by unsafe allocator. If the instance has interface or abstract modifiers
 * throw an {@link java.lang.UnsupportedOperationException}
 * @param c instance of the class to be checked
 */
private static void assertInstantiable(Class<?> c) {
  int modifiers = c.getModifiers();
  if (Modifier.isInterface(modifiers)) {
    throw new UnsupportedOperationException("Interface can't be instantiated! Interface name: " + c.getName());
  }
  if (Modifier.isAbstract(modifiers)) {
    throw new UnsupportedOperationException("Abstract class can't be instantiated! Class name: " + c.getName());
  }
}
 
源代码10 项目: openjdk-jdk8u-backup   文件: Introspector.java
/**
 * Basic method for testing that a MBean of a given class can be
 * instantiated by the MBean server.<p>
 * This method checks that:
 * <ul><li>The given class is a concrete class.</li>
 *     <li>The given class exposes at least one public constructor.</li>
 * </ul>
 * If these conditions are not met, throws a NotCompliantMBeanException.
 * @param c The class of the MBean we want to create.
 * @exception NotCompliantMBeanException if the MBean class makes it
 *            impossible to instantiate the MBean from within the
 *            MBeanServer.
 *
 **/
public static void testCreation(Class<?> c)
    throws NotCompliantMBeanException {
    // Check if the class is a concrete class
    final int mods = c.getModifiers();
    if (Modifier.isAbstract(mods) || Modifier.isInterface(mods)) {
        throw new NotCompliantMBeanException("MBean class must be concrete");
    }

    // Check if the MBean has a public constructor
    final Constructor<?>[] consList = c.getConstructors();
    if (consList.length == 0) {
        throw new NotCompliantMBeanException("MBean class must have public constructor");
    }
}
 
源代码11 项目: openjdk-8   文件: ClassDocImpl.java
/**
 * Return true if this is a class, not an interface.
 */
@Override
public boolean isClass() {
    return !Modifier.isInterface(getModifiers());
}
 
源代码12 项目: arthas   文件: StringUtils.java
/**
 * 翻译Modifier值
 *
 * @param mod modifier
 * @return 翻译值
 */
public static String modifier(int mod, char splitter) {
    StringBuilder sb = new StringBuilder();
    if (Modifier.isAbstract(mod)) {
        sb.append("abstract").append(splitter);
    }
    if (Modifier.isFinal(mod)) {
        sb.append("final").append(splitter);
    }
    if (Modifier.isInterface(mod)) {
        sb.append("interface").append(splitter);
    }
    if (Modifier.isNative(mod)) {
        sb.append("native").append(splitter);
    }
    if (Modifier.isPrivate(mod)) {
        sb.append("private").append(splitter);
    }
    if (Modifier.isProtected(mod)) {
        sb.append("protected").append(splitter);
    }
    if (Modifier.isPublic(mod)) {
        sb.append("public").append(splitter);
    }
    if (Modifier.isStatic(mod)) {
        sb.append("static").append(splitter);
    }
    if (Modifier.isStrict(mod)) {
        sb.append("strict").append(splitter);
    }
    if (Modifier.isSynchronized(mod)) {
        sb.append("synchronized").append(splitter);
    }
    if (Modifier.isTransient(mod)) {
        sb.append("transient").append(splitter);
    }
    if (Modifier.isVolatile(mod)) {
        sb.append("volatile").append(splitter);
    }
    if (sb.length() > 0) {
        sb.deleteCharAt(sb.length() - 1);
    }
    return sb.toString();
}
 
private boolean isInterfaceOrObjectClass(Class type) {
    return Modifier.isInterface(type.getModifiers()) || type.equals(Object.class);
}
 
源代码14 项目: pushfish-android   文件: ModelRuleInspector.java
/**
 * Validates that the given class is effectively static and has no instance state.
 *
 * @param source the class the validate
 */
public void validate(Class<?> source) throws InvalidModelRuleDeclarationException {

    // TODO - exceptions thrown here should point to some extensive documentation on the concept of class rule sources

    int modifiers = source.getModifiers();

    if (Modifier.isInterface(modifiers)) {
        throw invalid(source, "must be a class, not an interface");
    }
    if (Modifier.isAbstract(modifiers)) {
        throw invalid(source, "class cannot be abstract");
    }

    if (source.getEnclosingClass() != null) {
        if (Modifier.isStatic(modifiers)) {
            if (Modifier.isPrivate(modifiers)) {
                throw invalid(source, "class cannot be private");
            }
        } else {
            throw invalid(source, "enclosed classes must be static and non private");
        }
    }

    Class<?> superclass = source.getSuperclass();
    if (!superclass.equals(Object.class)) {
        throw invalid(source, "cannot have superclass");
    }

    Constructor<?>[] constructors = source.getDeclaredConstructors();
    if (constructors.length > 1) {
        throw invalid(source, "cannot have more than one constructor");
    }

    Constructor<?> constructor = constructors[0];
    if (constructor.getParameterTypes().length > 0) {
        throw invalid(source, "constructor cannot take any arguments");
    }

    Field[] fields = source.getDeclaredFields();
    for (Field field : fields) {
        int fieldModifiers = field.getModifiers();
        if (!field.isSynthetic() && !(Modifier.isStatic(fieldModifiers) && Modifier.isFinal(fieldModifiers))) {
            throw invalid(source, "field " + field.getName() + " is not static final");
        }
    }

}
 
源代码15 项目: simple-robot-core   文件: BaseApplication.java
/**
 * 使用一个Class来指定启动器。
 * 如果这个类存在{@link SimpleRobotApplication}注解,则以注解信息为主。
 * 如果不存在,则判断是否为{@link Application}接口的子类。如果是,尝试实例化,否则抛出异常。
 * @param appClass 启动类
 * @param args      参数
 */
public CONTEXT run(Class<?> appClass, String... args){
    SimpleRobotApplication applicationAnno = AnnotationUtils.getAnnotation(appClass, SimpleRobotApplication.class);
    if(applicationAnno == null){
        int modifiers = appClass.getModifiers();
        // interface or abstract
        if(Modifier.isInterface(modifiers) || Modifier.isAbstract(modifiers)){
            throw new RobotRunException(1, appClass + "can not be a simple-robot-application: cannot found @SimpleRobotApplication, and is an interface class or an Abstract class.");
        }
        // is child ?
        if(FieldUtils.isChild(appClass, Application.class)){
            // yes, child.
            try {
                Application<CONFIG> newInstance = (Application<CONFIG>) appClass.newInstance();
                return run(newInstance, args);
            } catch (Exception e) {
                throw new RobotRunException(1, appClass + "can not be a simple-robot-application: cannot get newInstance.", e);
            }
        }else{
            throw new RobotRunException(1, appClass + "can not be a simple-robot-application: cannot found @SimpleRobotApplication, and not implement Application interface.");

        }
    }else{
        // has annotation
        Class<?> application = applicationAnno.application();
        if(application.equals(Application.class)){
            application = appClass;
        }

        // get configuration
        SimpleRobotConfiguration configAnnotation = AnnotationUtils.getAnnotation(appClass, SimpleRobotConfiguration.class);
        CONFIG conf = getConf();
        Class<CONFIG> confClass = (Class<CONFIG>) conf.getClass();

        AutoResourceApplication<CONFIG> autoResourceApplication = AutoResourceApplication.autoConfig(confClass, applicationAnno, configAnnotation, application);

        // 正常启动
        return run(autoResourceApplication, args);
    }

}
 
源代码16 项目: PATDroid   文件: ClassInfo.java
/**
 * @return if the class is an interface
 */
public boolean isInterface() {
    return Modifier.isInterface(mutableDetail.accessFlags);
}
 
源代码17 项目: kogito-runtimes   文件: ClassUtils.java
public static boolean isInterface(Class<?> clazz) {
    return Modifier.isInterface( clazz.getModifiers() );
}
 
源代码18 项目: glowroot   文件: AnalyzedClass.java
boolean isInterface() {
    return Modifier.isInterface(modifiers());
}
 
源代码19 项目: ignite   文件: GridUriDeploymentFileProcessor.java
/**
 * Check that class may be instantiated as {@link org.apache.ignite.compute.ComputeTask} and used
 * in deployment.
 *
 * Loaded task class must implement interface {@link org.apache.ignite.compute.ComputeTask}.
 * Only non-abstract, non-interfaces and public classes allowed.
 * Inner static classes also allowed for loading.
 *
 * @param cls Class to check
 * @return {@code true} if class allowed for deployment.
 */
private static boolean isAllowedTaskClass(Class<?> cls) {
    if (!ComputeTask.class.isAssignableFrom(cls))
        return false;

    int modifiers = cls.getModifiers();

    return !Modifier.isAbstract(modifiers) && !Modifier.isInterface(modifiers) &&
        (!cls.isMemberClass() || Modifier.isStatic(modifiers)) && Modifier.isPublic(modifiers);
}
 
源代码20 项目: Taira   文件: ReflectionUtils.java
/**
 * check interface or abstract class
 *
 * @return true if abstract or interface
 */
static boolean isInterfaceOrAbstract(Class clazz) {
    return clazz != null && (Modifier.isAbstract(clazz.getModifiers()) || Modifier.isInterface(
        clazz.getModifiers()));
}