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

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

Introduction

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

Prototype

@Nullable
public static <A extends Annotation> A getMergedAnnotation(AnnotatedElement element, Class<A> annotationType) 

Source Link

Document

Get the first annotation of the specified annotationType within the annotation hierarchy above the supplied element , merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy, and synthesize the result back into an annotation of the specified annotationType .

Usage

From source file:org.mybatis.spring.boot.test.autoconfigure.MybatisTypeExcludeFilter.java

MybatisTypeExcludeFilter(Class<?> testClass) {
    this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, MybatisTest.class);
}

From source file:ac.simons.spring.boot.test.autoconfigure.data.mongo.DataMongoTypeExcludeFilter.java

DataMongoTypeExcludeFilter(final Class<?> testClass) {
    this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, DataMongoTest.class);
}

From source file:com.github.ljtfreitas.restify.http.spring.contract.metadata.reflection.SpringWebJavaTypeMetadata.java

public SpringWebJavaTypeMetadata(Class<?> javaType) {
    isTrue(javaType.isInterface(), "Your type must be a Java interface.");
    isTrue(javaType.getInterfaces().length <= 1, "Only single inheritance is supported.");

    RequestMapping mapping = AnnotatedElementUtils.getMergedAnnotation(javaType, RequestMapping.class);
    if (mapping != null) {
        isTrue(mapping.value().length <= 1, "Only single path is allowed.");
        isTrue(mapping.method().length == 0,
                "You must not set the HTTP method at the class level, only at the method level.");
    }/*from w w w.j  av  a 2  s.  c o  m*/

    this.mapping = Optional.ofNullable(mapping).map(m -> new SpringWebRequestMappingMetadata(m));
    this.javaType = javaType;
    this.parent = javaType.getInterfaces().length == 1
            ? new SpringWebJavaTypeMetadata(javaType.getInterfaces()[0])
            : null;
}

From source file:demo.ChildTestContext.java

@Override
public ApplicationContext getApplicationContext() {
    ApplicationContext parent = super.getApplicationContext();
    ApplicationContext context = parent;
    if (this.method != null) {
        SpringApplicationBuilder builder = null;
        ChildSpringApplication annotation = AnnotatedElementUtils.getMergedAnnotation(this.method,
                ChildSpringApplication.class);
        if (annotation != null) {
            if (annotation.classes().length > 0) {
                builder = new SpringApplicationBuilder();
                for (Class<?> source : annotation.classes()) {
                    builder.sources(source);
                }// w  w  w.  j a va2 s  .  c  om
            }
        }
        ChildTestProperties properties = AnnotatedElementUtils.getMergedAnnotation(this.method,
                ChildTestProperties.class);
        if (properties != null) {
            if (properties.value().length > 0) {
                if (builder == null) {
                    builder = new SpringApplicationBuilder();
                }
                for (String source : properties.value()) {
                    builder.properties(source);
                }
            }
        }
        if (builder != null) {
            this.closeable = builder.sources(PropertyPlaceholderAutoConfiguration.class).bannerMode(Mode.OFF)
                    .web(false).parent((ConfigurableApplicationContext) parent).run();
            context = this.closeable;
        }
    }
    return context;
}

From source file:com.linecorp.bot.spring.boot.support.LineMessageHandlerSupport.java

private HandlerMethod getMethodHandlerMethodFunction(Object consumer, Method method) {
    final EventMapping mapping = AnnotatedElementUtils.getMergedAnnotation(method, EventMapping.class);
    if (mapping == null) {
        return null;
    }/*from   w  w  w .ja  v  a 2 s.  c  o m*/

    Preconditions.checkState(method.getParameterCount() == 1, "Number of parameter should be 1. But {}",
            (Object[]) method.getParameterTypes());
    // TODO: Support more than 1 argument. Like MVC's argument resolver?

    final Type type = method.getGenericParameterTypes()[0];

    final Predicate<Event> predicate = new EventPredicate(type);
    return new HandlerMethod(predicate, consumer, method, getPriority(mapping, type));
}

From source file:org.springframework.boot.test.context.SpringBootTestContextBootstrapper.java

protected SpringBootTest getAnnotation(Class<?> testClass) {
    return AnnotatedElementUtils.getMergedAnnotation(testClass, SpringBootTest.class);
}

From source file:org.springframework.boot.test.context.SpringBootTestContextBootstrapper.java

private <T extends Annotation> T getAnnotation(Class<T> annotationType, Class<?> testClass) {
    return AnnotatedElementUtils.getMergedAnnotation(testClass, annotationType);
}