org.jboss.jandex.AnnotationInstance Java Examples

The following examples show how to use org.jboss.jandex.AnnotationInstance. 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: ResteasyCommonProcessor.java    From quarkus with 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 File: PathsReader.java    From smallrye-open-api with 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 #3
Source File: ResponseReader.java    From smallrye-open-api with 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 #4
Source File: StockMethodsAdder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private AnnotationTarget getIdAnnotationTargetRec(DotName currentDotName, IndexView index, DotName originalEntityDotName) {
    ClassInfo classInfo = index.getClassByName(currentDotName);
    if (classInfo == null) {
        throw new IllegalStateException("Entity " + originalEntityDotName + " was not part of the Quarkus index");
    }

    if (!classInfo.annotations().containsKey(DotNames.JPA_ID)) {
        if (DotNames.OBJECT.equals(classInfo.superName())) {
            throw new IllegalArgumentException("Currently only Entities with the @Id annotation are supported. " +
                    "Offending class is " + originalEntityDotName);
        }
        return getIdAnnotationTargetRec(classInfo.superName(), index, originalEntityDotName);
    }

    List<AnnotationInstance> annotationInstances = classInfo.annotations().get(DotNames.JPA_ID);
    if (annotationInstances.size() > 1) {
        throw new IllegalArgumentException(
                "Currently the @Id annotation can only be placed on a single field or method. " +
                        "Offending class is " + originalEntityDotName);
    }

    return annotationInstances.get(0).target();
}
 
Example #5
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 #6
Source File: SpringAnnotationScanner.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
/**
 * Find and process all Spring Controllers
 * TODO: Also support org.springframework.stereotype.Controller annotations ?
 *
 * @param context the scanning context
 * @param openApi the openAPI model
 */
private void processControllerClasses(final AnnotationScannerContext context, OpenAPI openApi) {
    // Get all Spring controllers and convert them to OpenAPI models (and merge them into a single one)
    Collection<AnnotationInstance> controllerAnnotations = context.getIndex()
            .getAnnotations(SpringConstants.REST_CONTROLLER);
    List<ClassInfo> applications = new ArrayList<>();
    for (AnnotationInstance annotationInstance : controllerAnnotations) {
        if (annotationInstance.target().kind().equals(AnnotationTarget.Kind.CLASS)) {
            ClassInfo classInfo = annotationInstance.target().asClass();
            applications.add(classInfo);
        } else {
            SpringLogging.log.ignoringAnnotation(SpringConstants.REST_CONTROLLER.withoutPackagePrefix());
        }
    }

    // this can be a useful extension point to set/override the application path
    processScannerExtensions(context, applications);

    for (ClassInfo controller : applications) {
        OpenAPI applicationOpenApi = processControllerClass(context, controller);
        openApi = MergeUtil.merge(openApi, applicationOpenApi);
    }
}
 
Example #7
Source File: MediaTypeReader.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
/**
 * Reads a single Content annotation into a {@link MediaType} model.
 * 
 * @param context the scanning context
 * @param annotationInstance {@literal @}Content annotation
 * @return MediaType model
 */
public static MediaType readMediaType(final AnnotationScannerContext context,
        final AnnotationInstance annotationInstance) {
    if (annotationInstance == null) {
        return null;
    }
    IoLogging.log.singleAnnotationAs("@Content", "MediaType");
    MediaType mediaType = new MediaTypeImpl();
    mediaType.setExamples(ExampleReader.readExamples(annotationInstance.value(MediaTypeConstant.PROP_EXAMPLES)));
    mediaType.setExample(JandexUtil.stringValue(annotationInstance, MediaTypeConstant.PROP_EXAMPLE));
    mediaType.setSchema(SchemaFactory.readSchema(context.getIndex(),
            annotationInstance.value(MediaTypeConstant.PROP_SCHEMA)));
    mediaType.setEncoding(
            EncodingReader.readEncodings(context, annotationInstance.value(MediaTypeConstant.PROP_ENCODING)));
    return mediaType;
}
 
Example #8
Source File: SpringDIProcessor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@BuildStep
SpringBeanNameToDotNameBuildItem createBeanNamesMap(BeanArchiveIndexBuildItem beanArchiveIndexBuildItem) {
    final Map<String, DotName> result = new HashMap<>();

    final IndexView index = beanArchiveIndexBuildItem.getIndex();
    final Collection<AnnotationInstance> stereotypeInstances = new ArrayList<>();
    stereotypeInstances.addAll(index.getAnnotations(SPRING_COMPONENT));
    stereotypeInstances.addAll(index.getAnnotations(SPRING_REPOSITORY));
    stereotypeInstances.addAll(index.getAnnotations(SPRING_SERVICE));
    for (AnnotationInstance stereotypeInstance : stereotypeInstances) {
        if (stereotypeInstance.target().kind() != AnnotationTarget.Kind.CLASS) {
            continue;
        }
        result.put(getBeanNameFromStereotypeInstance(stereotypeInstance), stereotypeInstance.target().asClass().name());
    }

    for (AnnotationInstance beanInstance : index.getAnnotations(BEAN_ANNOTATION)) {
        if (beanInstance.target().kind() != AnnotationTarget.Kind.METHOD) {
            continue;
        }
        result.put(getBeanNameFromBeanInstance(beanInstance), beanInstance.target().asMethod().returnType().name());
    }

    return new SpringBeanNameToDotNameBuildItem(result);
}
 
Example #9
Source File: JandexUtil.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
/**
 * Reads a string property named "ref" value from the given annotation and converts it
 * to a value appropriate for setting on a model's "$ref" property.
 * 
 * @param annotation AnnotationInstance
 * @param refType RefType
 * @return String value
 */
public static String refValue(AnnotationInstance annotation, RefType refType) {
    AnnotationValue value = annotation.value(OpenApiConstants.REF);
    if (value == null) {
        return null;
    }

    String ref = value.asString();

    if (!COMPONENT_KEY_PATTERN.matcher(ref).matches()) {
        return ref;
    }

    if (refType != null) {
        ref = "#/components/" + refType.componentPath + "/" + ref;
    } else {
        throw UtilMessages.msg.refTypeNotNull();
    }

    return ref;
}
 
Example #10
Source File: InfoReader.java    From smallrye-open-api with 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 #11
Source File: SchemaFactory.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
/**
 * Reads a Schema annotation into a model.
 *
 * @param index the index
 * @param annotation the annotation instance
 * @return Schema model
 */
public static Schema readSchema(IndexView index, AnnotationInstance annotation) {
    if (annotation == null) {
        return null;
    }
    IoLogging.log.singleAnnotation("@Schema");

    // Schemas can be hidden. Skip if that's the case.
    Optional<Boolean> isHidden = JandexUtil.booleanValue(annotation, SchemaConstant.PROP_HIDDEN);

    if (isHidden.isPresent() && isHidden.get()) {
        return null;
    }

    return readSchema(index, new SchemaImpl(), annotation, Collections.emptyMap());
}
 
Example #12
Source File: TemplateDataBuilder.java    From quarkus with 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 #13
Source File: RestClientProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep
AdditionalBeanBuildItem registerProviderBeans(CombinedIndexBuildItem combinedIndex) {
    IndexView index = combinedIndex.getIndex();
    List<AnnotationInstance> allInstances = new ArrayList<>(index.getAnnotations(REGISTER_PROVIDER));
    for (AnnotationInstance annotation : index.getAnnotations(REGISTER_PROVIDERS)) {
        allInstances.addAll(Arrays.asList(annotation.value().asNestedArray()));
    }
    AdditionalBeanBuildItem.Builder builder = AdditionalBeanBuildItem.builder().setUnremovable();
    for (AnnotationInstance annotationInstance : allInstances) {
        // Make sure all providers not annotated with @Provider but used in @RegisterProvider are registered as beans
        builder.addBeanClass(annotationInstance.value().asClass().toString());
    }
    return builder.build();
}
 
Example #14
Source File: FormatHelper.java    From smallrye-graphql with Apache License 2.0 5 votes vote down vote up
private static Optional<TransformInfo> getNumberFormat(AnnotationInstance annotationInstance) {
    if (annotationInstance != null) {
        String format = getStringValue(annotationInstance);
        String locale = getStringValue(annotationInstance, LOCALE);
        return Optional.of(new TransformInfo(
                TransformInfo.Type.NUMBER,
                format,
                locale,
                isJsonB(annotationInstance)));
    }
    return Optional.empty();
}
 
Example #15
Source File: ServerReader.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
/**
 * Reads any Server annotations.The annotation value is an array of Server annotations.
 * 
 * @param annotationValue an Array of {@literal @}Server annotations
 * @return a List of Server models
 */
public static Optional<List<Server>> readServers(final AnnotationValue annotationValue) {
    if (annotationValue != null) {
        IoLogging.log.annotationsArray("@Server");
        AnnotationInstance[] nestedArray = annotationValue.asNestedArray();
        List<Server> servers = new ArrayList<>();
        for (AnnotationInstance serverAnno : nestedArray) {
            servers.add(readServer(serverAnno));
        }
        return Optional.of(servers);
    }
    return Optional.empty();
}
 
Example #16
Source File: OAuthReader.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
/**
 * Reads an OAuthFlows annotation into a model.
 * 
 * @param annotationValue the annotation value
 * @return OAuthFlows model
 */
public static OAuthFlows readOAuthFlows(final AnnotationValue annotationValue) {
    if (annotationValue == null) {
        return null;
    }
    IoLogging.log.singleAnnotation("@OAuthFlows");
    AnnotationInstance annotation = annotationValue.asNested();
    OAuthFlows flows = new OAuthFlowsImpl();
    flows.setImplicit(readOAuthFlow(annotation.value(SecuritySchemeConstant.PROP_IMPLICIT)));
    flows.setPassword(readOAuthFlow(annotation.value(SecuritySchemeConstant.PROP_PASSWORD)));
    flows.setClientCredentials(readOAuthFlow(annotation.value(SecuritySchemeConstant.PROP_CLIENT_CREDENTIALS)));
    flows.setAuthorizationCode(readOAuthFlow(annotation.value(SecuritySchemeConstant.PROP_AUTHORIZATION_CODE)));
    return flows;
}
 
Example #17
Source File: Annotations.java    From quarkus with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param annotations
 * @param names
 * @return {@code true} if the given collection contains an annotation instance with any of the given names, {@code false}
 *         otherwise
 */
public static boolean containsAny(Collection<AnnotationInstance> annotations, Iterable<DotName> names) {
    if (annotations.isEmpty()) {
        return false;
    }
    for (AnnotationInstance annotationInstance : annotations) {
        for (DotName name : names) {
            if (annotationInstance.name().equals(name)) {
                return true;
            }
        }
    }
    return false;
}
 
Example #18
Source File: JandexUtilTests.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testEnumValue() {
    Index index = IndexScannerTestBase.indexOf(Implementor2.class);
    ClassInfo clazz = index.getClassByName(DotName.createSimple(Implementor2.class.getName()));
    AnnotationInstance annotation = clazz.method("getData")
            .annotation(DotName.createSimple(APIResponse.class.getName()))
            .value("content")
            .asNestedArray()[0]
                    .value("encoding")
                    .asNestedArray()[0];
    Encoding.Style style = JandexUtil.enumValue(annotation, "style", Encoding.Style.class);
    assertEquals(Encoding.Style.PIPE_DELIMITED, style);
}
 
Example #19
Source File: FormatHelper.java    From smallrye-graphql with Apache License 2.0 5 votes vote down vote up
private static Optional<String> getFormat(AnnotationInstance annotationInstance) {
    AnnotationValue locale = annotationInstance.value(LOCALE);
    AnnotationValue format = annotationInstance.value();

    if (format == null && locale == null) {
        return Optional.empty();
    } else if (format == null) {
        return Optional.of(locale.asString());
    } else if (locale == null) {
        return Optional.of(format.asString());
    } else {
        return Optional.of(format.asString() + " " + locale.asString());
    }
}
 
Example #20
Source File: ParameterProcessor.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the "value" parameter from annotation to be used as the name.
 * If no value was specified or an empty value, return the name of the annotation
 * target.
 *
 * @param annotation parameter annotation
 * @return the name of the parameter
 */
static String paramName(AnnotationInstance annotation) {
    AnnotationValue value = annotation.value();
    String valueString = null;

    if (value != null) {
        valueString = value.asString();
        if (valueString.length() > 0) {
            return valueString;
        }
    }

    AnnotationTarget target = annotation.target();

    switch (target.kind()) {
        case FIELD:
            valueString = target.asField().name();
            break;
        case METHOD_PARAMETER:
            valueString = target.asMethodParameter().name();
            break;
        case METHOD:
            // This is a bean property setter
            MethodInfo method = target.asMethod();
            if (method.parameters().size() == 1) {
                String methodName = method.name();

                if (methodName.startsWith("set")) {
                    valueString = Introspector.decapitalize(methodName.substring(3));
                } else {
                    valueString = methodName;
                }
            }
            break;
        default:
            break;
    }

    return valueString;
}
 
Example #21
Source File: SchemaBuilder.java    From smallrye-graphql with Apache License 2.0 5 votes vote down vote up
private Schema generateSchema() {

        // Get all the @GraphQLAPI annotations
        Collection<AnnotationInstance> graphQLApiAnnotations = ScanningContext.getIndex()
                .getAnnotations(Annotations.GRAPHQL_API);

        final Schema schema = new Schema();

        for (AnnotationInstance graphQLApiAnnotation : graphQLApiAnnotations) {
            ClassInfo apiClass = graphQLApiAnnotation.target().asClass();
            List<MethodInfo> methods = apiClass.methods();
            addOperations(schema, methods);
        }

        // The above queries and mutations reference some models (input / type / interfaces / enum), let's create those
        addTypesToSchema(schema);

        // We might have missed something
        addOutstandingTypesToSchema(schema);

        // Add all annotated errors (Exceptions)
        addErrors(schema);

        // Reset the maps. 
        referenceCreator.clear();

        return schema;
    }
 
Example #22
Source File: JandexBeanInfoAdapter.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private Stream<AnnotationInfo> getMetricAnnotationsThroughStereotype(AnnotationInstance stereotypeInstance,
        IndexView indexView) {
    ClassInfo annotationType = indexView.getClassByName(stereotypeInstance.name());
    if (annotationType.classAnnotation(DotNames.STEREOTYPE) != null) {
        JandexAnnotationInfoAdapter adapter = new JandexAnnotationInfoAdapter(indexView);
        return annotationType.classAnnotations()
                .stream()
                .filter(SmallRyeMetricsDotNames::isMetricAnnotation)
                .map(adapter::convert);
    } else {
        return Stream.empty();
    }
}
 
Example #23
Source File: SpringWebProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private AnnotationInstance getSingleControllerAdviceInstance(IndexView index) {
    Collection<AnnotationInstance> controllerAdviceInstances = index.getAnnotations(REST_CONTROLLER_ADVICE);

    if (controllerAdviceInstances.isEmpty()) {
        return null;
    }

    if (controllerAdviceInstances.size() > 1) {
        throw new IllegalStateException("You can only have a single class annotated with @ControllerAdvice");
    }

    return controllerAdviceInstances.iterator().next();
}
 
Example #24
Source File: SpringDIProcessorTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void getAnnotationsToAddExplicitScopeOnConflictWorks() {
    final Map<DotName, Set<DotName>> scopes = processor.getStereotypeScopes(index);
    final ClassInfo target = index
            .getClassByName(DotName.createSimple(OverrideConflictStereotypeBean.class.getName()));

    final Set<AnnotationInstance> ret = processor.getAnnotationsToAdd(target, scopes, null);

    final Set<AnnotationInstance> expected = setOf(
            AnnotationInstance.create(DotName.createSimple(ApplicationScoped.class.getName()), target,
                    Collections.emptyList()));
    assertEquals(expected, ret);
}
 
Example #25
Source File: GenerateYamlLoaderSupportClasses.java    From camel-k-runtime with Apache License 2.0 5 votes vote down vote up
public final TypeSpec generateReifiers() {
    TypeSpec.Builder type = TypeSpec.classBuilder("YamlReifiers");
    type.addModifiers(Modifier.PUBLIC, Modifier.FINAL);

    MethodSpec.Builder mb = MethodSpec.methodBuilder("registerReifiers")
        .addModifiers(Modifier.PUBLIC)
        .addModifiers(Modifier.STATIC);

    annotated(YAML_NODE_DEFINITION_ANNOTATION).forEach(i -> {
        final AnnotationInstance annotation = i.classAnnotation(YAML_NODE_DEFINITION_ANNOTATION);
        final AnnotationValue reifiers = annotation.value("reifiers");

        if (reifiers != null) {
            String name = i.toString();
            if (i.nestingType() == ClassInfo.NestingType.INNER) {
                name = i.enclosingClass().toString() + "." + i.simpleName();
            }

            for (String reifier: reifiers.asStringArray()) {
                mb.addStatement("org.apache.camel.reifier.ProcessorReifier.registerReifier($L.class, $L::new)", name, reifier);
            }
        }
    });

    type.addMethod(mb.build());

    return type.build();
}
 
Example #26
Source File: SpringScheduledProcessorTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testBuildDelayParam() {

    final MethodInfo target = index.getClassByName(DotName.createSimple(BeanWithScheduledMethods.class.getName()))
            .method("checkEverySecondWithDelay");
    AnnotationInstance annotation = target.annotation(SpringScheduledProcessor.SPRING_SCHEDULED);
    List<AnnotationValue> annotationValues = springScheduledProcessor.buildDelayParams(annotation.values());
    AnnotationValue expectedDelayValue = AnnotationValue.createLongValue("delay", 1000L);
    AnnotationValue expectedDelayUnitValue = AnnotationValue.createEnumValue("delayUnit",
            DotName.createSimple("java.util.concurrent.TimeUnit"),
            TimeUnit.MILLISECONDS.name());
    assertThat(annotationValues).contains(expectedDelayValue);
    assertThat(annotationValues).contains(expectedDelayUnitValue);

}
 
Example #27
Source File: SpringSecurityProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private void checksStandardSecurity(AnnotationInstance instance, ClassInfo classInfo) {
    if (hasStandardSecurityAnnotation(classInfo)) {
        Optional<AnnotationInstance> firstStandardSecurityAnnotation = findFirstStandardSecurityAnnotation(classInfo);
        if (firstStandardSecurityAnnotation.isPresent()) {
            String securityAnnotationName = findFirstStandardSecurityAnnotation(classInfo).get().name()
                    .withoutPackagePrefix();
            throw new IllegalArgumentException("An invalid security annotation combination was detected: Found @"
                    + instance.name().withoutPackagePrefix() + " and @" + securityAnnotationName + " on class "
                    + classInfo.simpleName());
        }
    }
}
 
Example #28
Source File: Annotations.java    From quarkus with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param annotations
 * @param name
 * @return the first matching annotation instance with the given name or null
 */
public static AnnotationInstance find(Collection<AnnotationInstance> annotations, DotName name) {
    if (annotations.isEmpty()) {
        return null;
    }
    for (AnnotationInstance annotationInstance : annotations) {
        if (annotationInstance.name().equals(name)) {
            return annotationInstance;
        }
    }
    return null;
}
 
Example #29
Source File: UndertowWebsocketProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private void registerCodersForReflection(BuildProducer<ReflectiveClassBuildItem> reflection,
        Collection<AnnotationInstance> endpoints) {
    for (AnnotationInstance endpoint : endpoints) {
        if (endpoint.target() instanceof ClassInfo) {
            ClassInfo clazz = (ClassInfo) endpoint.target();
            if (!Modifier.isAbstract(clazz.flags())) {
                registerForReflection(reflection, endpoint.value("encoders"));
                registerForReflection(reflection, endpoint.value("decoders"));
            }
        }
    }
}
 
Example #30
Source File: AutoInjectFieldProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep
void autoInjectQualifiers(BeanArchiveIndexBuildItem beanArchiveIndex,
        BuildProducer<AutoInjectAnnotationBuildItem> autoInjectAnnotations) {
    List<DotName> qualifiers = new ArrayList<>();
    for (AnnotationInstance qualifier : beanArchiveIndex.getIndex().getAnnotations(DotNames.QUALIFIER)) {
        qualifiers.add(qualifier.target().asClass().name());
    }
    autoInjectAnnotations.produce(new AutoInjectAnnotationBuildItem(qualifiers));
}