Java Code Examples for org.jboss.jandex.AnnotationValue

The following examples show how to use org.jboss.jandex.AnnotationValue. These examples are extracted from open source projects. 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 Project: quarkus   Source File: ResteasyCommonProcessor.java    License: Apache License 2.0 6 votes vote down vote up
private boolean restJsonSupportNeeded(CombinedIndexBuildItem indexBuildItem, DotName mediaTypeAnnotation) {
    for (AnnotationInstance annotationInstance : indexBuildItem.getIndex().getAnnotations(mediaTypeAnnotation)) {
        final AnnotationValue annotationValue = annotationInstance.value();
        if (annotationValue == null) {
            continue;
        }

        List<String> mediaTypes = Collections.emptyList();
        if (annotationValue.kind() == Kind.ARRAY) {
            mediaTypes = Arrays.asList(annotationValue.asStringArray());
        } else if (annotationValue.kind() == Kind.STRING) {
            mediaTypes = Collections.singletonList(annotationValue.asString());
        }
        return mediaTypes.contains(MediaType.APPLICATION_JSON)
                || mediaTypes.contains(MediaType.APPLICATION_JSON_PATCH_JSON);
    }

    return false;
}
 
Example 2
Source Project: smallrye-graphql   Source File: SchemaBuilder.java    License: Apache License 2.0 6 votes vote down vote up
private void addErrors(Schema schema) {
    Collection<AnnotationInstance> errorAnnotations = ScanningContext.getIndex().getAnnotations(Annotations.ERROR_CODE);
    if (errorAnnotations != null && !errorAnnotations.isEmpty()) {
        for (AnnotationInstance errorAnnotation : errorAnnotations) {
            AnnotationTarget annotationTarget = errorAnnotation.target();
            if (annotationTarget.kind().equals(AnnotationTarget.Kind.CLASS)) {
                ClassInfo exceptionClass = annotationTarget.asClass();
                AnnotationValue value = errorAnnotation.value();
                if (value != null && value.asString() != null && !value.asString().isEmpty()) {
                    schema.addError(new ErrorInfo(exceptionClass.name().toString(), value.asString()));
                } else {
                    LOG.warn("Ignoring @ErrorCode on " + annotationTarget.toString() + " - Annotation value is not set");
                }
            } else {
                LOG.warn("Ignoring @ErrorCode on " + annotationTarget.toString() + " - Wrong target, only apply to CLASS ["
                        + annotationTarget.kind().toString() + "]");
            }

        }
    }

}
 
Example 3
Source Project: quarkus   Source File: TemplateDataBuilder.java    License: Apache License 2.0 6 votes vote down vote up
public AnnotationInstance build() {
    AnnotationValue ignoreValue;
    if (ignores.isEmpty()) {
        ignoreValue = AnnotationValue.createArrayValue(ValueResolverGenerator.IGNORE, new AnnotationValue[] {});
    } else {
        AnnotationValue[] values = new AnnotationValue[ignores.size()];
        for (int i = 0; i < ignores.size(); i++) {
            values[i] = AnnotationValue.createStringValue(ValueResolverGenerator.IGNORE + i, ignores.get(i));
        }
        ignoreValue = AnnotationValue.createArrayValue(ValueResolverGenerator.IGNORE, values);
    }
    AnnotationValue propertiesValue = AnnotationValue.createBooleanValue(ValueResolverGenerator.PROPERTIES, properties);
    AnnotationValue ignoreSuperclassesValue = AnnotationValue.createBooleanValue(ValueResolverGenerator.IGNORE_SUPERCLASSES,
            ignoreSuperclasses);
    return AnnotationInstance.create(ValueResolverGenerator.TEMPLATE_DATA, null,
            new AnnotationValue[] { ignoreValue, propertiesValue, ignoreSuperclassesValue });
}
 
Example 4
Source Project: gizmo   Source File: AnnotatedElement.java    License: 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 5
Source Project: smallrye-open-api   Source File: JaxRsAnnotationScanner.java    License: Apache License 2.0 6 votes vote down vote up
static Optional<String[]> getMediaTypes(MethodInfo resourceMethod, DotName annotationName) {
    AnnotationInstance annotation = resourceMethod.annotation(annotationName);

    if (annotation == null) {
        annotation = JandexUtil.getClassAnnotation(resourceMethod.declaringClass(), annotationName);
    }

    if (annotation != null) {
        AnnotationValue annotationValue = annotation.value();

        if (annotationValue != null) {
            return Optional.of(annotationValue.asStringArray());
        }

        return Optional.of(OpenApiConstants.DEFAULT_MEDIA_TYPES.get());
    }

    return Optional.empty();
}
 
Example 6
Source Project: smallrye-open-api   Source File: ParameterProcessor.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Read a single annotation that is either {@link @Parameter} or
 * {@link @Parameters}. The results are stored in the private {@link #params}
 * collection.
 *
 * @param annotation a parameter annotation to be read and processed
 */
void readParameterAnnotation(AnnotationInstance annotation) {
    DotName name = annotation.name();

    if (ParameterConstant.DOTNAME_PARAMETER.equals(name)) {
        readAnnotatedType(annotation, null, false);
    } else if (ParameterConstant.DOTNAME_PARAMETERS.equals(name)) {
        AnnotationValue annotationValue = annotation.value();

        if (annotationValue != null) {
            /*
             * Unwrap annotations wrapped by @Parameters and
             * identify the target as the target of the @Parameters annotation
             */
            for (AnnotationInstance nested : annotationValue.asNestedArray()) {
                readAnnotatedType(AnnotationInstance.create(nested.name(),
                        annotation.target(),
                        nested.values()),
                        null,
                        false);
            }
        }
    }
}
 
Example 7
Source Project: quarkus   Source File: SpringCacheProcessor.java    License: 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 8
Source Project: smallrye-open-api   Source File: ParameterProcessor.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Scan and parse a Spring DefaultValue property on the mapping annotation.
 * If the target is a Java primitive, the value will be parsed into an equivalent
 * wrapper object.
 *
 * @param target target annotated with a Spring mapping
 * @return the default value
 */
static Object getDefaultValue(AnnotationTarget target) {
    AnnotationInstance defaultValueAnno = TypeUtil.getAnnotation(target, SpringConstants.QUERY_PARAM);
    Object defaultValue = null;

    if (defaultValueAnno != null) {
        AnnotationValue value = defaultValueAnno.value("defaultValue");
        if (value != null && !value.asString().isEmpty()) {
            String defaultValueString = value.asString();
            defaultValue = defaultValueString;
            Type targetType = getType(target);

            if (targetType != null && targetType.kind() == Type.Kind.PRIMITIVE) {
                Primitive primitive = targetType.asPrimitiveType().primitive();
                Object primitiveValue = primitiveToObject(primitive, defaultValueString);

                if (primitiveValue != null) {
                    defaultValue = primitiveValue;
                }
            }
        }
    }
    return defaultValue;
}
 
Example 9
Source Project: smallrye-open-api   Source File: SpringAnnotationScanner.java    License: Apache License 2.0 6 votes vote down vote up
static Optional<String[]> getMediaTypes(MethodInfo resourceMethod, MediaTypeProperty property) {
    Set<DotName> annotationNames = SpringConstants.HTTP_METHODS;

    for (DotName annotationName : annotationNames) {
        AnnotationInstance annotation = resourceMethod.annotation(annotationName);

        if (annotation == null || annotation.value(property.name()) == null) {
            annotation = JandexUtil.getClassAnnotation(resourceMethod.declaringClass(), SpringConstants.REQUEST_MAPPING);
        }

        if (annotation != null) {
            AnnotationValue annotationValue = annotation.value(property.name());

            if (annotationValue != null) {
                return Optional.of(annotationValue.asStringArray());
            }

            return Optional.of(OpenApiConstants.DEFAULT_MEDIA_TYPES.get());
        }
    }
    return Optional.empty();
}
 
Example 10
Source Project: quarkus   Source File: SpringDIProcessor.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Meant to be called with instances of @Bean
 */
private String getBeanNameFromBeanInstance(AnnotationInstance annotationInstance) {
    if (annotationInstance.target().kind() != AnnotationTarget.Kind.METHOD) {
        throw new IllegalStateException(
                "AnnotationInstance " + annotationInstance + " is an invalid target. Only Method targets are supported");
    }

    String beanName = null;
    final AnnotationValue beanNameAnnotationValue = annotationInstance.value("name");
    if (beanNameAnnotationValue != null) {
        beanName = determineName(beanNameAnnotationValue);
    }
    if (beanName == null || beanName.isEmpty()) {
        final AnnotationValue beanValueAnnotationValue = annotationInstance.value();
        if (beanNameAnnotationValue != null) {
            beanName = determineName(beanValueAnnotationValue);
        }
    }
    if (beanName == null || beanName.isEmpty()) {
        beanName = annotationInstance.target().asMethod().name();
    }

    return beanName;
}
 
Example 11
Source Project: smallrye-open-api   Source File: ExampleReader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Reads a map of Example annotations.
 *
 * @param annotationValue map of {@literal @}ExampleObject annotations
 * @return Map of Example model
 */
public static Map<String, Example> readExamples(final AnnotationValue annotationValue) {
    if (annotationValue == null) {
        return null;
    }
    IoLogging.log.annotationsMap("@ExampleObject");
    Map<String, Example> examples = new LinkedHashMap<>();
    AnnotationInstance[] nestedArray = annotationValue.asNestedArray();
    for (AnnotationInstance nested : nestedArray) {
        String name = JandexUtil.stringValue(nested, ExampleConstant.PROP_NAME);
        if (name == null && JandexUtil.isRef(nested)) {
            name = JandexUtil.nameFromRef(nested);
        }
        if (name != null) {
            examples.put(name, readExample(nested));
        }
    }
    return examples;
}
 
Example 12
Source Project: smallrye-open-api   Source File: InfoReader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Annotation to Info
 * 
 * @param annotationValue the {@literal @}Info annotation
 * @return Info model
 */
public static Info readInfo(final AnnotationValue annotationValue) {
    if (annotationValue == null) {
        return null;
    }
    IoLogging.log.annotation("@Info");
    AnnotationInstance nested = annotationValue.asNested();

    Info info = new InfoImpl();
    info.setTitle(JandexUtil.stringValue(nested, InfoConstant.PROP_TITLE));
    info.setDescription(JandexUtil.stringValue(nested, InfoConstant.PROP_DESCRIPTION));
    info.setTermsOfService(JandexUtil.stringValue(nested, InfoConstant.PROP_TERMS_OF_SERVICE));
    info.setContact(ContactReader.readContact(nested.value(InfoConstant.PROP_CONTACT)));
    info.setLicense(LicenseReader.readLicense(nested.value(InfoConstant.PROP_LICENSE)));
    info.setVersion(JandexUtil.stringValue(nested, InfoConstant.PROP_VERSION));
    return info;
}
 
Example 13
Source Project: quarkus   Source File: InterceptorResolver.java    License: Apache License 2.0 6 votes vote down vote up
private boolean isInterceptorBinding(AnnotationInstance interceptorBinding, AnnotationInstance candidate) {
    ClassInfo interceptorBindingClass = beanDeployment.getInterceptorBinding(interceptorBinding.name());
    if (candidate.name().equals(interceptorBinding.name())) {
        // Must have the same annotation member value for each member which is not annotated @Nonbinding
        boolean matches = true;
        Set<String> nonBindingFields = beanDeployment.getNonBindingFields(interceptorBinding.name());
        for (AnnotationValue value : candidate.valuesWithDefaults(beanDeployment.getIndex())) {
            String annotationField = value.name();
            if (!interceptorBindingClass.method(annotationField).hasAnnotation(DotNames.NONBINDING)
                    && !nonBindingFields.contains(annotationField)
                    && !value.equals(interceptorBinding.valueWithDefault(beanDeployment.getIndex(), annotationField))) {
                matches = false;
                break;
            }
        }
        if (matches) {
            return true;
        }
    }
    return false;
}
 
Example 14
Source Project: smallrye-open-api   Source File: RequestBodyReader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Reads a map of RequestBody annotations.
 * 
 * @param context the scanning context
 * @param annotationValue map of {@literal @}RequestBody annotations
 * @return Map of RequestBody model
 */
public static Map<String, RequestBody> readRequestBodies(final AnnotationScannerContext context,
        final AnnotationValue annotationValue) {
    if (annotationValue == null) {
        return null;
    }
    IoLogging.log.annotationsMap("@RequestBody");
    Map<String, RequestBody> requestBodies = new LinkedHashMap<>();
    AnnotationInstance[] nestedArray = annotationValue.asNestedArray();
    for (AnnotationInstance nested : nestedArray) {
        String name = JandexUtil.stringValue(nested, RequestBodyConstant.PROP_NAME);
        if (name == null && JandexUtil.isRef(nested)) {
            name = JandexUtil.nameFromRef(nested);
        }
        if (name != null) {
            requestBodies.put(name, readRequestBody(context, nested));
        }
    }
    return requestBodies;
}
 
Example 15
Source Project: smallrye-open-api   Source File: LinkReader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Reads Link annotations
 * 
 * @param annotationValue map of {@literal @}Link annotations
 * @return Map of Link model
 */
public static Map<String, Link> readLinks(final AnnotationValue annotationValue) {
    if (annotationValue == null) {
        return null;
    }
    IoLogging.log.annotationsMap("@Link");
    Map<String, Link> links = new LinkedHashMap<>();
    AnnotationInstance[] nestedArray = annotationValue.asNestedArray();
    for (AnnotationInstance nested : nestedArray) {
        String name = JandexUtil.stringValue(nested, LinkConstant.PROP_NAME);
        if (name == null && JandexUtil.isRef(nested)) {
            name = JandexUtil.nameFromRef(nested);
        }
        if (name != null) {
            links.put(name, readLink(nested));
        }
    }
    return links;
}
 
Example 16
Source Project: smallrye-open-api   Source File: ResponseReader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Reads an array of APIResponse annotations into an {@link APIResponses} model.
 * 
 * @param context the scanning context
 * @param annotationValue {@literal @}APIResponse annotation
 * @return APIResponses model
 */
public static APIResponses readResponses(final AnnotationScannerContext context,
        final AnnotationValue annotationValue) {
    if (annotationValue == null) {
        return null;
    }
    IoLogging.log.annotationsListInto("@APIResponse", "APIResponses model");
    APIResponses responses = new APIResponsesImpl();
    AnnotationInstance[] nestedArray = annotationValue.asNestedArray();
    for (AnnotationInstance nested : nestedArray) {
        String responseCode = JandexUtil.stringValue(nested, ResponseConstant.PROP_RESPONSE_CODE);
        if (responseCode != null) {
            responses.addAPIResponse(responseCode,
                    ResponseReader.readResponse(context, nested));
        }
    }
    return responses;
}
 
Example 17
Source Project: smallrye-open-api   Source File: OAuthReader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Reads an array of OAuthScope annotations into a Scopes model.
 * 
 * @param annotationValue {@literal @}OAuthScope annotation
 * @return Map of name and description of the scope
 */
// TODO: Update return type and remove warning suppression for MicroProfile OpenAPI 2.0
@SuppressWarnings("deprecation")
private static Scopes readOAuthScopes(final AnnotationValue annotationValue) {
    if (annotationValue == null) {
        return null;
    }
    IoLogging.log.annotationsList("@OAuthScope");
    AnnotationInstance[] nestedArray = annotationValue.asNestedArray();
    Scopes scopes = new ScopesImpl();
    for (AnnotationInstance nested : nestedArray) {
        String name = JandexUtil.stringValue(nested, SecuritySchemeConstant.PROP_NAME);
        if (name != null) {
            String description = JandexUtil.stringValue(nested, SecuritySchemeConstant.PROP_DESCRIPTION);
            scopes.put(name, description);
        }
    }
    return scopes;
}
 
Example 18
Source Project: smallrye-open-api   Source File: CallbackReader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Reads a map of Callback annotations.
 * 
 * @param context the scanner context
 * @param annotationValue Map of {@literal @}Callback annotations
 * @return Map of Callback models
 */
public static Map<String, Callback> readCallbacks(final AnnotationScannerContext context,
        final AnnotationValue annotationValue) {
    if (annotationValue == null) {
        return null;
    }
    IoLogging.log.annotationsMap("@Callback");
    Map<String, Callback> callbacks = new LinkedHashMap<>();
    AnnotationInstance[] nestedArray = annotationValue.asNestedArray();
    for (AnnotationInstance nested : nestedArray) {
        String name = getCallbackName(nested);
        if (name == null && JandexUtil.isRef(nested)) {
            name = JandexUtil.nameFromRef(nested);
        }
        if (name != null) {
            callbacks.put(name, readCallback(context, nested));
        }
    }
    return callbacks;
}
 
Example 19
Source Project: smallrye-open-api   Source File: EncodingReader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Reads an array of Encoding annotations as a Map.
 * 
 * @param context the scanning context
 * @param annotationValue Map of {@literal @}Encoding annotations
 * @return Map of Encoding models
 */
public static Map<String, Encoding> readEncodings(final AnnotationScannerContext context,
        final AnnotationValue annotationValue) {
    if (annotationValue == null) {
        return null;
    }
    IoLogging.log.annotationsMap("@Encoding");
    Map<String, Encoding> encodings = new LinkedHashMap<>();
    AnnotationInstance[] nestedArray = annotationValue.asNestedArray();
    for (AnnotationInstance annotation : nestedArray) {
        String name = JandexUtil.stringValue(annotation, EncodingConstant.PROP_NAME);
        if (name != null) {
            encodings.put(name, readEncoding(context, annotation));
        }
    }
    return encodings;
}
 
Example 20
Source Project: quarkus   Source File: InterfaceConfigPropertiesUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Add a method like this:
 * 
 * <pre>
 *  &#64;Produces
 *  public SomeConfig produceSomeClass(Config config) {
 *      return new SomeConfigQuarkusImpl(config)
 *  }
 * </pre>
 */
static void addProducerMethodForInterfaceConfigProperties(ClassCreator classCreator, DotName interfaceName,
        String prefix, boolean needsQualifier, String generatedClassName) {
    String methodName = "produce" + interfaceName.withoutPackagePrefix();
    if (needsQualifier) {
        // we need to differentiate the different producers of the same class
        methodName = methodName + "WithPrefix" + HashUtil.sha1(prefix);
    }
    try (MethodCreator method = classCreator.getMethodCreator(methodName, interfaceName.toString(),
            Config.class.getName())) {

        method.addAnnotation(Produces.class);
        if (needsQualifier) {
            method.addAnnotation(AnnotationInstance.create(DotNames.CONFIG_PREFIX, null,
                    new AnnotationValue[] { AnnotationValue.createStringValue("value", prefix) }));
        } else {
            method.addAnnotation(Default.class);
        }
        method.returnValue(method.newInstance(MethodDescriptor.ofConstructor(generatedClassName, Config.class),
                method.getMethodParam(0)));
    }
}
 
Example 21
Source Project: smallrye-open-api   Source File: PathsReader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Reads the PathItem.
 * Also used in CallbackOperation
 * 
 * @param context the scanning context
 * @param annotationValue the annotation value
 * @return PathItem model
 */
public static PathItem readPathItem(final AnnotationScannerContext context,
        final AnnotationValue annotationValue) {
    if (annotationValue == null) {
        return null;
    }

    AnnotationInstance[] nestedArray = annotationValue.asNestedArray();
    PathItem pathItem = new PathItemImpl();
    for (AnnotationInstance operationAnno : nestedArray) {
        String method = JandexUtil.stringValue(operationAnno, PathsConstant.PROP_METHOD);
        Operation operation = OperationReader.readOperation(context, operationAnno);
        if (method == null) {
            continue;
        }
        try {
            PropertyDescriptor descriptor = new PropertyDescriptor(method.toUpperCase(), pathItem.getClass());
            Method mutator = descriptor.getWriteMethod();
            mutator.invoke(pathItem, operation);
        } catch (IntrospectionException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
            IoLogging.log.readingCallbackOperation(e);
        }
    }
    return pathItem;
}
 
Example 22
Source Project: smallrye-open-api   Source File: ServerVariableReader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Reads an array of ServerVariable annotations, returning a new {@link ServerVariable} model. The
 * annotation value is an array of ServerVariable annotations.
 * 
 * @param annotationValue an arrays of {@literal @}ServerVariable annotations
 * @return a Map of Variable name and ServerVariable model
 */
public static Map<String, ServerVariable> readServerVariables(final AnnotationValue annotationValue) {
    if (annotationValue == null) {
        return null;
    }
    IoLogging.log.annotationsArray("@ServerVariable");
    AnnotationInstance[] nestedArray = annotationValue.asNestedArray();
    Map<String, ServerVariable> variables = new LinkedHashMap<>();
    for (AnnotationInstance serverVariableAnno : nestedArray) {
        String name = JandexUtil.stringValue(serverVariableAnno, ServerVariableConstant.PROP_NAME);
        if (name != null) {
            variables.put(name, readServerVariable(serverVariableAnno));
        }
    }
    return variables;
}
 
Example 23
Source Project: quarkus   Source File: Types.java    License: Apache License 2.0 6 votes vote down vote up
static Set<Type> restrictBeanTypes(Set<Type> types, Collection<AnnotationInstance> annotations) {
    AnnotationInstance typed = annotations.stream().filter(a -> a.name().equals(DotNames.TYPED))
            .findFirst().orElse(null);
    if (typed != null) {
        AnnotationValue typedValue = typed.value();
        if (typedValue == null) {
            types.clear();
            types.add(OBJECT_TYPE);
        } else {
            Set<DotName> typedClasses = new HashSet<>();
            for (Type type : typedValue.asClassArray()) {
                typedClasses.add(type.name());
            }
            for (Iterator<Type> iterator = types.iterator(); iterator.hasNext();) {
                Type nextType = iterator.next();
                if (!typedClasses.contains(nextType.name()) && !DotNames.OBJECT.equals(nextType.name())) {
                    iterator.remove();
                }
            }
        }
    }
    return types;
}
 
Example 24
Source Project: quarkus   Source File: UndertowBuildStep.java    License: Apache License 2.0 5 votes vote down vote up
private List<ParamValueMetaData> getInitParams(AnnotationValue initParamsValue) {
    List<ParamValueMetaData> paramValuesMetaData = new ArrayList<>();
    if (initParamsValue == null) {
        return paramValuesMetaData;
    }

    AnnotationInstance[] initParamsAnnotations = initParamsValue.asNestedArray();
    if (initParamsAnnotations != null && initParamsAnnotations.length > 0) {
        for (AnnotationInstance initParamsAnnotation : initParamsAnnotations) {
            ParamValueMetaData initParam = new ParamValueMetaData();
            AnnotationValue initParamName = initParamsAnnotation.value("name");
            AnnotationValue initParamValue = initParamsAnnotation.value();
            AnnotationValue initParamDescription = initParamsAnnotation.value("description");
            initParam.setParamName(initParamName.asString());
            initParam.setParamValue(initParamValue.asString());
            if (initParamDescription != null) {
                Descriptions descriptions = getDescription(initParamDescription.asString());
                if (descriptions != null) {
                    initParam.setDescriptions(descriptions);
                }
            }
            paramValuesMetaData.add(initParam);
        }
    }

    return paramValuesMetaData;
}
 
Example 25
Source Project: quarkus   Source File: JsonbProcessor.java    License: Apache License 2.0 5 votes vote down vote up
private void registerInstance(BuildProducer<ReflectiveClassBuildItem> reflectiveClass, AnnotationInstance instance) {
    AnnotationTarget annotationTarget = instance.target();
    if (FIELD.equals(annotationTarget.kind()) || METHOD.equals(annotationTarget.kind())) {
        AnnotationValue value = instance.value();
        if (value != null) {
            // the Deserializers are constructed internally by JSON-B using a no-args constructor
            reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, value.asClass().toString()));
        }
    }
}
 
Example 26
Source Project: quarkus   Source File: SmallRyeFaultToleranceProcessor.java    License: Apache License 2.0 5 votes vote down vote up
@BuildStep
AnnotationsTransformerBuildItem transformInterceptorPriority(BeanArchiveIndexBuildItem index) {
    return new AnnotationsTransformerBuildItem(new AnnotationsTransformer() {
        @Override
        public boolean appliesTo(Kind kind) {
            return kind == Kind.CLASS;
        }

        @Override
        public void transform(TransformationContext ctx) {
            if (ctx.isClass()) {
                if (!ctx.getTarget().asClass().name().toString()
                        .equals("io.smallrye.faulttolerance.FaultToleranceInterceptor")) {
                    return;
                }
                final Config config = ConfigProvider.getConfig();

                OptionalInt priority = config.getValue("mp.fault.tolerance.interceptor.priority", OptionalInt.class);
                if (priority.isPresent()) {
                    ctx.transform()
                            .remove(ann -> ann.name().toString().equals(Priority.class.getName()))
                            .add(Priority.class, AnnotationValue.createIntegerValue("value", priority.getAsInt()))
                            .done();
                }
            }
        }
    });
}
 
Example 27
Source Project: quarkus   Source File: HibernateUserTypeProcessor.java    License: Apache License 2.0 5 votes vote down vote up
private Set<String> getUserTypes(Collection<AnnotationInstance> typeDefinitionAnnotationInstances) {
    final Set<String> userTypes = new HashSet<>();

    for (AnnotationInstance typeDefAnnotationInstance : typeDefinitionAnnotationInstances) {
        final AnnotationValue typeClassValue = typeDefAnnotationInstance.value(TYPE_CLASS_VALUE);
        if (typeClassValue == null) {
            continue;
        }

        final String typeClass = typeClassValue.asClass().name().toString();
        userTypes.add(typeClass);
    }

    return userTypes;
}
 
Example 28
Source Project: smallrye-graphql   Source File: TypeNameHelper.java    License: Apache License 2.0 5 votes vote down vote up
private static String getNameForClassType(ClassInfo classInfo, Annotations annotations, DotName typeName, String postFix) {
    if (annotations.containsKeyAndValidValue(typeName)) {
        AnnotationValue annotationValue = annotations.getAnnotationValue(typeName);
        return annotationValue.asString().trim();
    } else if (annotations.containsKeyAndValidValue(Annotations.NAME)) {
        return annotations.getAnnotationValue(Annotations.NAME).asString().trim();
    }

    return classInfo.name().local() + postFix;
}
 
Example 29
Source Project: quarkus   Source File: AddObservesTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void transform(TransformationContext transformationContext) {
    MethodInfo method = transformationContext.getTarget().asMethod();
    if (method.name().equals("observe")) {
        transformationContext.transform()
                .add(AnnotationInstance.create(DotName.createSimple(Observes.class.getName()),
                        MethodParameterInfo.create(method, (short) 0), new AnnotationValue[] {}))
                .done();
    }
}
 
Example 30
Source Project: gizmo   Source File: AnnotationTestCase.java    License: Apache License 2.0 5 votes vote down vote up
private void addAnnotationWithAnnotationValueArray(AnnotatedElement element) {
    AnnotationInstance annotation = AnnotationInstance.create(DotName.createSimple(MyArrayAnnotation.class.getName()), null,
            new AnnotationValue[] {
                    AnnotationValue.createArrayValue("value",
                            new AnnotationValue[] {
                                    AnnotationValue.createStringValue("value", "test")
                            }
                    )
            }
    );
    element.addAnnotation(annotation);
}