Java Code Examples for org.jboss.jandex.AnnotationTarget.Kind#METHOD_PARAMETER

The following examples show how to use org.jboss.jandex.AnnotationTarget.Kind#METHOD_PARAMETER . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParameterProcessor.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
boolean haveSameAnnotatedTarget(ParameterContext context, AnnotationTarget target, String name) {
    /*
     * Consider names to match if one is unspecified or they are equal.
     */
    boolean nameMatches = (context.name == null || name == null || Objects.equals(context.name, name));

    if (target.equals(context.target)) {
        /*
         * The name must match for annotations on a method because it is
         * ambiguous which parameters is being referenced.
         */
        return nameMatches || target.kind() != Kind.METHOD;
    }

    if (nameMatches && target.kind() == Kind.METHOD && context.target.kind() == Kind.METHOD_PARAMETER) {
        return context.target.asMethodParameter().method().equals(target);
    }

    return false;
}
 
Example 2
Source File: ParameterProcessor.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
boolean haveSameAnnotatedTarget(ParameterContext context, AnnotationTarget target, String name) {
    boolean nameMatches = Objects.equals(context.name, name);

    if (target.equals(context.target)) {
        return true;
    }

    if (nameMatches && target.kind() == Kind.METHOD && context.target.kind() == Kind.METHOD_PARAMETER) {
        return context.target.asMethodParameter().method().equals(target);
    }

    return false;
}
 
Example 3
Source File: JandexUtil.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
/**
 * Finds an annotation (if present) with the given name, on a particular parameter of a
 * method.Returns null if not found.
 * 
 * @param method the method
 * @param parameterIndex the parameter index
 * @param annotationName name of annotation we are looking for
 * @return the Annotation instance
 */
public static AnnotationInstance getMethodParameterAnnotation(MethodInfo method, int parameterIndex,
        DotName annotationName) {
    for (AnnotationInstance annotation : method.annotations()) {
        if (annotation.target().kind() == Kind.METHOD_PARAMETER &&
                annotation.target().asMethodParameter().position() == parameterIndex &&
                annotation.name().equals(annotationName)) {
            return annotation;
        }
    }
    return null;
}
 
Example 4
Source File: ObserverInfo.java    From quarkus with Apache License 2.0 5 votes vote down vote up
static MethodParameterInfo initEventParam(MethodInfo observerMethod, BeanDeployment beanDeployment) {
    List<MethodParameterInfo> eventParams = new ArrayList<>();
    for (AnnotationInstance annotation : beanDeployment.getAnnotations(observerMethod)) {
        if (Kind.METHOD_PARAMETER == annotation.target().kind()
                && (annotation.name().equals(DotNames.OBSERVES) || annotation.name().equals(DotNames.OBSERVES_ASYNC))) {
            eventParams.add(annotation.target().asMethodParameter());
        }
    }
    if (eventParams.isEmpty()) {
        throw new DefinitionException("No event parameters found for " + observerMethod);
    } else if (eventParams.size() > 1) {
        throw new DefinitionException("Multiple event parameters found for " + observerMethod);
    }
    return eventParams.get(0);
}
 
Example 5
Source File: Annotations.java    From quarkus with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param beanDeployment
 * @param method
 * @param position
 * @return the parameter annotations for the given position
 */
public static Set<AnnotationInstance> getParameterAnnotations(BeanDeployment beanDeployment, MethodInfo method,
        int position) {
    Set<AnnotationInstance> annotations = new HashSet<>();
    for (AnnotationInstance annotation : beanDeployment.getAnnotations(method)) {
        if (Kind.METHOD_PARAMETER == annotation.target().kind()
                && annotation.target().asMethodParameter().position() == position) {
            annotations.add(annotation);
        }
    }
    return annotations;
}
 
Example 6
Source File: CacheAnnotationsTransformer.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private Optional<AnnotationValue> findCacheKeyParameters(MethodInfo method) {
    List<AnnotationValue> parameters = new ArrayList<>();
    for (AnnotationInstance annotation : method.annotations()) {
        if (annotation.target().kind() == Kind.METHOD_PARAMETER && CACHE_KEY.equals(annotation.name())) {
            parameters.add(AnnotationValue.createShortValue("", annotation.target().asMethodParameter().position()));
        }
    }
    if (parameters.isEmpty()) {
        return Optional.empty();
    }
    return Optional.of(AnnotationValue.createArrayValue(CACHE_KEY_PARAMETER_POSITIONS_PARAM, toArray(parameters)));
}
 
Example 7
Source File: ResteasyServerCommonProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static void checkParameterNames(IndexView index,
        List<AdditionalJaxRsResourceMethodParamAnnotations> additionalJaxRsResourceMethodParamAnnotations) {

    final List<DotName> methodParameterAnnotations = new ArrayList<>(RESTEASY_PARAM_ANNOTATIONS.length);
    methodParameterAnnotations.addAll(Arrays.asList(RESTEASY_PARAM_ANNOTATIONS));
    for (AdditionalJaxRsResourceMethodParamAnnotations annotations : additionalJaxRsResourceMethodParamAnnotations) {
        methodParameterAnnotations.addAll(annotations.getAnnotationClasses());
    }

    OUTER: for (DotName annotationType : methodParameterAnnotations) {
        Collection<AnnotationInstance> instances = index.getAnnotations(annotationType);
        for (AnnotationInstance instance : instances) {
            // we only care about method parameters, because properties or fields always work
            if (instance.target().kind() != Kind.METHOD_PARAMETER) {
                continue;
            }
            MethodParameterInfo param = instance.target().asMethodParameter();
            if (param.name() == null) {
                log.warnv(
                        "Detected RESTEasy annotation {0} on method parameter {1}.{2} with no name. Either specify its name,"
                                + " or tell your compiler to enable debug info (-g) or parameter names (-parameters). This message is only"
                                + " logged for the first such parameter.",
                        instance.name(),
                        param.method().declaringClass(), param.method().name());
                break OUTER;
            }
        }
    }
}
 
Example 8
Source File: ResteasyServerCommonProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static boolean hasAnnotation(MethodInfo method, short paramPosition, DotName annotation) {
    for (AnnotationInstance annotationInstance : method.annotations()) {
        AnnotationTarget target = annotationInstance.target();
        if (target != null && target.kind() == Kind.METHOD_PARAMETER
                && target.asMethodParameter().position() == paramPosition
                && annotationInstance.name().equals(annotation)) {
            return true;
        }
    }
    return false;
}