Example usage for org.springframework.core MethodParameter getParameterAnnotation

List of usage examples for org.springframework.core MethodParameter getParameterAnnotation

Introduction

In this page you can find the example usage for org.springframework.core MethodParameter getParameterAnnotation.

Prototype

@SuppressWarnings("unchecked")
@Nullable
public <A extends Annotation> A getParameterAnnotation(Class<A> annotationType) 

Source Link

Document

Return the parameter annotation of the given type, if available.

Usage

From source file:springfox.documentation.swagger.readers.parameter.ParameterMultiplesReader.java

@Override
public void apply(ParameterContext context) {

    MethodParameter methodParameter = context.methodParameter();
    ApiParam apiParam = methodParameter.getParameterAnnotation(ApiParam.class);

    Boolean allowMultiple;//from w  w w  .  j  a v a2 s  .c  om
    Class<?> parameterType = methodParameter.getParameterType();
    if (null != apiParam && !(parameterType != null && parameterType.isArray()
            && parameterType.getComponentType().isEnum())) {
        allowMultiple = apiParam.allowMultiple();
        context.parameterBuilder().allowMultiple(allowMultiple);
    }
}

From source file:com.nec.harvest.resolver.AuthenticatedArgumentResolver.java

/**
 * Obtains the specified {@link java.lang.annotation.Annotation} on the specified {@link org.springframework.core.MethodParameter}.
 *
 * @param annotationClass the class of the {@link java.lang.annotation.Annotation} to find on the {@link org.springframework.core.MethodParameter}
 * @param parameter the {@link org.springframework.core.MethodParameter} to search for an {@link java.lang.annotation.Annotation}
 * @return the {@link java.lang.annotation.Annotation} that was found or null.
 *//*from   w  ww .j av  a  2  s  . com*/
private <T extends Annotation> T findMethodAnnotation(Class<T> annotationClass, MethodParameter parameter) {
    T annotation = parameter.getParameterAnnotation(annotationClass);
    if (annotation != null) {
        return annotation;
    }

    Annotation[] annotationsToSearch = parameter.getParameterAnnotations();
    for (Annotation toSearch : annotationsToSearch) {
        annotation = AnnotationUtils.findAnnotation(toSearch.annotationType(), annotationClass);
        if (annotation != null) {
            return annotation;
        }
    }
    return null;
}

From source file:net.kaczmarzyk.spring.data.jpa.web.JoinFetchSpecificationResolver.java

private <A extends Annotation> A getFetchDef(Class<A> annotation, MethodParameter parameter) {
    A fetchDef = parameter.getParameterAnnotation(annotation);
    if (fetchDef == null) {
        fetchDef = parameter.getParameterType().getAnnotation(annotation);
    }/*  www . jav  a 2  s .c  om*/
    return fetchDef;
}

From source file:curly.commons.github.GitHubAuthenticationMethodHandler.java

private <T extends Annotation> T findMethodAnnotation(Class<T> annotationClass, MethodParameter parameter) {
    T annotation = parameter.getParameterAnnotation(annotationClass);
    if (annotation != null) {
        return annotation;
    }/*from   w w  w  .  j a va2s.  c  o m*/
    Annotation[] annotationsToSearch = parameter.getParameterAnnotations();
    for (Annotation toSearch : annotationsToSearch) {
        annotation = AnnotationUtils.findAnnotation(toSearch.annotationType(), annotationClass);
        if (annotation != null) {
            return annotation;
        }
    }
    return null;
}

From source file:de.iew.web.isc.spring.IscRequestMethodArgumentResolver.java

public boolean supportsParameter(MethodParameter methodParameter) {
    IscRequest iscRequestAnnotation = methodParameter.getParameterAnnotation(IscRequest.class);
    return (iscRequestAnnotation != null);
}

From source file:de.chludwig.websec.saml2sp.springconfig.CurrentUserHandlerMethodArgumentResolver.java

@Override
public boolean supportsParameter(MethodParameter methodParameter) {
    return methodParameter.getParameterAnnotation(CurrentUser.class) != null
            && methodParameter.getParameterType().isAssignableFrom(ApplicationUser.class);
}

From source file:com.linecorp.bot.spring.boot.interceptor.LineBotServerInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    HandlerMethod hm = (HandlerMethod) handler;
    MethodParameter[] methodParameters = hm.getMethodParameters();
    for (MethodParameter methodParameter : methodParameters) {
        if (methodParameter.getParameterAnnotation(LineBotMessages.class) != null) {
            try {
                CallbackRequest callbackRequest = lineBotCallbackRequestParser.handle(request);
                LineBotServerArgumentProcessor.setValue(request, callbackRequest);
                return true;
            } catch (LineBotCallbackException e) {
                log.info("LINE Bot callback exception: {}", e.getMessage());
                response.sendError(HttpStatus.BAD_REQUEST.value());
                try (PrintWriter writer = response.getWriter()) {
                    writer.println(e.getMessage());
                }//from  w  w w.  ja  va2 s. c o m
                return false;
            }
        }
    }
    return true;
}

From source file:com.oembedler.moon.graphql.engine.dfs.GraphQLMethodParameters.java

@Override
protected String getParameterName(int idx, MethodParameter methodParameter) {
    String inputParameterName = null;
    GraphQLIn graphQLIn = methodParameter.getParameterAnnotation(GraphQLIn.class);
    if (graphQLIn != null && StringUtils.hasLength(graphQLIn.value())) {
        inputParameterName = graphQLIn.value();
    }/*from  www . j  ava 2 s . co  m*/
    return inputParameterName;
}

From source file:io.neba.core.mvc.ResourceParamArgumentResolver.java

private ResourceParam getParameterAnnotation(MethodParameter parameter) {
    return parameter.getParameterAnnotation(ResourceParam.class);
}

From source file:org.sarons.spring4me.web.widget.bind.support.PrefParamWebArgumentResolver.java

public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) throws Exception {
    PrefParam prefParam = methodParameter.getParameterAnnotation(PrefParam.class);
    if (prefParam == null) {
        return WebArgumentResolver.UNRESOLVED;
    }/*from  ww w.ja  v a  2s  .  co  m*/
    //
    Object value = getValue(webRequest, methodParameter.getParameterName());
    if (value == null) {
        value = prefParam.value();
    }
    //
    Class<?> requiredType = methodParameter.getParameterType();
    if (conversionService.canConvert(String.class, requiredType)) {
        return conversionService.convert(value, TypeDescriptor.valueOf(String.class),
                TypeDescriptor.valueOf(requiredType));
    }
    return WebArgumentResolver.UNRESOLVED;
}