Example usage for org.springframework.core.annotation AnnotationUtils synthesizeAnnotation

List of usage examples for org.springframework.core.annotation AnnotationUtils synthesizeAnnotation

Introduction

In this page you can find the example usage for org.springframework.core.annotation AnnotationUtils synthesizeAnnotation.

Prototype

public static <A extends Annotation> A synthesizeAnnotation(A annotation,
        @Nullable AnnotatedElement annotatedElement) 

Source Link

Document

Synthesize an annotation from the supplied annotation by wrapping it in a dynamic proxy that transparently enforces attribute alias semantics for annotation attributes that are annotated with AliasFor @AliasFor .

Usage

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

public SpringWebJavaMethodParameterMetadata(java.lang.reflect.Parameter javaMethodParameter,
        Class<?> targetClassType) {
    this.type = JavaType.of(new JavaTypeResolver(targetClassType).parameterizedTypeOf(javaMethodParameter));

    this.pathParameter = AnnotationUtils
            .synthesizeAnnotation(javaMethodParameter.getAnnotation(PathVariable.class), javaMethodParameter);

    this.headerParameter = AnnotationUtils
            .synthesizeAnnotation(javaMethodParameter.getAnnotation(RequestHeader.class), javaMethodParameter);

    this.bodyParameter = AnnotationUtils
            .synthesizeAnnotation(javaMethodParameter.getAnnotation(RequestBody.class), javaMethodParameter);

    this.queryParameter = AnnotationUtils
            .synthesizeAnnotation(javaMethodParameter.getAnnotation(RequestParam.class), javaMethodParameter);

    this.name = Optional.ofNullable(pathParameter).map(PathVariable::value).filter(s -> !s.trim().isEmpty())
            .orElseGet(() -> Optional.ofNullable(headerParameter).map(RequestHeader::value)
                    .filter(s -> !s.trim().isEmpty())
                    .orElseGet(() -> Optional.ofNullable(queryParameter).map(RequestParam::value)
                            .filter(s -> !s.trim().isEmpty())
                            .orElseGet(() -> Optional.ofNullable(javaMethodParameter.getName()).orElseThrow(
                                    () -> new IllegalStateException("Could not get the name of the parameter "
                                            + javaMethodParameter)))));

    this.serializerType = SpringWebEndpointMethodParameterSerializer.of(this);
}