Java Code Examples for org.jboss.jandex.AnnotationTarget#asClass()

The following examples show how to use org.jboss.jandex.AnnotationTarget#asClass() . 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: SchemaBuilder.java    From smallrye-graphql with 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 2
Source File: BeanInfo.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private ClassInfo initImplClazz(AnnotationTarget target, BeanDeployment beanDeployment) {
    switch (target.kind()) {
        case CLASS:
            return target.asClass();
        case FIELD:
            return getClassByName(beanDeployment.getIndex(), target.asField().type());
        case METHOD:
            return getClassByName(beanDeployment.getIndex(), target.asMethod().returnType());
        default:
            break;
    }
    return null;
}
 
Example 3
Source File: QuteProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private void processsTemplateData(IndexView index, AnnotationInstance templateData, AnnotationTarget annotationTarget,
        Set<DotName> controlled, Map<DotName, AnnotationInstance> uncontrolled, Map<DotName, ClassInfo> nameToClass) {
    AnnotationValue targetValue = templateData.value("target");
    if (targetValue == null || targetValue.asClass().name().equals(ValueResolverGenerator.TEMPLATE_DATA)) {
        ClassInfo annotationTargetClass = annotationTarget.asClass();
        controlled.add(annotationTargetClass.name());
        nameToClass.put(annotationTargetClass.name(), annotationTargetClass);
    } else {
        ClassInfo uncontrolledClass = index.getClassByName(targetValue.asClass().name());
        if (uncontrolledClass != null) {
            uncontrolled.compute(uncontrolledClass.name(), (c, v) -> {
                if (v == null) {
                    nameToClass.put(uncontrolledClass.name(), uncontrolledClass);
                    return templateData;
                }
                if (!Objects.equals(v.value(ValueResolverGenerator.IGNORE),
                        templateData.value(ValueResolverGenerator.IGNORE))
                        || !Objects.equals(v.value(ValueResolverGenerator.PROPERTIES),
                                templateData.value(ValueResolverGenerator.PROPERTIES))
                        || !Objects.equals(v.value(ValueResolverGenerator.IGNORE_SUPERCLASSES),
                                templateData.value(ValueResolverGenerator.IGNORE_SUPERCLASSES))) {
                    throw new IllegalStateException(
                            "Multiple unequal @TemplateData declared for " + c + ": " + v + " and " + templateData);
                }
                return v;
            });
        } else {
            LOGGER.warnf("@TemplateData#target() not available: %s", annotationTarget.asClass().name());
        }
    }
}
 
Example 4
Source File: RestClientProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private void findInterfaces(IndexView index, Map<DotName, ClassInfo> interfaces, Set<Type> returnTypes,
        DotName annotationToFind) {
    for (AnnotationInstance annotation : index.getAnnotations(annotationToFind)) {
        AnnotationTarget target = annotation.target();
        ClassInfo theInfo;
        if (target.kind() == AnnotationTarget.Kind.CLASS) {
            theInfo = target.asClass();
        } else if (target.kind() == AnnotationTarget.Kind.METHOD) {
            theInfo = target.asMethod().declaringClass();
        } else {
            continue;
        }

        if (!isRestClientInterface(index, theInfo)) {
            continue;
        }

        interfaces.put(theInfo.name(), theInfo);

        // Find Return types
        processInterfaceReturnTypes(theInfo, returnTypes);
        for (Type interfaceType : theInfo.interfaceTypes()) {
            ClassInfo interfaceClassInfo = index.getClassByName(interfaceType.name());
            if (interfaceClassInfo != null) {
                processInterfaceReturnTypes(interfaceClassInfo, returnTypes);
            }
        }
    }
}
 
Example 5
Source File: CamelDeploymentSettingsBuilderProcessor.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
private boolean annotationTargetIsCamelApi(AnnotationTarget target) {
    /**
     * Verify whether an annotation is applied to org.apache.camel types. If the declaring class
     * has the org.apache.camel package prefix, it is ignored since we are only interested in
     * annotations declared within user classes.
     */
    if (target != null) {
        if (target.kind().equals(Kind.CLASS)) {
            ClassInfo classInfo = target.asClass();
            if (isCamelApi(classInfo.name())) {
                return false;
            }

            Type superType = classInfo.superClassType();
            if (superType != null && isCamelApi(superType.name())) {
                return true;
            }

            return classInfo.interfaceNames().stream().anyMatch(interfaceName -> isCamelApi(interfaceName));
        } else if (target.kind().equals(Kind.FIELD)) {
            FieldInfo fieldInfo = target.asField();
            return !isCamelApi(fieldInfo.declaringClass().name()) && isCamelApi(fieldInfo.type().name());
        } else if (target.kind().equals(Kind.METHOD)) {
            MethodInfo methodInfo = target.asMethod();
            return !isCamelApi(methodInfo.declaringClass().name()) && isCamelApi(methodInfo.returnType().name());
        }
    }
    return false;
}