Example usage for java.lang Class isAnnotation

List of usage examples for java.lang Class isAnnotation

Introduction

In this page you can find the example usage for java.lang Class isAnnotation.

Prototype

public boolean isAnnotation() 

Source Link

Document

Returns true if this Class object represents an annotation type.

Usage

From source file:adalid.core.XS1.java

private static boolean isRestrictedFieldType(Class<?> fieldType) {
    int modifiers = fieldType.getModifiers();
    boolean b = fieldType.isPrimitive();
    b |= Modifier.isAbstract(modifiers) || !Modifier.isPublic(modifiers);
    b |= fieldType.isAnnotation();
    b |= fieldType.isAnonymousClass();//w w w  . ja  va  2 s  .  c  o  m
    b |= fieldType.isArray();
    b |= fieldType.isEnum();
    b |= fieldType.isLocalClass();
    b |= fieldType.isInterface();
    return b;
}

From source file:hwolf.spring.boot.servlet.ClassPathScanner.java

@SuppressWarnings("unchecked")
private ClassPathScanningCandidateComponentProvider buildClassPathScanner() {

    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(
            false);//  w  w w  . ja va  2s.  co  m
    for (Class<?> type : types) {
        if (type.isAnnotation()) {
            if (debug) {
                LOGGER.debug("Search for classes annotated with " + type);
            }
            scanner.addIncludeFilter(new AnnotationTypeFilter((Class<Annotation>) type));
        } else {
            if (debug) {
                LOGGER.debug("Search for classes assignable to " + type);
            }
            scanner.addIncludeFilter(new AssignableTypeFilter(type));
        }
    }
    return scanner;
}

From source file:org.brekka.stillingar.spring.config.AnnotationConfigBeanDefinitionParser.java

@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    String serviceRef = element.getAttribute("service-ref");
    builder.addConstructorArgValue(":" + serviceRef);
    builder.addConstructorArgReference(serviceRef);
    String marker = element.getAttribute("marker");
    if (StringUtils.hasLength(marker)) {
        Class<?> theClass = ClassUtils.resolveClassName(marker, Thread.currentThread().getContextClassLoader());
        if (!theClass.isAnnotation()) {
            throw new ConfigurationException(String.format("The class '%s' is not an annotation", marker));
        }/*from  w w w .j  ava2 s . co m*/
        builder.addPropertyValue("markerAnnotation", theClass);
    }
}

From source file:de.alpharogroup.lang.ClassExtensions.java

/**
 * Gets the {@link ClassType} from the given class.
 *
 * @param clazz//from w w w . j a  va 2 s  . com
 *            The class.
 * @return the {@link ClassType} from the given class.
 */
public static ClassType getClassType(final Class<?> clazz) {
    if (clazz.isArray()) {
        return ClassType.ARRAY;
    }
    if (isCollection(clazz)) {
        return ClassType.COLLECTION;
    }
    if (isMap(clazz)) {
        return ClassType.MAP;
    }
    if (clazz.isLocalClass()) {
        return ClassType.LOCAL;
    }
    if (clazz.isMemberClass()) {
        return ClassType.MEMBER;
    }
    if (clazz.isPrimitive()) {
        return ClassType.PRIMITIVE;
    }
    if (clazz.isAnnotation()) {
        return ClassType.ANNOTATION;
    }
    if (clazz.isEnum()) {
        return ClassType.ENUM;
    }
    if (clazz.isInterface()) {
        return ClassType.INTERFACE;
    }
    if (clazz.isSynthetic()) {
        return ClassType.SYNTHETIC;
    }
    if (clazz.isAnonymousClass()) {
        return ClassType.ANONYMOUS;
    }
    return ClassType.DEFAULT;
}

From source file:com.manydesigns.elements.annotations.AnnotationsManager.java

public void addAnnotationMapping(String annotationName, String annotationImplName) {
    logger.debug("Mapping annotation {} to implemetation {}", annotationName, annotationImplName);
    Class annotationClass = ReflectionUtil.loadClass(annotationName);
    if (annotationClass == null) {
        logger.warn("Failed to load annotation class: {}", annotationName);
        return;/*www. j  a v a 2s. c o m*/
    }
    if (!annotationClass.isAnnotation()) {
        logger.warn("Not an annotation: {}", annotationName);
        return;
    }
    Class annotationImplClass = ReflectionUtil.loadClass(annotationImplName);
    if (annotationImplClass == null) {
        logger.warn("Failed to load annotation implementation class: {}", annotationImplName);
        return;
    }
    if (!Arrays.asList(annotationImplClass.getInterfaces()).contains(annotationClass)) {
        logger.warn("Class {} not an implementation of {}", annotationImplName, annotationName);
        return;
    }

    annotationClassMap.put(annotationClass, annotationImplClass);
    logger.debug("Mapped annotation {} to implementation {}", annotationName, annotationImplName);

}

From source file:org.zalando.stups.spring.cloud.netflix.feign.OAuth2FeignClientsRegsitrar.java

protected ClassPathScanningCandidateComponentProvider getScanner() {
    return new ClassPathScanningCandidateComponentProvider(false) {

        @Override//from   ww w  .  j  a v  a  2 s .  c om
        protected boolean isCandidateComponent(final AnnotatedBeanDefinition beanDefinition) {
            if (beanDefinition.getMetadata().isIndependent()) {

                // TODO until SPR-11711 will be resolved
                if (beanDefinition.getMetadata().isInterface()
                        && beanDefinition.getMetadata().getInterfaceNames().length == 1 && Annotation.class
                                .getName().equals(beanDefinition.getMetadata().getInterfaceNames()[0])) {
                    try {
                        Class<?> target = ClassUtils.forName(beanDefinition.getMetadata().getClassName(),
                                OAuth2FeignClientsRegsitrar.this.classLoader);
                        return !target.isAnnotation();
                    } catch (Exception ex) {
                        this.logger.error(
                                "Could not load target class: " + beanDefinition.getMetadata().getClassName(),
                                ex);

                    }
                }

                return true;
            }

            return false;

        }
    };
}

From source file:com.eviware.soapui.plugins.LoaderBase.java

protected void loadAutoFactories(Reflections jarFileScanner, Collection<SoapUIFactory> factories) {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.addUrls(ClasspathHelper.forClass(AutoFactory.class));
    builder.setScanners(new SubTypesScanner(), new TypeAnnotationsScanner());
    builder.addClassLoader(Thread.currentThread().getContextClassLoader());
    Reflections autoAnnotationFinder = new Reflections(builder);

    for (Class clazz : autoAnnotationFinder.getTypesAnnotatedWith(AutoFactory.class)) {
        if (clazz.isAnnotation() && clazz.getSimpleName().startsWith("Plugin")) {
            try {
                String className = "Auto" + clazz.getSimpleName().substring(6) + "Factory";
                Class<? extends SoapUIFactory> factoryClass = (Class<? extends SoapUIFactory>) Class
                        .forName(clazz.getPackage().getName() + ".factories." + className);
                factories.addAll(findAutoFactoryObjects(jarFileScanner, clazz, factoryClass));
            } catch (ClassNotFoundException e) {
                SoapUI.logError(e);/*from  w  ww . java2s. c  o m*/
            }
        }
    }
}

From source file:com.feilong.core.lang.ClassUtilTest.java

/**
 *  class info map for LOGGER.//  w  ww  .  j a va2s  . c o m
 *
 * @param klass
 *            the klass
 * @return  <code>klass</code> nullempty, {@link Collections#emptyMap()}<br>
 */
public static Map<String, Object> getClassInfoMapForLog(Class<?> klass) {
    if (isNullOrEmpty(klass)) {
        return Collections.emptyMap();
    }

    Map<String, Object> map = new LinkedHashMap<String, Object>();

    map.put("clz.getCanonicalName()", klass.getCanonicalName());//"com.feilong.core.date.DatePattern"
    map.put("clz.getName()", klass.getName());//"com.feilong.core.date.DatePattern"
    map.put("clz.getSimpleName()", klass.getSimpleName());//"DatePattern"

    map.put("clz.getComponentType()", klass.getComponentType());
    // ?"". ,voidboolean?byte?char?short?int?long?float  double?.
    map.put("clz.isPrimitive()", klass.isPrimitive());

    // ?"".,.
    map.put("clz.isLocalClass()", klass.isLocalClass());
    // ?"?".?,?,?"""??".
    map.put("clz.isMemberClass()", klass.isMemberClass());

    //isSynthetic()?Class?"??".java??false,?true.,JVM???,java??"??"?
    map.put("clz.isSynthetic()", klass.isSynthetic());
    map.put("clz.isArray()", klass.isArray());
    map.put("clz.isAnnotation()", klass.isAnnotation());

    //??true.
    map.put("clz.isAnonymousClass()", klass.isAnonymousClass());
    map.put("clz.isEnum()", klass.isEnum());

    return map;
}

From source file:hu.bme.mit.sette.common.validator.reflection.ClassValidator.java

/**
 * Sets the required type for the Java class.
 *
 * @param type//from w  w  w  .j  av  a2s. c om
 *            the required type for the Java class.
 * @return this object
 */
public ClassValidator type(final ClassType type) {
    Validate.notNull(type, "The type must not be null");

    if (getSubject() != null) {
        Class<?> javaClass = getSubject();
        boolean isTypeValid = false;

        switch (type) {
        case CLASS:
            isTypeValid = !javaClass.isInterface() && !javaClass.isEnum() && !javaClass.isAnnotation()
                    && !javaClass.isPrimitive() && !javaClass.isArray();
            break;

        case REGULAR_CLASS:
            isTypeValid = !javaClass.isInterface() && !javaClass.isEnum() && !javaClass.isAnnotation()
                    && !javaClass.isPrimitive() && !javaClass.isArray() && !javaClass.isMemberClass()
                    && !javaClass.isAnonymousClass() && !javaClass.isLocalClass();
            break;

        case MEMBER_CLASS:
            isTypeValid = !javaClass.isInterface() && !javaClass.isEnum() && !javaClass.isAnnotation()
                    && !javaClass.isPrimitive() && !javaClass.isArray() && javaClass.isMemberClass();
            break;

        case ANONYMOUS_CLASS:
            isTypeValid = !javaClass.isInterface() && !javaClass.isEnum() && !javaClass.isAnnotation()
                    && !javaClass.isPrimitive() && !javaClass.isArray() && javaClass.isAnonymousClass();
            break;

        case LOCAL_CLASS:
            isTypeValid = !javaClass.isInterface() && !javaClass.isEnum() && !javaClass.isAnnotation()
                    && !javaClass.isPrimitive() && !javaClass.isArray() && javaClass.isLocalClass();
            break;

        case INTERFACE:
            isTypeValid = javaClass.isInterface();
            break;

        case REGULAR_INTERFACE:
            isTypeValid = javaClass.isInterface() && !javaClass.isMemberClass();
            break;

        case MEMBER_INTERFACE:
            isTypeValid = javaClass.isInterface() && javaClass.isMemberClass();
            break;

        case ENUM:
            isTypeValid = javaClass.isEnum();
            break;

        case REGULAR_ENUM:
            isTypeValid = javaClass.isEnum() && !javaClass.isMemberClass();
            break;

        case MEMBER_ENUM:
            isTypeValid = javaClass.isEnum() && javaClass.isMemberClass();
            break;

        case ANNOTATION:
            isTypeValid = javaClass.isAnnotation();
            break;

        case REGULAR_ANNOTATION:
            isTypeValid = javaClass.isAnnotation() && !javaClass.isMemberClass();
            break;

        case MEMBER_ANNOTATION:
            isTypeValid = javaClass.isAnnotation() && javaClass.isMemberClass();
            break;

        case PRIMITIVE:
            isTypeValid = javaClass.isPrimitive();
            break;

        case ARRAY:
            isTypeValid = javaClass.isArray();
            break;

        default:
            throw new UnsupportedOperationException("Unknown class type: " + type);
        }

        if (!isTypeValid) {
            this.addException(
                    String.format("The Java class must have the specified type\n" + "(type: [%s])", type));
        }
    }

    return this;
}

From source file:com.mirth.connect.server.MirthWebServer.java

@SuppressWarnings("unchecked")
private Set<Class<?>> getClassesInPackage(String packageName, Class<?>[] baseClasses, Class<?>[] annotations) {
    ConfigurationBuilder config = new ConfigurationBuilder();
    config.setScanners(new ResourcesScanner(), new TypeAnnotationsScanner(), new SubTypesScanner(false));
    config.addUrls(ClasspathHelper.forPackage(packageName));
    config.setInputsFilter(new PackagePredicate(packageName));
    Reflections reflections = new Reflections(config);

    Set<Class<?>> classes = new HashSet<Class<?>>();
    if (ArrayUtils.isNotEmpty(baseClasses)) {
        for (Class<?> baseClass : baseClasses) {
            classes.addAll(reflections.getSubTypesOf(baseClass));
        }/*from  w  ww .  java  2s.c om*/
    }
    if (ArrayUtils.isNotEmpty(annotations)) {
        for (Class<?> annotation : annotations) {
            if (annotation.isAnnotation()) {
                classes.addAll(reflections.getTypesAnnotatedWith((Class<? extends Annotation>) annotation));
            }
        }
    }
    return classes;
}