Example usage for java.lang.reflect Method getParameterAnnotations

List of usage examples for java.lang.reflect Method getParameterAnnotations

Introduction

In this page you can find the example usage for java.lang.reflect Method getParameterAnnotations.

Prototype

@Override
public Annotation[][] getParameterAnnotations() 

Source Link

Usage

From source file:Main.java

public static void main(String... args) {
    try {//www.  ja v  a  2  s. c om
        Class<?> c = Class.forName("Main");
        Method[] allMethods = c.getDeclaredMethods();
        for (Method m : allMethods) {
            Annotation[][] types = m.getParameterAnnotations();

        }
    } catch (ClassNotFoundException x) {
        x.printStackTrace();
    }
}

From source file:ws.antonov.config.api.consumer.ConfigClientInvocationHandler.java

public static ConfigParam[] retrieveRequestParams(Method method) {
    Annotation[][] annotations = method.getParameterAnnotations();
    ConfigParam[] paramNames = new ConfigParam[annotations.length];
    for (int i = 0; i < annotations.length; i++) {
        Annotation[] anns = annotations[i];
        paramNames[i] = null;/*from   ww  w.j  a v a  2s.  co m*/
        for (Annotation ann : anns) {
            if (ConfigParam.class.isInstance(ann)) {
                paramNames[i] = (ConfigParam) ann;
                break;
            }
        }
    }
    return paramNames;
}

From source file:org.springframework.cloud.sleuth.annotation.SleuthAnnotationUtils.java

static List<SleuthAnnotatedParameter> findAnnotatedParameters(Method method, Object[] args) {
    Annotation[][] parameters = method.getParameterAnnotations();
    List<SleuthAnnotatedParameter> result = new ArrayList<>();
    int i = 0;/*from  w w w. j av  a  2 s  .com*/
    for (Annotation[] parameter : parameters) {
        for (Annotation parameter2 : parameter) {
            if (parameter2 instanceof SpanTag) {
                result.add(new SleuthAnnotatedParameter(i, (SpanTag) parameter2, args[i]));
            }
        }
        i++;
    }
    return result;
}

From source file:de.otto.jsonhome.generator.MethodHelper.java

private static Annotation[][] parameterAnnotationsOf(final Method method) {
    if (method != null) {
        final Annotation[][] parameterAnnotations = method.getParameterAnnotations();
        if (isEmpty(parameterAnnotations)) {
            return parameterAnnotationsOf(methodFromSuperclass(method));
        } else {/* ww w . j a v a  2  s.  co m*/
            return parameterAnnotations;
        }
    }
    return EMPTY_ANNOTATIONS;
}

From source file:io.fabric8.spring.boot.AbstractServiceRegistar.java

private static Class getSourceType(Method method) {
    Annotation[][] annotations = method.getParameterAnnotations();
    for (int i = 0; i < annotations.length; i++) {
        for (int j = 0; j < annotations[i].length; j++) {
            if (ServiceName.class.equals(annotations[i][j].annotationType())) {
                return method.getParameterTypes()[i];
            }//from  w w  w  .j  a v  a  2 s .c  o m
        }
    }
    throw new IllegalStateException("No source type found for @Factory:" + method.getName());
}

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

@SuppressWarnings("unchecked")
private static <A extends Annotation> A searchOnInterfaces(Method method, int parameterIndex,
        Class<A> annotationType, Class<?>[] interfaces) {

    A annotation = null;/* w  ww  .j  a  v  a2  s  .c  o m*/
    for (Class<?> interfaze : interfaces) {
        Optional<Method> interfaceMethod = interfaceMethod(interfaze, method);
        if (interfaceMethod.isPresent()) {
            Method superMethod = interfaceMethod.get();
            Optional<Annotation> found = tryFind(
                    newArrayList(superMethod.getParameterAnnotations()[parameterIndex]),
                    annotationOfType(annotationType));
            if (found.isPresent()) {
                annotation = (A) found.get();
                break;
            }
            Class<?>[] superInterfaces = superMethod.getDeclaringClass().getInterfaces();
            annotation = searchOnInterfaces(superMethod, parameterIndex, annotationType, superInterfaces);
        }
    }
    return annotation;
}

From source file:com.yahoo.bard.webservice.web.filters.QueryParameterNormalizationFilter.java

/**
 * Extract query parameters from a stream of methods.
 *
 * @param method Method to extract from which to extract @QueryParam's
 * @return  A stream of QueryParam annotations
 *//*w w w  .  ja v  a 2  s  . com*/
private static Stream<QueryParam> extractQueryParameters(Method method) {
    return Stream.of(method.getParameterAnnotations()).flatMap(Stream::of)
            .filter(annotation -> annotation.annotationType().isAssignableFrom(QueryParam.class))
            .map(QueryParam.class::cast);
}

From source file:alfio.datamapper.QueryType.java

private static SqlParameterSource extractParameters(Method m, Object[] args) {

    Annotation[][] parameterAnnotations = m.getParameterAnnotations();
    if (parameterAnnotations == null || parameterAnnotations.length == 0) {
        return new EmptySqlParameterSource();
    }/*from   w  w w  .  ja  va2  s  . com*/

    MapSqlParameterSource ps = new MapSqlParameterSource();
    Class<?>[] parameterTypes = m.getParameterTypes();
    for (int i = 0; i < args.length; i++) {
        String name = parameterName(parameterAnnotations[i]);
        if (name != null) {
            if (args[i] != null && ZonedDateTime.class.isAssignableFrom(parameterTypes[i])) {
                ZonedDateTime dateTime = ZonedDateTime.class.cast(args[i]);
                final ZonedDateTime utc = dateTime.withZoneSameInstant(ZoneId.of("UTC"));
                Calendar c = Calendar.getInstance();
                c.setTimeZone(TimeZone.getTimeZone("UTC"));
                c.setTimeInMillis(utc.toInstant().toEpochMilli());
                ps.addValue(name, c, Types.TIMESTAMP);
            } else {
                ps.addValue(name, args[i], StatementCreatorUtils.javaTypeToSqlParameterType(parameterTypes[i]));
            }
        }
    }

    return ps;
}

From source file:nz.ac.otago.psyanlab.common.model.util.ModelUtils.java

/**
 * Get the parameter id annotation for a parameter of the given method.
 * //from w  w w.  ja v a2s  .  com
 * @param parameterPosition Position of parameter in method.
 * @param method Method to query.
 * @return
 */
public static ParameterId getParameterIdAnnotation(int parameterPosition, Method method) {
    Annotation[][] parameterAnnotations = method.getParameterAnnotations();
    for (int j = 0; j < parameterAnnotations.length; j++) {
        Annotation annotation = parameterAnnotations[parameterPosition][j];
        if (annotation instanceof ParameterId) {
            return (ParameterId) annotation;
        }
    }
    return null;
}

From source file:io.lavagna.common.QueryType.java

private static SqlParameterSource extractParameters(Method m, Object[] args) {

    Class<?>[] parameterTypes = m.getParameterTypes();
    Annotation[][] parameterAnnotations = m.getParameterAnnotations();
    if (parameterAnnotations == null || parameterAnnotations.length == 0) {
        return new EmptySqlParameterSource();
    }//from ww w  . jav a  2s. co  m

    MapSqlParameterSource ps = new MapSqlParameterSource();
    for (int i = 0; i < args.length; i++) {
        String name = parameterName(parameterAnnotations[i]);
        if (name != null) {
            ps.addValue(name, args[i], StatementCreatorUtils.javaTypeToSqlParameterType(parameterTypes[i]));
        }
    }

    return ps;
}