Java Code Examples for org.jboss.jandex.AnnotationInstance#values()

The following examples show how to use org.jboss.jandex.AnnotationInstance#values() . 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: AnnotatedElement.java    From gizmo with Apache License 2.0 6 votes vote down vote up
default void addAnnotation(AnnotationInstance annotation) {
    AnnotationCreator ac = addAnnotation(annotation.name().toString());
    for (AnnotationValue member : annotation.values()) {
        if (member.kind() == AnnotationValue.Kind.NESTED) {
            throw new RuntimeException("Not Yet Implemented: Cannot generate annotation " + annotation);
        } else if (member.kind() == AnnotationValue.Kind.BOOLEAN) {
            ac.addValue(member.name(), member.asBoolean());
        } else if (member.kind() == AnnotationValue.Kind.BYTE) {
            ac.addValue(member.name(), member.asByte());
        } else if (member.kind() == AnnotationValue.Kind.SHORT) {
            ac.addValue(member.name(), member.asShort());
        } else if (member.kind() == AnnotationValue.Kind.INTEGER) {
            ac.addValue(member.name(), member.asInt());
        } else if (member.kind() == AnnotationValue.Kind.LONG) {
            ac.addValue(member.name(), member.asLong());
        } else if (member.kind() == AnnotationValue.Kind.FLOAT) {
            ac.addValue(member.name(), member.asFloat());
        } else if (member.kind() == AnnotationValue.Kind.DOUBLE) {
            ac.addValue(member.name(), member.asDouble());
        } else if (member.kind() == AnnotationValue.Kind.STRING) {
            ac.addValue(member.name(), member.asString());
        } else if (member.kind() == AnnotationValue.Kind.ARRAY) {
            ac.addValue(member.name(), member.value());
        }
    }
}
 
Example 2
Source File: Beans.java    From quarkus with Apache License 2.0 6 votes vote down vote up
static boolean hasQualifier(ClassInfo requiredInfo, AnnotationInstance required,
        Collection<AnnotationInstance> qualifiers) {
    List<AnnotationValue> binding = new ArrayList<>();
    for (AnnotationValue val : required.values()) {
        if (!requiredInfo.method(val.name()).hasAnnotation(DotNames.NONBINDING)) {
            binding.add(val);
        }
    }
    for (AnnotationInstance qualifier : qualifiers) {
        if (required.name().equals(qualifier.name())) {
            // Must have the same annotation member value for each member which is not annotated @Nonbinding
            boolean matches = true;
            for (AnnotationValue value : binding) {
                if (!value.equals(qualifier.value(value.name()))) {
                    matches = false;
                    break;
                }
            }
            if (matches) {
                return true;
            }
        }
    }
    return false;
}
 
Example 3
Source File: SpringCacheProcessor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private void validateUsage(AnnotationInstance instance) {
    if (instance.target().kind() != AnnotationTarget.Kind.METHOD) {
        throw new IllegalArgumentException(
                "Currently Spring Cache annotations can only be added to methods. Offending instance is annotation '"
                        + instance + "' on " + instance.target() + "'");
    }
    List<AnnotationValue> values = instance.values();
    List<String> unsupportedValues = new ArrayList<>();
    for (AnnotationValue value : values) {
        if (CURRENTLY_UNSUPPORTED_ANNOTATION_VALUES.contains(value.name())) {
            unsupportedValues.add(value.name());
        }
    }
    if (!unsupportedValues.isEmpty()) {
        throw new IllegalArgumentException("Annotation '" +
                instance + "' on '" + instance.target()
                + "' contains the following currently unsupported annotation values: "
                + String.join(", ", unsupportedValues));
    }
}
 
Example 4
Source File: CustomQueryMethodsAdder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private void verifyQueryAnnotation(AnnotationInstance queryInstance, String methodName, String repositoryName) {
    List<AnnotationValue> values = queryInstance.values();
    for (AnnotationValue value : values) {
        if (!QUERY_VALUE_FIELD.equals(value.name()) && !QUERY_COUNT_FIELD.equals(value.name())) {
            throw new IllegalArgumentException("Attribute " + value.name() + " of @Query is currently not supported. " +
                    "Offending method is " + methodName + " of Repository " + repositoryName);
        }
    }
    if (queryInstance.value(QUERY_VALUE_FIELD) == null) {
        throw new IllegalArgumentException("'value' attribute must be specified on @Query annotation of method. " +
                "Offending method is " + methodName + " of Repository " + repositoryName);
    }
}
 
Example 5
Source File: SpringScheduledProcessor.java    From quarkus with Apache License 2.0 4 votes vote down vote up
void processSpringScheduledAnnotation(BuildProducer<ScheduledBusinessMethodItem> scheduledBusinessMethods,
        BeanInfo bean, MethodInfo method, List<AnnotationInstance> scheduledAnnotations) {
    List<AnnotationInstance> schedules = new ArrayList<>();
    if (scheduledAnnotations != null) {
        for (AnnotationInstance scheduledAnnotation : scheduledAnnotations) {
            List<AnnotationValue> springAnnotationValues = scheduledAnnotation.values();
            List<AnnotationValue> confValues = new ArrayList<>();
            if (!springAnnotationValues.isEmpty()) {
                if (annotationsValuesContain(springAnnotationValues, "fixedRate")
                        || annotationsValuesContain(springAnnotationValues, "fixedRateString")) {
                    confValues.add(buildEveryParam(springAnnotationValues));
                    if (annotationsValuesContain(springAnnotationValues, "initialDelay")
                            || annotationsValuesContain(springAnnotationValues, "initialDelayString")) {
                        confValues.addAll(buildDelayParams(springAnnotationValues));
                    }

                } else if (annotationsValuesContain(springAnnotationValues, "fixedDelay")
                        || annotationsValuesContain(springAnnotationValues, "fixedDelayString")) {
                    throw new IllegalArgumentException(
                            "Invalid @Scheduled method '" + method.name()
                                    + "': 'fixedDelay' not supported");
                } else if (annotationsValuesContain(springAnnotationValues, "cron")) {
                    if (annotationsValuesContain(springAnnotationValues, "initialDelay")) {
                        throw new IllegalArgumentException(
                                "Invalid @Scheduled method '" + method.name()
                                        + "': 'initialDelay' not supported for cron triggers");
                    }
                    confValues.add(buildCronParam(springAnnotationValues));
                }

            }
            AnnotationInstance regularAnnotationInstance = AnnotationInstance.create(QUARKUS_SCHEDULED,
                    scheduledAnnotation.target(), confValues);
            schedules.add(regularAnnotationInstance);
        }
        if (schedules != null) {
            scheduledBusinessMethods.produce(new ScheduledBusinessMethodItem(bean, method, schedules));
            LOGGER.debugf("Found scheduled business method %s declared on %s", method, bean);
        }
    }
}
 
Example 6
Source File: JandexUtil.java    From smallrye-open-api with Apache License 2.0 2 votes vote down vote up
/**
 * Returns true if the given annotation is void of any values (and thus is "empty"). An example
 * of this would be if a jax-rs method were annotated with @Tag()
 * 
 * @param annotation AnnotationInstance
 * @return Whether it's empty
 */
public static boolean isEmpty(AnnotationInstance annotation) {
    return annotation.values() == null || annotation.values().isEmpty();
}