Example usage for org.springframework.core.annotation AnnotatedElementUtils hasAnnotation

List of usage examples for org.springframework.core.annotation AnnotatedElementUtils hasAnnotation

Introduction

In this page you can find the example usage for org.springframework.core.annotation AnnotatedElementUtils hasAnnotation.

Prototype

public static boolean hasAnnotation(AnnotatedElement element, Class<? extends Annotation> annotationType) 

Source Link

Document

Determine if an annotation of the specified annotationType is available on the supplied AnnotatedElement or within the annotation hierarchy above the specified element.

Usage

From source file:com.example.config.StartupApplicationListener.java

private boolean isSpringBootApplication(Set<Class<?>> sources) {
    for (Class<?> source : sources) {
        if (AnnotatedElementUtils.hasAnnotation(source, SpringBootConfiguration.class)) {
            return true;
        }/*from  w  w  w .  j a v  a 2  s .c  o  m*/
    }
    return false;
}

From source file:org.springframework.boot.context.properties.ValidatedLocalValidatorFactoryBean.java

@Override
public boolean supports(Class<?> type) {
    if (!super.supports(type)) {
        return false;
    }//w w  w .  j a v  a 2  s  .  c  o  m
    if (AnnotatedElementUtils.hasAnnotation(type, Validated.class)) {
        return true;
    }
    if (type.getPackage() != null && type.getPackage().getName().startsWith("org.springframework.boot")) {
        return false;
    }
    if (getConstraintsForClass(type).isBeanConstrained()) {
        logger.warn("The @ConfigurationProperties bean " + type
                + " contains validation constraints but had not been annotated " + "with @Validated.");
    }
    return true;
}

From source file:org.springframework.messaging.handler.HandlerMethod.java

/**
 * Return whether the parameter is declared with the given annotation type.
 * @param annotationType the annotation type to look for
 * @since 4.3//from ww w.ja  v  a  2  s.c  om
 * @see AnnotatedElementUtils#hasAnnotation
 */
public <A extends Annotation> boolean hasMethodAnnotation(Class<A> annotationType) {
    return AnnotatedElementUtils.hasAnnotation(this.method, annotationType);
}

From source file:org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler.java

@Override
protected boolean isHandler(Class<?> beanType) {
    return AnnotatedElementUtils.hasAnnotation(beanType, Controller.class);
}

From source file:org.springframework.test.context.support.AnnotationConfigContextLoaderUtils.java

/**
 * Determine if the supplied {@link Class} meets the criteria for being
 * considered a <em>default configuration class</em> candidate.
 * <p>Specifically, such candidates:
 * <ul>// w ww. j  a  v a 2 s . c  o m
 * <li>must not be {@code null}</li>
 * <li>must not be {@code private}</li>
 * <li>must not be {@code final}</li>
 * <li>must be {@code static}</li>
 * <li>must be annotated or meta-annotated with {@code @Configuration}</li>
 * </ul>
 * @param clazz the class to check
 * @return {@code true} if the supplied class meets the candidate criteria
 */
private static boolean isDefaultConfigurationClassCandidate(@Nullable Class<?> clazz) {
    return (clazz != null && isStaticNonPrivateAndNonFinal(clazz)
            && AnnotatedElementUtils.hasAnnotation(clazz, Configuration.class));
}

From source file:org.springframework.test.context.transaction.TransactionalTestExecutionListener.java

/**
 * Get all methods in the supplied {@link Class class} and its superclasses
 * which are annotated with the supplied {@code annotationType} but
 * which are not <em>shadowed</em> by methods overridden in subclasses.
 * <p>Default methods on interfaces are also detected.
 * @param clazz the class for which to retrieve the annotated methods
 * @param annotationType the annotation type for which to search
 * @return all annotated methods in the supplied class and its superclasses
 * as well as annotated interface default methods
 */// w  w w .ja v a  2  s.  c  o m
private List<Method> getAnnotatedMethods(Class<?> clazz, Class<? extends Annotation> annotationType) {
    return Arrays.stream(ReflectionUtils.getUniqueDeclaredMethods(clazz))
            .filter(method -> AnnotatedElementUtils.hasAnnotation(method, annotationType))
            .collect(Collectors.toList());
}

From source file:org.springframework.test.context.web.ServletTestExecutionListener.java

private boolean isActivated(TestContext testContext) {
    return (Boolean.TRUE.equals(testContext.getAttribute(ACTIVATE_LISTENER))
            || AnnotatedElementUtils.hasAnnotation(testContext.getTestClass(), WebAppConfiguration.class));
}