Search in sources :

Example 16 with AnnotationValue

use of org.jboss.jandex.AnnotationValue in project wildfly by wildfly.

the class JSFAnnotationProcessor method deploy.

public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (JsfVersionMarker.isJsfDisabled(deploymentUnit)) {
        return;
    }
    final Map<Class<? extends Annotation>, Set<Class<?>>> instances = new HashMap<Class<? extends Annotation>, Set<Class<?>>>();
    final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
    if (compositeIndex == null) {
        // Can not continue without index
        return;
    }
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    if (module == null) {
        // Can not continue without module
        return;
    }
    final ClassLoader classLoader = module.getClassLoader();
    for (FacesAnnotation annotation : FacesAnnotation.values()) {
        final List<AnnotationInstance> annotationInstances = compositeIndex.getAnnotations(annotation.indexName);
        if (annotationInstances == null || annotationInstances.isEmpty()) {
            continue;
        }
        final Set<Class<?>> discoveredClasses = new HashSet<Class<?>>();
        instances.put(annotation.annotationClass, discoveredClasses);
        for (AnnotationInstance annotationInstance : annotationInstances) {
            final AnnotationTarget target = annotationInstance.target();
            if (target instanceof ClassInfo) {
                final DotName className = ClassInfo.class.cast(target).name();
                final Class<?> annotatedClass;
                try {
                    annotatedClass = classLoader.loadClass(className.toString());
                } catch (ClassNotFoundException e) {
                    throw new DeploymentUnitProcessingException(JSFLogger.ROOT_LOGGER.classLoadingFailed(className));
                }
                discoveredClasses.add(annotatedClass);
            } else {
                if (annotation == FacesAnnotation.FACES_VALIDATOR || annotation == FacesAnnotation.FACES_CONVERTER || annotation == FacesAnnotation.FACES_BEHAVIOR) {
                    // Support for Injection into Jakarta Server Faces Managed Objects allows to inject FacesValidator, FacesConverter and FacesBehavior if managed = true
                    // Jakarta Server Faces 2.3 spec chapter 5.9.1 - Jakarta Server Faces Objects Valid for @Inject Injection
                    AnnotationValue value = annotationInstance.value(MANAGED_ANNOTATION_PARAMETER);
                    if (value != null && value.asBoolean()) {
                        continue;
                    }
                }
                throw new DeploymentUnitProcessingException(JSFLogger.ROOT_LOGGER.invalidAnnotationLocation(annotation, target));
            }
        }
    }
    deploymentUnit.addToAttachmentList(ServletContextAttribute.ATTACHMENT_KEY, new ServletContextAttribute(FACES_ANNOTATIONS_SC_ATTR, instances));
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) DotName(org.jboss.jandex.DotName) Annotation(java.lang.annotation.Annotation) ServletContextAttribute(org.jboss.as.web.common.ServletContextAttribute) AnnotationValue(org.jboss.jandex.AnnotationValue) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) AnnotationInstance(org.jboss.jandex.AnnotationInstance) HashSet(java.util.HashSet) ClassInfo(org.jboss.jandex.ClassInfo)

Example 17 with AnnotationValue

use of org.jboss.jandex.AnnotationValue in project wildfly by wildfly.

the class MessageDrivenComponentDescriptionFactory method getMessageListenerInterface.

private String getMessageListenerInterface(final CompositeIndex compositeIndex, final AnnotationInstance messageBeanAnnotation) throws DeploymentUnitProcessingException {
    final AnnotationValue value = messageBeanAnnotation.value("messageListenerInterface");
    if (value != null)
        return value.asClass().name().toString();
    final ClassInfo beanClass = (ClassInfo) messageBeanAnnotation.target();
    final Set<DotName> interfaces = new HashSet<DotName>(getPotentialViewInterfaces(beanClass));
    // check super class(es) of the bean
    DotName superClassDotName = beanClass.superName();
    while (interfaces.isEmpty() && superClassDotName != null && !superClassDotName.toString().equals(Object.class.getName())) {
        final ClassInfo superClass = compositeIndex.getClassByName(superClassDotName);
        if (superClass == null) {
            break;
        }
        interfaces.addAll(getPotentialViewInterfaces(superClass));
        // move to next super class
        superClassDotName = superClass.superName();
    }
    if (interfaces.size() != 1)
        throw EjbLogger.ROOT_LOGGER.mdbDoesNotImplementNorSpecifyMessageListener(beanClass);
    return interfaces.iterator().next().toString();
}
Also used : AnnotationValue(org.jboss.jandex.AnnotationValue) DotName(org.jboss.jandex.DotName) ClassInfo(org.jboss.jandex.ClassInfo) HashSet(java.util.HashSet)

Example 18 with AnnotationValue

use of org.jboss.jandex.AnnotationValue in project wildfly-swarm by wildfly-swarm.

the class OpenApiAnnotationScanner method processJaxRsMethod.

/**
 * Process a single JAX-RS method to produce an OpenAPI Operation.
 * @param openApi
 * @param resource
 * @param method
 * @param methodAnno
 * @param methodType
 * @param resourceTags
 */
private void processJaxRsMethod(OpenAPIImpl openApi, ClassInfo resource, MethodInfo method, AnnotationInstance methodAnno, HttpMethod methodType, Set<String> resourceTags) {
    LOG.debugf("Processing jax-rs method: {0}", method.toString());
    // Figure out the path for the operation.  This is a combination of the App, Resource, and Method @Path annotations
    String path;
    if (method.hasAnnotation(OpenApiConstants.DOTNAME_PATH)) {
        AnnotationInstance pathAnno = method.annotation(OpenApiConstants.DOTNAME_PATH);
        String methodPath = pathAnno.value().asString();
        path = makePath(this.currentAppPath, this.currentResourcePath, methodPath);
    } else {
        path = makePath(this.currentAppPath, this.currentResourcePath);
    }
    // Get or create a PathItem to hold the operation
    PathItem pathItem = ModelUtil.paths(openApi).get(path);
    if (pathItem == null) {
        pathItem = new PathItemImpl();
        ModelUtil.paths(openApi).addPathItem(path, pathItem);
    }
    // Figure out the current @Produces and @Consumes (if any)
    currentConsumes = null;
    currentProduces = null;
    AnnotationInstance consumesAnno = method.annotation(OpenApiConstants.DOTNAME_CONSUMES);
    if (consumesAnno == null) {
        consumesAnno = JandexUtil.getClassAnnotation(method.declaringClass(), OpenApiConstants.DOTNAME_CONSUMES);
    }
    AnnotationInstance producesAnno = method.annotation(OpenApiConstants.DOTNAME_PRODUCES);
    if (producesAnno == null) {
        producesAnno = JandexUtil.getClassAnnotation(method.declaringClass(), OpenApiConstants.DOTNAME_PRODUCES);
    }
    if (consumesAnno != null) {
        AnnotationValue annotationValue = consumesAnno.value();
        if (annotationValue != null) {
            currentConsumes = annotationValue.asStringArray();
        } else {
            currentConsumes = OpenApiConstants.DEFAULT_CONSUMES;
        }
    }
    if (producesAnno != null) {
        AnnotationValue annotationValue = producesAnno.value();
        if (annotationValue != null) {
            currentProduces = annotationValue.asStringArray();
        } else {
            currentProduces = OpenApiConstants.DEFAULT_PRODUCES;
        }
    }
    Operation operation = new OperationImpl();
    // ///////////////////////////////////////
    if (method.hasAnnotation(OpenApiConstants.DOTNAME_OPERATION)) {
        AnnotationInstance operationAnno = method.annotation(OpenApiConstants.DOTNAME_OPERATION);
        // If the operation is marked as hidden, just bail here because we don't want it as part of the model.
        if (operationAnno.value(OpenApiConstants.PROP_HIDDEN) != null && operationAnno.value(OpenApiConstants.PROP_HIDDEN).asBoolean()) {
            return;
        }
        // Otherwise, set various bits of meta-data from the values in the @Operation annotation
        operation.setSummary(JandexUtil.stringValue(operationAnno, OpenApiConstants.PROP_SUMMARY));
        operation.setDescription(JandexUtil.stringValue(operationAnno, OpenApiConstants.PROP_DESCRIPTION));
        operation.setOperationId(JandexUtil.stringValue(operationAnno, OpenApiConstants.PROP_OPERATION_ID));
        operation.setDeprecated(JandexUtil.booleanValue(operationAnno, OpenApiConstants.PROP_DEPRECATED));
    }
    // Process tags - @Tag and @Tags annotations combines with the resource tags we've already found (passed in)
    // ///////////////////////////////////////
    boolean hasOpTags = false;
    Set<String> tags = new HashSet<>();
    if (method.hasAnnotation(OpenApiConstants.DOTNAME_TAG)) {
        hasOpTags = true;
        AnnotationInstance tagAnno = method.annotation(OpenApiConstants.DOTNAME_TAG);
        if (JandexUtil.isRef(tagAnno)) {
            String tagRef = JandexUtil.stringValue(tagAnno, OpenApiConstants.PROP_REF);
            tags.add(tagRef);
        } else if (JandexUtil.isEmpty(tagAnno)) {
        // Nothing to do here.  The @Tag() was empty.
        } else {
            Tag tag = readTag(tagAnno);
            if (tag.getName() != null) {
                openApi.addTag(tag);
                tags.add(tag.getName());
            }
        }
    }
    if (method.hasAnnotation(OpenApiConstants.DOTNAME_TAGS)) {
        hasOpTags = true;
        AnnotationInstance tagsAnno = method.annotation(OpenApiConstants.DOTNAME_TAGS);
        AnnotationValue tagsArrayVal = tagsAnno.value();
        if (tagsArrayVal != null) {
            AnnotationInstance[] tagsArray = tagsArrayVal.asNestedArray();
            for (AnnotationInstance tagAnno : tagsArray) {
                if (JandexUtil.isRef(tagAnno)) {
                    String tagRef = JandexUtil.stringValue(tagAnno, OpenApiConstants.PROP_REF);
                    tags.add(tagRef);
                } else {
                    Tag tag = readTag(tagAnno);
                    if (tag.getName() != null) {
                        openApi.addTag(tag);
                        tags.add(tag.getName());
                    }
                }
            }
        }
        List<String> listValue = JandexUtil.stringListValue(tagsAnno, OpenApiConstants.PROP_REFS);
        if (listValue != null) {
            tags.addAll(listValue);
        }
    }
    if (!hasOpTags) {
        tags.addAll(resourceTags);
    }
    if (!tags.isEmpty()) {
        operation.setTags(new ArrayList<>(tags));
    }
    // Process @Parameter annotations
    // ///////////////////////////////////////
    List<AnnotationInstance> parameterAnnotations = JandexUtil.getRepeatableAnnotation(method, OpenApiConstants.DOTNAME_PARAMETER, OpenApiConstants.DOTNAME_PARAMETERS);
    for (AnnotationInstance annotation : parameterAnnotations) {
        Parameter parameter = readParameter(annotation);
        if (parameter == null) {
            // Param was hidden
            continue;
        }
        AnnotationTarget target = annotation.target();
        // If the target is METHOD_PARAMETER, then the @Parameter is on one of the method's arguments (THIS ONE WE CARE ABOUT)
        if (target != null && target.kind() == Kind.METHOD_PARAMETER) {
            In in = parameterIn(target.asMethodParameter());
            parameter.setIn(in);
            // if the Parameter model we read does *NOT* have a Schema at this point, then create one from the method argument's type
            if (!ModelUtil.parameterHasSchema(parameter)) {
                Type paramType = JandexUtil.getMethodParameterType(method, target.asMethodParameter().position());
                Schema schema = typeToSchema(paramType);
                ModelUtil.setParameterSchema(parameter, schema);
            }
        } else {
        // TODO if the @Parameter is on the method, we could perhaps find the one it refers to by name
        // and use its type to create a Schema (if missing)
        }
        operation.addParameter(parameter);
    }
    // Now process any jax-rs parameters that were NOT annotated with @Parameter (do not yet exist in the model)
    List<Type> parameters = method.parameters();
    for (int idx = 0; idx < parameters.size(); idx++) {
        JaxRsParameterInfo paramInfo = JandexUtil.getMethodParameterJaxRsInfo(method, idx);
        if (paramInfo != null && !ModelUtil.operationHasParameter(operation, paramInfo.name)) {
            Type paramType = parameters.get(idx);
            Parameter parameter = new ParameterImpl();
            parameter.setName(paramInfo.name);
            parameter.setIn(paramInfo.in);
            parameter.setRequired(true);
            Schema schema = typeToSchema(paramType);
            parameter.setSchema(schema);
            operation.addParameter(parameter);
        }
    }
    // TODO @Parameter can be located on a field - what does that mean?
    // TODO need to handle the case where we have @BeanParam annotations
    // Process any @RequestBody annotation
    // ///////////////////////////////////////
    // note: the @RequestBody annotation can be found on a method argument *or* on the method
    List<AnnotationInstance> requestBodyAnnotations = JandexUtil.getRepeatableAnnotation(method, OpenApiConstants.DOTNAME_REQUEST_BODY, null);
    for (AnnotationInstance annotation : requestBodyAnnotations) {
        RequestBody requestBody = readRequestBody(annotation);
        // TODO if the method argument type is Request, don't generate a Schema!
        if (!ModelUtil.requestBodyHasSchema(requestBody)) {
            Type requestBodyType = null;
            if (annotation.target().kind() == AnnotationTarget.Kind.METHOD_PARAMETER) {
                requestBodyType = JandexUtil.getMethodParameterType(method, annotation.target().asMethodParameter().position());
            } else if (annotation.target().kind() == AnnotationTarget.Kind.METHOD) {
                requestBodyType = JandexUtil.getRequestBodyParameterClassType(method);
            }
            if (requestBodyType != null) {
                Schema schema = typeToSchema(requestBodyType);
                ModelUtil.setRequestBodySchema(requestBody, schema, currentConsumes);
            }
        }
        operation.setRequestBody(requestBody);
    }
    // method declares that it @Consumes data
    if (operation.getRequestBody() == null && currentConsumes != null) {
        Type requestBodyType = JandexUtil.getRequestBodyParameterClassType(method);
        if (requestBodyType != null) {
            Schema schema = typeToSchema(requestBodyType);
            if (schema != null) {
                RequestBody requestBody = new RequestBodyImpl();
                ModelUtil.setRequestBodySchema(requestBody, schema, currentConsumes);
                operation.setRequestBody(requestBody);
            }
        }
    }
    // Process @APIResponse annotations
    // ///////////////////////////////////////
    List<AnnotationInstance> apiResponseAnnotations = JandexUtil.getRepeatableAnnotation(method, OpenApiConstants.DOTNAME_API_RESPONSE, OpenApiConstants.DOTNAME_API_RESPONSES);
    for (AnnotationInstance annotation : apiResponseAnnotations) {
        String responseCode = JandexUtil.stringValue(annotation, OpenApiConstants.PROP_RESPONSE_CODE);
        if (responseCode == null) {
            responseCode = APIResponses.DEFAULT;
        }
        APIResponse response = readResponse(annotation);
        APIResponses responses = ModelUtil.responses(operation);
        responses.addApiResponse(responseCode, response);
    }
    // If there are no responses from annotations, try to create a response from the method return value.
    if (operation.getResponses() == null || operation.getResponses().isEmpty()) {
        createResponseFromJaxRsMethod(method, operation);
    }
    // Process @SecurityRequirement annotations
    // /////////////////////////////////////////
    List<AnnotationInstance> securityRequirementAnnotations = JandexUtil.getRepeatableAnnotation(method, OpenApiConstants.DOTNAME_SECURITY_REQUIREMENT, OpenApiConstants.DOTNAME_SECURITY_REQUIREMENTS);
    securityRequirementAnnotations.addAll(JandexUtil.getRepeatableAnnotation(resource, OpenApiConstants.DOTNAME_SECURITY_REQUIREMENT, OpenApiConstants.DOTNAME_SECURITY_REQUIREMENTS));
    for (AnnotationInstance annotation : securityRequirementAnnotations) {
        SecurityRequirement requirement = readSecurityRequirement(annotation);
        if (requirement != null) {
            operation.addSecurityRequirement(requirement);
        }
    }
    // Process @Callback annotations
    // ///////////////////////////////////////
    List<AnnotationInstance> callbackAnnotations = JandexUtil.getRepeatableAnnotation(method, OpenApiConstants.DOTNAME_CALLBACK, OpenApiConstants.DOTNAME_CALLBACKS);
    Map<String, Callback> callbacks = new LinkedHashMap<>();
    for (AnnotationInstance annotation : callbackAnnotations) {
        String name = JandexUtil.stringValue(annotation, OpenApiConstants.PROP_NAME);
        if (name == null && JandexUtil.isRef(annotation)) {
            name = JandexUtil.nameFromRef(annotation);
        }
        if (name != null) {
            callbacks.put(name, readCallback(annotation));
        }
        if (!callbacks.isEmpty()) {
            operation.setCallbacks(callbacks);
        }
    }
    // Process @Server annotations
    // /////////////////////////////////
    List<AnnotationInstance> serverAnnotations = JandexUtil.getRepeatableAnnotation(method, OpenApiConstants.DOTNAME_SERVER, OpenApiConstants.DOTNAME_SERVERS);
    if (serverAnnotations.isEmpty()) {
        serverAnnotations.addAll(JandexUtil.getRepeatableAnnotation(method.declaringClass(), OpenApiConstants.DOTNAME_SERVER, OpenApiConstants.DOTNAME_SERVERS));
    }
    for (AnnotationInstance annotation : serverAnnotations) {
        Server server = readServer(annotation);
        operation.addServer(server);
    }
    // /////////////////////////////////////////
    switch(methodType) {
        case DELETE:
            pathItem.setDELETE(operation);
            break;
        case GET:
            pathItem.setGET(operation);
            break;
        case HEAD:
            pathItem.setHEAD(operation);
            break;
        case OPTIONS:
            pathItem.setOPTIONS(operation);
            break;
        case PATCH:
            pathItem.setPATCH(operation);
            break;
        case POST:
            pathItem.setPOST(operation);
            break;
        case PUT:
            pathItem.setPUT(operation);
            break;
        case TRACE:
            pathItem.setTRACE(operation);
            break;
        default:
            break;
    }
}
Also used : APIResponse(org.eclipse.microprofile.openapi.models.responses.APIResponse) Server(org.eclipse.microprofile.openapi.models.servers.Server) In(org.eclipse.microprofile.openapi.models.parameters.Parameter.In) Schema(org.eclipse.microprofile.openapi.models.media.Schema) Operation(org.eclipse.microprofile.openapi.models.Operation) LinkedHashMap(java.util.LinkedHashMap) PathItem(org.eclipse.microprofile.openapi.models.PathItem) OperationImpl(org.wildfly.swarm.microprofile.openapi.api.models.OperationImpl) APIResponses(org.eclipse.microprofile.openapi.models.responses.APIResponses) HashSet(java.util.HashSet) RequestBody(org.eclipse.microprofile.openapi.models.parameters.RequestBody) AnnotationTarget(org.jboss.jandex.AnnotationTarget) RequestBodyImpl(org.wildfly.swarm.microprofile.openapi.api.models.parameters.RequestBodyImpl) ClassType(org.jboss.jandex.ClassType) RefType(org.wildfly.swarm.microprofile.openapi.runtime.util.JandexUtil.RefType) MediaType(org.eclipse.microprofile.openapi.models.media.MediaType) Type(org.jboss.jandex.Type) Callback(org.eclipse.microprofile.openapi.models.callbacks.Callback) ParameterImpl(org.wildfly.swarm.microprofile.openapi.api.models.parameters.ParameterImpl) AnnotationValue(org.jboss.jandex.AnnotationValue) Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter) Tag(org.eclipse.microprofile.openapi.models.tags.Tag) JaxRsParameterInfo(org.wildfly.swarm.microprofile.openapi.runtime.util.JandexUtil.JaxRsParameterInfo) PathItemImpl(org.wildfly.swarm.microprofile.openapi.api.models.PathItemImpl) AnnotationInstance(org.jboss.jandex.AnnotationInstance) SecurityRequirement(org.eclipse.microprofile.openapi.models.security.SecurityRequirement)

Example 19 with AnnotationValue

use of org.jboss.jandex.AnnotationValue in project wildfly-swarm by wildfly-swarm.

the class OpenApiAnnotationScanner method processJaxRsResourceClass.

/**
 * Processing a single JAX-RS resource class (annotated with @Path).
 * @param openApi
 * @param resourceClass
 */
private void processJaxRsResourceClass(OpenAPIImpl openApi, ClassInfo resourceClass) {
    LOG.debug("Processing a JAX-RS resource class: " + resourceClass.simpleName());
    // Set the current resource path.
    AnnotationInstance pathAnno = JandexUtil.getClassAnnotation(resourceClass, OpenApiConstants.DOTNAME_PATH);
    this.currentResourcePath = pathAnno.value().asString();
    // TODO handle the use-case where the resource class extends a base class, and the base class has jax-rs relevant methods and annotations
    // Process @SecurityScheme annotations
    // //////////////////////////////////////
    List<AnnotationInstance> securitySchemeAnnotations = JandexUtil.getRepeatableAnnotation(resourceClass, OpenApiConstants.DOTNAME_SECURITY_SCHEME, OpenApiConstants.DOTNAME_SECURITY_SCHEMES);
    for (AnnotationInstance annotation : securitySchemeAnnotations) {
        String name = JandexUtil.stringValue(annotation, OpenApiConstants.PROP_SECURITY_SCHEME_NAME);
        if (name == null && JandexUtil.isRef(annotation)) {
            name = JandexUtil.nameFromRef(annotation);
        }
        if (name != null) {
            SecurityScheme securityScheme = readSecurityScheme(annotation);
            Components components = ModelUtil.components(openApi);
            components.addSecurityScheme(name, securityScheme);
        }
    }
    // Process tags (both declarations and references)
    // //////////////////////////////////////
    Set<String> tagRefs = new HashSet<>();
    AnnotationInstance tagAnno = JandexUtil.getClassAnnotation(resourceClass, OpenApiConstants.DOTNAME_TAG);
    if (tagAnno != null) {
        if (JandexUtil.isRef(tagAnno)) {
            String tagRef = JandexUtil.stringValue(tagAnno, OpenApiConstants.PROP_REF);
            tagRefs.add(tagRef);
        } else {
            Tag tag = readTag(tagAnno);
            if (tag.getName() != null) {
                openApi.addTag(tag);
                tagRefs.add(tag.getName());
            }
        }
    }
    AnnotationInstance tagsAnno = JandexUtil.getClassAnnotation(resourceClass, OpenApiConstants.DOTNAME_TAGS);
    if (tagsAnno != null) {
        AnnotationValue tagsArrayVal = tagsAnno.value();
        if (tagsArrayVal != null) {
            AnnotationInstance[] tagsArray = tagsArrayVal.asNestedArray();
            for (AnnotationInstance ta : tagsArray) {
                if (JandexUtil.isRef(ta)) {
                    String tagRef = JandexUtil.stringValue(ta, OpenApiConstants.PROP_REF);
                    tagRefs.add(tagRef);
                } else {
                    Tag tag = readTag(ta);
                    if (tag.getName() != null) {
                        openApi.addTag(tag);
                        tagRefs.add(tag.getName());
                    }
                }
            }
        }
        List<String> listValue = JandexUtil.stringListValue(tagsAnno, OpenApiConstants.PROP_REFS);
        if (listValue != null) {
            tagRefs.addAll(listValue);
        }
    }
    // //////////////////////////////////////
    for (MethodInfo methodInfo : resourceClass.methods()) {
        AnnotationInstance get = methodInfo.annotation(OpenApiConstants.DOTNAME_GET);
        if (get != null) {
            processJaxRsMethod(openApi, resourceClass, methodInfo, get, HttpMethod.GET, tagRefs);
        }
        AnnotationInstance put = methodInfo.annotation(OpenApiConstants.DOTNAME_PUT);
        if (put != null) {
            processJaxRsMethod(openApi, resourceClass, methodInfo, put, HttpMethod.PUT, tagRefs);
        }
        AnnotationInstance post = methodInfo.annotation(OpenApiConstants.DOTNAME_POST);
        if (post != null) {
            processJaxRsMethod(openApi, resourceClass, methodInfo, post, HttpMethod.POST, tagRefs);
        }
        AnnotationInstance delete = methodInfo.annotation(OpenApiConstants.DOTNAME_DELETE);
        if (delete != null) {
            processJaxRsMethod(openApi, resourceClass, methodInfo, delete, HttpMethod.DELETE, tagRefs);
        }
        AnnotationInstance head = methodInfo.annotation(OpenApiConstants.DOTNAME_HEAD);
        if (head != null) {
            processJaxRsMethod(openApi, resourceClass, methodInfo, head, HttpMethod.HEAD, tagRefs);
        }
        AnnotationInstance options = methodInfo.annotation(OpenApiConstants.DOTNAME_OPTIONS);
        if (options != null) {
            processJaxRsMethod(openApi, resourceClass, methodInfo, options, HttpMethod.OPTIONS, tagRefs);
        }
    }
}
Also used : Components(org.eclipse.microprofile.openapi.models.Components) AnnotationValue(org.jboss.jandex.AnnotationValue) MethodInfo(org.jboss.jandex.MethodInfo) Tag(org.eclipse.microprofile.openapi.models.tags.Tag) SecurityScheme(org.eclipse.microprofile.openapi.models.security.SecurityScheme) AnnotationInstance(org.jboss.jandex.AnnotationInstance) HashSet(java.util.HashSet)

Example 20 with AnnotationValue

use of org.jboss.jandex.AnnotationValue in project wildfly-swarm by wildfly-swarm.

the class JandexUtil method enumValue.

/**
 * Reads a String property value from the given annotation instance.  If no value is found
 * this will return null.
 * @param annotation
 * @param propertyName
 */
@SuppressWarnings("rawtypes")
public static <T extends Enum> T enumValue(AnnotationInstance annotation, String propertyName, Class<T> clazz) {
    AnnotationValue value = annotation.value(propertyName);
    if (value == null) {
        return null;
    }
    String strVal = value.asString();
    T[] constants = clazz.getEnumConstants();
    for (T t : constants) {
        if (t.name().equals(strVal)) {
            return t;
        }
    }
    for (T t : constants) {
        if (t.name().equalsIgnoreCase(strVal)) {
            return t;
        }
    }
    return null;
}
Also used : AnnotationValue(org.jboss.jandex.AnnotationValue)

Aggregations

AnnotationValue (org.jboss.jandex.AnnotationValue)32 AnnotationInstance (org.jboss.jandex.AnnotationInstance)20 ClassInfo (org.jboss.jandex.ClassInfo)12 AnnotationTarget (org.jboss.jandex.AnnotationTarget)10 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)8 CompositeIndex (org.jboss.as.server.deployment.annotation.CompositeIndex)8 PropertyReplacer (org.jboss.metadata.property.PropertyReplacer)6 HashSet (java.util.HashSet)5 BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)4 InjectionSource (org.jboss.as.ee.component.InjectionSource)4 LookupInjectionSource (org.jboss.as.ee.component.LookupInjectionSource)4 PersistenceContextInjectionSource (org.jboss.as.jpa.injectors.PersistenceContextInjectionSource)4 PersistenceUnitInjectionSource (org.jboss.as.jpa.injectors.PersistenceUnitInjectionSource)4 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)4 MethodInfo (org.jboss.jandex.MethodInfo)4 ServiceName (org.jboss.msc.service.ServiceName)4 ArrayList (java.util.ArrayList)3 TimeUnit (java.util.concurrent.TimeUnit)3 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)3 ResourceInjectionConfiguration (org.jboss.as.ee.component.ResourceInjectionConfiguration)3