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:com.google.ratel.util.RatelUtils.java

public static void populateParameterTypes(MethodData methodData) {
    Method method = methodData.getMethod();
    Class[] parameterTypes = method.getParameterTypes();
    List<ParameterData> parameters = new ArrayList<ParameterData>();
    methodData.setParameters(parameters);

    Annotation[][] parameterAnnotations = method.getParameterAnnotations();

    for (int i = 0; i < parameterTypes.length; i++) {
        Class parameterType = parameterTypes[i];
        Annotation[] annotations = parameterAnnotations[i];

        ParameterData parameterData = new ParameterData();
        parameterData.setType(parameterType);
        parameterData.setAnnotations(annotations);

        for (Annotation annotation : annotations) {
            if (annotation instanceof Param) {
                Param param = (Param) annotation;
                parameterData.setParam(param);

            } else if (annotation instanceof JsonParam) {
                JsonParam param = (JsonParam) annotation;
                parameterData.setJsonParam(param);
            }//from w  w  w  .  j ava 2  s  . c  o  m
        }

        parameters.add(parameterData);
    }
}

From source file:pl.bristleback.server.bristle.conf.resolver.action.client.ClientActionResolver.java

private List<ClientActionParameterInformation> resolveActionParameters(Method actionMethod) {
    SerializationResolver serializationResolver = serializationEngine.getSerializationResolver();
    List<ClientActionParameterInformation> parameters = new ArrayList<ClientActionParameterInformation>();
    for (int i = 0; i < actionMethod.getParameterTypes().length; i++) {
        Type parameterType = actionMethod.getGenericParameterTypes()[i];
        ClientActionParameterInformation parameterInformation = parameterResolver.prepareActionParameter(
                serializationResolver, parameterType, actionMethod.getParameterAnnotations()[i]);
        parameters.add(parameterInformation);
    }/* w  w  w  .j  a v a 2  s  . c om*/
    return parameters;
}

From source file:com.reactivetechnologies.platform.rest.depre.RequestDispatchers.java

private void addAnnotatedClass(Class<?> restletClass) throws InstantiationException, IllegalAccessException {
    final JAXRSInstanceMetadata proxy = new JAXRSInstanceMetadata(restletClass.newInstance());
    if (restletClass.isAnnotationPresent(Path.class)) {
        String rootUri = restletClass.getAnnotation(Path.class).value();
        proxy.setRootUri(rootUri);//from   w w  w .  jav a  2  s.  c o m
    }
    ReflectionUtils.doWithMethods(restletClass, new MethodCallback() {

        @Override
        public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
            String subUri = "";
            if (method.isAnnotationPresent(Path.class)) {
                subUri = method.getAnnotation(Path.class).value();
            }
            if (method.isAnnotationPresent(GET.class)) {
                MethodDetail m = new MethodDetail(method);
                Annotation[][] mAnnots = method.getParameterAnnotations();
                int i = 0;
                for (Annotation[] annots : mAnnots) {
                    for (Annotation annot : annots) {
                        if (annot.annotationType() == QueryParam.class) {
                            m.setQueryParam(i, ((QueryParam) annot).value());
                        }
                    }
                    i++;
                }
                proxy.addGetMethod(proxy.getRootUri() + subUri, m);
            }
            if (method.isAnnotationPresent(POST.class)) {
                MethodDetail m = new MethodDetail(method);
                Annotation[][] mAnnots = method.getParameterAnnotations();
                int i = 0;
                for (Annotation[] annots : mAnnots) {
                    for (Annotation annot : annots) {
                        if (annot.annotationType() == QueryParam.class) {
                            m.setQueryParam(i, ((QueryParam) annot).value());
                        }
                    }
                    i++;
                }
                proxy.addPostMethod(proxy.getRootUri() + subUri, m);
            }

        }
    }, new MethodFilter() {

        @Override
        public boolean matches(Method method) {
            return (method.isAnnotationPresent(GET.class) || method.isAnnotationPresent(POST.class));
        }
    });

    allClasses.add(proxy);
}

From source file:com.googlecode.ehcache.annotations.impl.CacheAttributeSourceImpl.java

/**
 * Parse the parameters annotated with {@link PartialCacheKey}.
 * //  w ww.  j a  va 2 s.  co  m
 * @param method The method who's parameters should be checked.
 * @return The parameter mask for the annotated parameters.
 */
protected ParameterMask parsePartialCacheKeyAnnotations(Method method) {
    final Annotation[][] parameterAnnotations = method.getParameterAnnotations();
    final boolean[] mask = new boolean[parameterAnnotations.length];
    for (int i = 0; i < parameterAnnotations.length; i++) {
        final Annotation[] annotations = parameterAnnotations[i];
        for (final Annotation annotation : annotations) {
            final Class<? extends Annotation> annotationType = annotation.annotationType();
            if (PartialCacheKey.class.equals(annotationType)) {
                mask[i] = true;
                break;
            }
        }
    }

    return ParameterMask.create(mask);
}

From source file:name.ikysil.beanpathdsl.codegen.Context.java

@SuppressWarnings("unchecked")
private <A extends Annotation> void scanMethod(Map<Class<?>, A> result, Method method,
        Class<A> annotationClass) {
    final A methodAnnotation = method.getAnnotation(annotationClass);
    if (methodAnnotation != null) {
        result.put(resolveClass(method.getReturnType()), methodAnnotation);
    }/*from  w w  w .ja v a  2 s .  c o  m*/
    Class<?>[] paramTypes = method.getParameterTypes();
    Annotation[][] paramsAnnotations = method.getParameterAnnotations();
    for (int i = 0; i < paramTypes.length; i++) {
        Annotation[] paramAnnotations = paramsAnnotations[i];
        A paramAnnotation = methodAnnotation;
        for (Annotation annotation : paramAnnotations) {
            if (annotation.annotationType().equals(annotationClass)) {
                paramAnnotation = (A) annotation;
                break;
            }
        }
        if (paramAnnotation != null) {
            result.put(resolveClass(paramTypes[i]), paramAnnotation);
        }
    }
}

From source file:org.omnaest.utils.reflection.ReflectionUtils.java

/**
 * Returns an ordered {@link List} of {@link MethodParameterMetaInformation} instances for each parameter the given
 * {@link Method} has.//from  ww w . j a v a  2s.c  om
 * 
 * @param method
 * @return
 */
public static List<MethodParameterMetaInformation> declaredMethodParameterMetaInformationList(Method method) {
    //    
    List<MethodParameterMetaInformation> retlist = new ArrayList<MethodParameterMetaInformation>();

    //
    if (method != null) {
        //
        Class<?>[] parameterTypes = method.getParameterTypes();
        Annotation[][] parametersAnnotations = method.getParameterAnnotations();

        //
        for (int ii = 0; ii < Math.max(parameterTypes.length, parametersAnnotations.length); ii++) {
            //
            Class<?> parameterType = parameterTypes[ii];
            Annotation[] parameterAnnotations = parametersAnnotations[ii];

            //
            MethodParameterMetaInformation methodParameterMetaInformation = new MethodParameterMetaInformation(
                    parameterType, Arrays.asList(parameterAnnotations));
            retlist.add(methodParameterMetaInformation);
        }

    }

    //
    return retlist;
}

From source file:org.wso2.carbon.device.mgt.extensions.feature.mgt.util.AnnotationProcessor.java

private List<String> processParamAnnotations(Method currentMethod, Class<?> clazz) throws Throwable {
    List<String> params = new ArrayList<>();
    try {// w  ww.  j av  a  2 s  . c om
        Class<?> paramClazz = (Class<?>) classLoader.loadClass(clazz.getName());
        Method[] formMethods = paramClazz.getMethods();
        //Extract method parameter information and store same as feature meta info
        Annotation[][] paramAnnotations = currentMethod.getParameterAnnotations();
        Method valueMethod = formMethods[0];
        for (int j = 0; j < paramAnnotations.length; j++) {
            for (Annotation anno : paramAnnotations[j]) {
                if (anno.annotationType().getName().equals(clazz.getName())) {
                    params.add(invokeMethod(valueMethod, anno, STRING));
                }
            }
        }
    } catch (ClassNotFoundException e) {
        log.debug("No " + clazz.getName() + " Param found for class " + featureAnnotationClazz.getName());
    }
    return params;
}

From source file:com.shop.commons.swagger.Reader.java

private void read(ReaderContext context) {
    final SwaggerDefinition swaggerDefinition = context.getCls().getAnnotation(SwaggerDefinition.class);
    if (swaggerDefinition != null) {
        readSwaggerConfig(swaggerDefinition);
    }//w  w  w.j av  a 2 s . c  om
    for (Method method : context.getCls().getMethods()) {
        if (ReflectionUtils.isOverriddenMethod(method, context.getCls())) {
            continue;
        }
        final Operation operation = new Operation();
        String operationPath = null;
        String httpMethod = null;

        final Type[] genericParameterTypes = method.getGenericParameterTypes();
        final Annotation[][] paramAnnotations = method.getParameterAnnotations();

        for (ReaderExtension extension : ReaderExtensions.getExtensions()) {
            if (operationPath == null) {
                operationPath = extension.getPath(context, method);
            }
            if (httpMethod == null) {
                httpMethod = extension.getHttpMethod(context, method);
            }
            if (operationPath == null || httpMethod == null) {
                continue;
            }

            if (extension.isReadable(context)) {
                extension.setDeprecated(operation, method);
                extension.applyConsumes(context, operation, method);
                extension.applyProduces(context, operation, method);
                extension.applyOperationId(operation, method);
                extension.applySummary(operation, method);
                extension.applyDescription(operation, method);
                extension.applySchemes(context, operation, method);
                extension.applySecurityRequirements(context, operation, method);
                extension.applyTags(context, operation, method);
                extension.applyResponses(context, operation, method);
                extension.applyImplicitParameters(context, operation, method);
                extension.applyExtensions(context, operation, method);
                for (int i = 0; i < genericParameterTypes.length; i++) {
                    extension.applyParameters(context, operation, genericParameterTypes[i],
                            paramAnnotations[i]);
                }
            }
        }

        if (httpMethod != null) {
            if (operation.getResponses() == null) {
                operation.defaultResponse(new Response().description("successful operation"));
            }

            final Map<String, String> regexMap = new HashMap<String, String>();
            final String parsedPath = PathUtils.parsePath(operationPath, regexMap);

            Path path = swagger.getPath(parsedPath);
            if (path == null) {
                path = new Path();
                swagger.path(parsedPath, path);
            }
            path.set(httpMethod.toLowerCase(), operation);
        }
    }
}

From source file:org.cruxframework.crux.core.server.rest.core.dispatch.MethodInvoker.java

public MethodInvoker(Class<?> root, Method method, String httpMethod) {
    this.method = method;
    this.rootClass = root;
    this.restErrorHandler = RestErrorHandlerFactory.createErrorHandler(method);
    this.params = new ValueInjector[method.getParameterTypes().length];
    Type[] genericParameterTypes = method.getGenericParameterTypes();
    for (int i = 0; i < genericParameterTypes.length; i++) {
        Annotation[] annotations = method.getParameterAnnotations()[i];
        Type paramType = ClassUtils.resolveGenericTypeOnMethod(genericParameterTypes[i], rootClass, method);
        params[i] = createParameterExtractor(root, paramType, annotations);
    }//  w w  w .j av a  2s.c o m
    validateParamExtractors(httpMethod);
    initializePreprocessors();
    initializePostprocessors();
}

From source file:com.khs.sherpa.servlet.SherpaRequest.java

private Object[] getParams(Method method) {
    RequestMapper map = new RequestMapper();
    map.setService(service);//from  w w  w.  jav a 2s .c  o m
    map.setRequest(servletRequest);
    map.setResponse(servletResponse);

    Class<?>[] types = method.getParameterTypes();
    Object[] params = null;
    // get parameters
    if (types.length > 0) {
        params = new Object[types.length];
    }

    Annotation[][] parameters = method.getParameterAnnotations();
    for (int i = 0; i < parameters.length; i++) {
        Class<?> type = types[i];
        Annotation annotation = null;
        if (parameters[i].length > 0) {
            for (Annotation an : parameters[i]) {
                if (an.annotationType().isAssignableFrom(Param.class)) {
                    annotation = an;
                    break;
                }
            }

        }
        params[i] = map.map(method.getClass().getName(), method.getName(), type, annotation);
    }
    return params;
}