Java Code Examples for org.jboss.jandex.AnnotationValue#asNestedArray()

The following examples show how to use org.jboss.jandex.AnnotationValue#asNestedArray() . 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: 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 2
Source File: HeaderReader.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
/**
 * Reads a map of Header annotations.
 * 
 * @param context the scanning context
 * @param annotationValue map of {@literal @}Header annotations
 * @return Map of Header models
 */
public static Map<String, Header> readHeaders(final AnnotationScannerContext context,
        final AnnotationValue annotationValue) {
    if (annotationValue == null) {
        return null;
    }
    IoLogging.log.annotationsMap("@Header");
    Map<String, Header> headers = new LinkedHashMap<>();
    AnnotationInstance[] nestedArray = annotationValue.asNestedArray();
    for (AnnotationInstance nested : nestedArray) {
        String name = JandexUtil.stringValue(nested, Parameterizable.PROP_NAME);
        if (name == null && JandexUtil.isRef(nested)) {
            name = JandexUtil.nameFromRef(nested);
        }
        if (name != null) {
            headers.put(name, readHeader(context, nested));
        }
    }
    return headers;
}
 
Example 3
Source File: EncodingReader.java    From smallrye-open-api with 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 4
Source File: CallbackReader.java    From smallrye-open-api with 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 5
Source File: OAuthReader.java    From smallrye-open-api with 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 6
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 7
Source File: ResponseReader.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
/**
 * Reads a map of APIResponse annotations.
 * 
 * @param context the scanning context
 * @param annotationValue map of {@literal @}APIResponse annotations
 * @return Map of APIResponse models
 */
public static Map<String, APIResponse> readResponsesMap(final AnnotationScannerContext context,
        final AnnotationValue annotationValue) {
    if (annotationValue == null) {
        return null;
    }
    IoLogging.log.annotationsMap("@APIResponse");
    Map<String, APIResponse> responses = new LinkedHashMap<>();
    AnnotationInstance[] nestedArray = annotationValue.asNestedArray();
    for (AnnotationInstance nested : nestedArray) {
        String name = JandexUtil.stringValue(nested, ResponseConstant.PROP_NAME);
        if (name == null && JandexUtil.isRef(nested)) {
            name = JandexUtil.nameFromRef(nested);
        }
        if (name != null) {
            responses.put(name, readResponse(context, nested));
        }
    }
    return responses;
}
 
Example 8
Source File: ParameterProcessor.java    From smallrye-open-api with 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 9
Source File: ParameterReader.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
/**
 * Reads a map of Parameter annotations.
 * 
 * @param context the scanning context
 * @param annotationValue Map of {@literal @}Parameter annotations
 * @return Map of Parameter model
 */
public static Map<String, Parameter> readParameters(final AnnotationScannerContext context,
        final AnnotationValue annotationValue) {
    if (annotationValue == null) {
        return null;
    }
    IoLogging.log.annotationsMap("@Parameter");
    Map<String, Parameter> parameters = new LinkedHashMap<>();
    AnnotationInstance[] nestedArray = annotationValue.asNestedArray();
    for (AnnotationInstance nested : nestedArray) {
        String name = JandexUtil.stringValue(nested, Parameterizable.PROP_NAME);
        if (name == null && JandexUtil.isRef(nested)) {
            name = JandexUtil.nameFromRef(nested);
        }
        if (name != null) {
            Parameter parameter = readParameter(context, nested);
            if (parameter != null) {
                parameters.put(name, parameter);
            }
        }
    }
    return parameters;
}
 
Example 10
Source File: ParameterReader.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
/**
 * Reads a map of Parameter annotations.
 * 
 * @param context the scanning context
 * @param annotationValue Map of {@literal @}Parameter annotations
 * @return List of Parameter model
 */
public static Optional<List<Parameter>> readParametersList(final AnnotationScannerContext context,
        final AnnotationValue annotationValue) {
    if (annotationValue != null) {
        IoLogging.log.annotationsList("@Parameter");
        List<Parameter> parameters = new ArrayList<>();
        AnnotationInstance[] nestedArray = annotationValue.asNestedArray();
        for (AnnotationInstance nested : nestedArray) {
            Parameter parameter = readParameter(context, nested);
            if (parameter != null) {
                parameters.add(parameter);
            }
        }
        return Optional.of(parameters);
    }
    return Optional.empty();
}
 
Example 11
Source File: SecurityRequirementReader.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
/**
 * Reads any SecurityRequirement annotations. The annotation value is an array of
 * SecurityRequirement annotations.
 * 
 * @param annotationValue Array of {@literal @}SecurityRequirement annotations
 * @return List of SecurityRequirement models
 */
public static Optional<List<SecurityRequirement>> readSecurityRequirements(final AnnotationValue annotationValue) {
    if (annotationValue != null) {
        IoLogging.log.annotationsArray("@SecurityRequirement");
        AnnotationInstance[] nestedArray = annotationValue.asNestedArray();
        List<SecurityRequirement> requirements = new ArrayList<>();
        for (AnnotationInstance requirementAnno : nestedArray) {
            SecurityRequirement requirement = readSecurityRequirement(requirementAnno);
            if (requirement != null) {
                requirements.add(requirement);
            }
        }
        return Optional.of(requirements);
    }
    return Optional.empty();
}
 
Example 12
Source File: LinkReader.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
/**
 * Reads an array of LinkParameter annotations into a map.
 * 
 * @param annotationValue the annotation value
 * @return map of parameters
 */
private static Map<String, Object> readLinkParameters(final AnnotationValue annotationValue) {
    if (annotationValue == null) {
        return null;
    }
    AnnotationInstance[] nestedArray = annotationValue.asNestedArray();
    Map<String, Object> linkParams = new LinkedHashMap<>();
    for (AnnotationInstance annotation : nestedArray) {
        String name = JandexUtil.stringValue(annotation, LinkConstant.PROP_NAME);
        if (name != null) {
            String expression = JandexUtil.stringValue(annotation, LinkConstant.PROP_EXPRESSION);
            linkParams.put(name, expression);
        }
    }
    return linkParams;
}
 
Example 13
Source File: LinkReader.java    From smallrye-open-api with 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 14
Source File: RequestBodyReader.java    From smallrye-open-api with 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 File: ParameterProcessor.java    From smallrye-open-api with 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 16
Source File: TagReader.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
/**
 * Reads any Tag annotations.The annotation
 * value is an array of Tag annotations.
 * 
 * @param annotationValue an array of {@literal @}Tag annotations
 * @return List of Tag models
 */
public static Optional<List<Tag>> readTags(final AnnotationValue annotationValue) {
    if (annotationValue != null) {
        IoLogging.log.annotationsArray("@Tag");
        AnnotationInstance[] nestedArray = annotationValue.asNestedArray();
        List<Tag> tags = new ArrayList<>();
        for (AnnotationInstance tagAnno : nestedArray) {
            if (!JandexUtil.isRef(tagAnno)) {
                tags.add(readTag(tagAnno));
            }
        }
        return Optional.of(tags);
    }
    return Optional.empty();
}
 
Example 17
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 18
Source File: ExtensionReader.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
/**
 * Reads an array of Extension annotations. The AnnotationValue in this case is
 * an array of Extension annotations. These must be read and converted into a Map.
 * 
 * @param context the scanning context
 * @param annotationValue map of {@literal @}Extension annotations
 * @return Map of Objects
 */
public static Map<String, Object> readExtensions(final AnnotationScannerContext context,
        final AnnotationValue annotationValue) {
    if (annotationValue == null) {
        return null;
    }
    IoLogging.log.annotationsMap("@Extension");
    Map<String, Object> e = new LinkedHashMap<>();
    AnnotationInstance[] nestedArray = annotationValue.asNestedArray();
    for (AnnotationInstance annotation : nestedArray) {
        String extName = JandexUtil.stringValue(annotation, ExtensionConstant.PROP_NAME);
        e.put(extName, readExtensionValue(context, extName, annotation));
    }
    return e;
}
 
Example 19
Source File: TestResourceManager.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private List<TestResourceEntry> getTestResources(Class<?> testClass) {
    IndexView index = TestClassIndexer.readIndex(testClass);

    List<TestResourceEntry> testResourceEntries = new ArrayList<>();

    // we need to keep track of duplicate entries to make sure we don't start the same resource
    // multiple times even if there are multiple same @QuarkusTestResource annotations
    Set<TestResourceClassEntry> alreadyAddedEntries = new HashSet<>();
    for (AnnotationInstance annotation : findQuarkusTestResourceInstances(index)) {
        try {
            Class<? extends QuarkusTestResourceLifecycleManager> testResourceClass = (Class<? extends QuarkusTestResourceLifecycleManager>) Class
                    .forName(annotation.value().asString(), true, Thread.currentThread().getContextClassLoader());

            AnnotationValue argsAnnotationValue = annotation.value("initArgs");
            Map<String, String> args;
            if (argsAnnotationValue == null) {
                args = Collections.emptyMap();
            } else {
                args = new HashMap<>();
                AnnotationInstance[] resourceArgsInstances = argsAnnotationValue.asNestedArray();
                for (AnnotationInstance resourceArgsInstance : resourceArgsInstances) {
                    args.put(resourceArgsInstance.value("name").asString(), resourceArgsInstance.value().asString());
                }
            }

            TestResourceClassEntry testResourceClassEntry = new TestResourceClassEntry(testResourceClass, args);
            if (alreadyAddedEntries.contains(testResourceClassEntry)) {
                continue;
            }
            alreadyAddedEntries.add(testResourceClassEntry);

            testResourceEntries.add(new TestResourceEntry(testResourceClass.getConstructor().newInstance(), args));
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException
                | InvocationTargetException | NoSuchMethodException | SecurityException e) {
            throw new RuntimeException("Unable to instantiate the test resource " + annotation.value().asString());
        }
    }

    for (QuarkusTestResourceLifecycleManager quarkusTestResourceLifecycleManager : ServiceLoader
            .load(QuarkusTestResourceLifecycleManager.class, Thread.currentThread().getContextClassLoader())) {
        testResourceEntries.add(new TestResourceEntry(quarkusTestResourceLifecycleManager));
    }

    testResourceEntries.sort(new Comparator<TestResourceEntry>() {

        private final QuarkusTestResourceLifecycleManagerComparator lifecycleManagerComparator = new QuarkusTestResourceLifecycleManagerComparator();

        @Override
        public int compare(TestResourceEntry o1, TestResourceEntry o2) {
            return lifecycleManagerComparator.compare(o1.getTestResource(), o2.getTestResource());
        }
    });

    return testResourceEntries;
}
 
Example 20
Source File: SmallRyeOpenApiProcessor.java    From quarkus with Apache License 2.0 4 votes vote down vote up
private void registerReflectionForApiResponseSchemaSerialization(BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
        BuildProducer<ReflectiveHierarchyBuildItem> reflectiveHierarchy,
        Collection<AnnotationInstance> apiResponseAnnotationInstances) {
    for (AnnotationInstance apiResponseAnnotationInstance : apiResponseAnnotationInstances) {
        AnnotationValue contentAnnotationValue = apiResponseAnnotationInstance.value(OPENAPI_RESPONSE_CONTENT);
        if (contentAnnotationValue == null) {
            continue;
        }

        AnnotationInstance[] contents = contentAnnotationValue.asNestedArray();
        for (AnnotationInstance content : contents) {
            AnnotationValue annotationValue = content.value(OPENAPI_RESPONSE_SCHEMA);
            if (annotationValue == null) {
                continue;
            }
            AnnotationInstance schema = annotationValue.asNested();
            AnnotationValue schemaImplementationClass = schema.value(OPENAPI_SCHEMA_IMPLEMENTATION);
            if (schemaImplementationClass != null) {
                reflectiveHierarchy.produce(new ReflectiveHierarchyBuildItem(schemaImplementationClass.asClass(),
                        IgnoreDotNames.IGNORE_FOR_REFLECTION_PREDICATE));
            }

            AnnotationValue schemaNotClass = schema.value(OPENAPI_SCHEMA_NOT);
            if (schemaNotClass != null) {
                reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, schemaNotClass.asString()));
            }

            AnnotationValue schemaOneOfClasses = schema.value(OPENAPI_SCHEMA_ONE_OF);
            if (schemaOneOfClasses != null) {
                for (Type schemaOneOfClass : schemaOneOfClasses.asClassArray()) {
                    reflectiveHierarchy.produce(new ReflectiveHierarchyBuildItem(schemaOneOfClass,
                            IgnoreDotNames.IGNORE_FOR_REFLECTION_PREDICATE));
                }
            }

            AnnotationValue schemaAnyOfClasses = schema.value(OPENAPI_SCHEMA_ANY_OF);
            if (schemaAnyOfClasses != null) {
                for (Type schemaAnyOfClass : schemaAnyOfClasses.asClassArray()) {
                    reflectiveHierarchy.produce(new ReflectiveHierarchyBuildItem(schemaAnyOfClass,
                            IgnoreDotNames.IGNORE_FOR_REFLECTION_PREDICATE));
                }
            }

            AnnotationValue schemaAllOfClasses = schema.value(OPENAPI_SCHEMA_ALL_OF);
            if (schemaAllOfClasses != null) {
                for (Type schemaAllOfClass : schemaAllOfClasses.asClassArray()) {
                    reflectiveHierarchy.produce(new ReflectiveHierarchyBuildItem(schemaAllOfClass,
                            IgnoreDotNames.IGNORE_FOR_REFLECTION_PREDICATE));
                }
            }
        }
    }
}