Example usage for org.springframework.core MethodParameter getParameterIndex

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

Introduction

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

Prototype

public int getParameterIndex() 

Source Link

Document

Return the index of the method/constructor parameter.

Usage

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

public static <A extends Annotation> Optional<A> fromHierarchy(MethodParameter methodParameter,
        Class<A> annotationType) {
    return fromNullable(searchOnInterfaces(methodParameter.getMethod(), methodParameter.getParameterIndex(),
            annotationType, getParentInterfaces(methodParameter)));
}

From source file:ch.rasc.wampspring.method.PayloadArgumentResolver.java

private static String getParameterName(MethodParameter param) {
    String paramName = param.getParameterName();
    return paramName != null ? paramName : "Arg " + param.getParameterIndex();
}

From source file:org.ngrinder.infra.spring.UserHandlerMethodArgumentResolver.java

@Override
public boolean supportsParameter(MethodParameter parameter) {
    return parameter.getParameterIndex() == 0 && parameter.getParameterType().equals(User.class);
}

From source file:com.kinglcc.spring.jms.core.Jackson2PayloadArgumentResolver.java

private String getParameterName(MethodParameter param) {
    String paramName = param.getParameterName();
    return (paramName != null ? paramName : "Arg " + param.getParameterIndex());
}

From source file:springfox.documentation.spring.web.readers.parameter.ParameterNameReader.java

private Optional<String> discoveredName(MethodParameter methodParameter) {
    String[] discoveredNames = parameterNameDiscover.getParameterNames(methodParameter.getMethod());
    return discoveredNames != null && methodParameter.getParameterIndex() < discoveredNames.length
            ? Optional.fromNullable(emptyToNull(discoveredNames[methodParameter.getParameterIndex()]))
            : Optional.<String>absent();
}

From source file:springfox.documentation.spring.web.readers.parameter.ParameterNameReader.java

@Override
public void apply(ParameterContext context) {
    MethodParameter methodParameter = context.methodParameter();
    String name = findParameterNameFromAnnotations(methodParameter);
    if (isNullOrEmpty(name)) {
        Optional<String> discoveredName = discoveredName(methodParameter);
        name = discoveredName.isPresent() ? discoveredName.get()
                : format("param%s", methodParameter.getParameterIndex());
    }//from   w  w  w. ja v a 2  s  .  c o m
    context.parameterBuilder().name(name).description(name);
}

From source file:com.fengduo.bee.commons.component.FormModelMethodArgumentResolver.java

/**
 * Whether to raise a {@link org.springframework.validation.BindException} on bind or validation errors. The default
 * implementation returns {@code true} if the next method argument is not of type
 * {@link org.springframework.validation.Errors}.
 * //w  w  w .j a v a2 s.  c  o m
 * @param binder the data binder used to perform data binding
 * @param parameter the method argument
 */
protected boolean isBindExceptionRequired(WebDataBinder binder, MethodParameter parameter) {
    int i = parameter.getParameterIndex();
    Class<?>[] paramTypes = parameter.getMethod().getParameterTypes();
    boolean hasBindingResult = (paramTypes.length > (i + 1)
            && Errors.class.isAssignableFrom(paramTypes[i + 1]));

    return !hasBindingResult;
}

From source file:com.redblackit.web.server.mvc.RequestUrlHandlerMethodArgumentResolver.java

/**
 * Check for parameter type support. Note if the annotation is present, we
 * throw an exception if the annotation is applied to an invalid type.
 *
 * @param methodParameter//from w ww  . j a  v  a2s  .c  om
 * @return true if supported, false if not
 */
@Override
public boolean supportsParameter(MethodParameter methodParameter) {
    final Class<?> paramType = methodParameter.getParameterType();

    boolean isSupported = UrlChildLocation.class.isAssignableFrom(paramType);

    if (!isSupported) {
        if (methodParameter.hasParameterAnnotation(RequestUrl.class)) {
            isSupported = String.class.isAssignableFrom(paramType)
                    || StringBuffer.class.isAssignableFrom(paramType)
                    || StringBuilder.class.isAssignableFrom(paramType) || URL.class.isAssignableFrom(paramType)
                    || URI.class.isAssignableFrom(paramType);

            if (!isSupported) {
                throw new IllegalStateException("methodParameter[" + methodParameter.getParameterIndex()
                        + "] type=" + paramType
                        + ":not compatible with @RequestUrl annotation:must be String, StringBuffer, StringBuilder, URL or URI");
            }
        }
    }

    return isSupported;
}

From source file:de.escalon.hypermedia.spring.AffordanceBuilderFactory.java

/**
 * Returns {@link ActionInputParameter}s contained in the method link.
 *
 * @param annotation to inspect/*from  www.j a  v  a2 s .c o m*/
 * @param method     must not be {@literal null}.
 * @param arguments  to the method link
 * @return maps parameter names to parameter info
 */
private static Map<String, ActionInputParameter> getActionInputParameters(
        Class<? extends Annotation> annotation, Method method, Object... arguments) {

    Assert.notNull(method, "MethodInvocation must not be null!");

    MethodParameters parameters = new MethodParameters(method);
    Map<String, ActionInputParameter> result = new HashMap<String, ActionInputParameter>();

    for (MethodParameter parameter : parameters.getParametersWith(annotation)) {
        final int parameterIndex = parameter.getParameterIndex();
        final Object argument;
        if (parameterIndex < arguments.length) {
            argument = arguments[parameterIndex];
        } else {
            argument = null;
        }
        result.put(parameter.getParameterName(), new ActionInputParameter(parameter, argument));
    }

    return result;
}