org.jboss.jandex.Type Java Examples

The following examples show how to use org.jboss.jandex.Type. 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: JpaJandexScavenger.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static void collectEmbeddedTypes(Set<DotName> embeddedTypes, Type indexType) {
    switch (indexType.kind()) {
        case CLASS:
            embeddedTypes.add(indexType.asClassType().name());
            break;
        case PARAMETERIZED_TYPE:
            embeddedTypes.add(indexType.name());
            for (Type typeArgument : indexType.asParameterizedType().arguments()) {
                collectEmbeddedTypes(embeddedTypes, typeArgument);
            }
            break;
        case ARRAY:
            collectEmbeddedTypes(embeddedTypes, indexType.asArrayType().component());
            break;
        default:
            // do nothing
            break;
    }
}
 
Example #2
Source File: AnnotationTargetProcessor.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
private Schema readSchemaAnnotatedField(String propertyKey, AnnotationInstance annotation, Type postProcessedField) {
    DataObjectLogging.log.processingFieldAnnotation(annotation, propertyKey);

    // If "required" attribute is on field. It should be applied to the *parent* schema.
    // Required is false by default.
    if (JandexUtil.booleanValueWithDefault(annotation, SchemaConstant.PROP_REQUIRED)) {
        parentPathEntry.getSchema().addRequired(propertyKey);
    }

    // TypeFormat pair contains mappings for Java <-> OAS types and formats.
    // Provide inferred type and format if relevant.
    Map<String, Object> defaults;

    if (JandexUtil.isArraySchema(annotation)) {
        defaults = Collections.emptyMap();
    } else {
        defaults = TypeUtil.getTypeAttributes(postProcessedField);
    }

    // readSchema *may* replace the existing schema, so we must assign.
    return SchemaFactory.readSchema(index, new SchemaImpl(), annotation, defaults);
}
 
Example #3
Source File: Types.java    From quarkus with Apache License 2.0 6 votes vote down vote up
static Type resolveTypeParam(Type typeParam, Map<TypeVariable, Type> resolvedTypeParameters, IndexView index) {
    if (typeParam.kind() == Kind.TYPE_VARIABLE) {
        return resolvedTypeParameters.getOrDefault(typeParam, typeParam);
    } else if (typeParam.kind() == Kind.PARAMETERIZED_TYPE) {
        ParameterizedType parameterizedType = typeParam.asParameterizedType();
        ClassInfo classInfo = getClassByName(index, parameterizedType.name());
        if (classInfo != null) {
            List<TypeVariable> typeParameters = classInfo.typeParameters();
            List<Type> arguments = parameterizedType.arguments();
            Map<TypeVariable, Type> resolvedMap = buildResolvedMap(arguments, typeParameters,
                    resolvedTypeParameters, index);
            Type[] typeParams = new Type[typeParameters.size()];
            for (int i = 0; i < typeParameters.size(); i++) {
                typeParams[i] = resolveTypeParam(arguments.get(i), resolvedMap, index);
            }
            return ParameterizedType.create(parameterizedType.name(), typeParams, null);
        }
    }
    return typeParam;
}
 
Example #4
Source File: BeanArchives.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Override
public Collection<ClassInfo> getKnownDirectImplementors(DotName className) {
    if (additionalClasses.isEmpty()) {
        return index.getKnownDirectImplementors(className);
    }
    Set<ClassInfo> directImplementors = new HashSet<ClassInfo>(index.getKnownDirectImplementors(className));
    for (Optional<ClassInfo> additional : additionalClasses.values()) {
        if (!additional.isPresent()) {
            continue;
        }
        for (Type interfaceType : additional.get().interfaceTypes()) {
            if (className.equals(interfaceType.name())) {
                directImplementors.add(additional.get());
                break;
            }
        }
    }
    return directImplementors;
}
 
Example #5
Source File: Methods.java    From quarkus with Apache License 2.0 6 votes vote down vote up
static boolean matchesSignature(MethodInfo method, MethodInfo subclassMethod) {
    if (!method.name().equals(subclassMethod.name())) {
        return false;
    }
    List<Type> parameters = method.parameters();
    List<Type> subParameters = subclassMethod.parameters();

    int paramCount = parameters.size();
    if (paramCount != subParameters.size()) {
        return false;
    }

    if (paramCount == 0) {
        return true;
    }

    for (int i = 0; i < paramCount; i++) {
        if (!Methods.isTypeEqual(parameters.get(i), subParameters.get(i))) {
            return false;
        }
    }

    return true;
}
 
Example #6
Source File: AnnotationScanner.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
/**
 * Extracts all methods from the provided class and its ancestors that are known to the instance's index
 * 
 * @param context the scanning context
 * @param resource the resource class
 * @return all methods from the provided class and its ancestors
 */
default List<MethodInfo> getResourceMethods(final AnnotationScannerContext context, ClassInfo resource) {
    Type resourceType = Type.create(resource.name(), Type.Kind.CLASS);
    Map<ClassInfo, Type> chain = JandexUtil.inheritanceChain(context.getIndex(), resource, resourceType);
    List<MethodInfo> methods = new ArrayList<>();

    for (ClassInfo classInfo : chain.keySet()) {
        methods.addAll(classInfo.methods());

        classInfo.interfaceTypes()
                .stream()
                .map(iface -> context.getIndex().getClassByName(TypeUtil.getName(iface)))
                .filter(Objects::nonNull)
                .flatMap(iface -> iface.methods().stream())
                .forEach(methods::add);
    }

    return methods;
}
 
Example #7
Source File: InterceptedStaticMethodsProcessor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Override
public void visitEnd() {
    // Invoke the initializer, i.e. Foo_InterceptorInitializer.hash("ping")
    MethodDescriptor descriptor = MethodDescriptor.of(interceptedStaticMethod.getMethod());
    int paramSlot = 0;
    for (Type paramType : interceptedStaticMethod.getMethod().parameters()) {
        superVisitor.visitIntInsn(AsmUtil.getLoadOpcode(paramType), paramSlot);
        paramSlot += AsmUtil.getParameterSize(paramType);
    }
    superVisitor.visitMethodInsn(Opcodes.INVOKESTATIC,
            initializerClassName.replace('.', '/'), interceptedStaticMethod.getHash(),
            descriptor.getDescriptor().toString(),
            false);
    superVisitor.visitInsn(AsmUtil.getReturnInstruction(interceptedStaticMethod.getMethod().returnType()));
    superVisitor.visitMaxs(0, 0);
    superVisitor.visitEnd();

    super.visitEnd();
}
 
Example #8
Source File: Types.java    From quarkus with 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 #9
Source File: JandexUtil.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("incomplete-switch")
public static String getBoxedTypeName(Type type) {
    switch (type.kind()) {
        case PRIMITIVE:
            switch (type.asPrimitiveType().primitive()) {
                case BOOLEAN:
                    return "java.lang.Boolean";
                case BYTE:
                    return "java.lang.Byte";
                case CHAR:
                    return "java.lang.Character";
                case DOUBLE:
                    return "java.lang.Double";
                case FLOAT:
                    return "java.lang.Float";
                case INT:
                    return "java.lang.Integer";
                case LONG:
                    return "java.lang.Long";
                case SHORT:
                    return "java.lang.Short";
            }
    }
    return type.toString();
}
 
Example #10
Source File: AsmUtil.java    From quarkus with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the Java bytecode signature of a given Jandex MethodInfo using the given type argument mappings.
 * For example, given this method:
 * 
 * <pre>
 * {@code
 * public class Foo<T> {
 *  public <R> List<R> method(int a, T t){...} 
 * }
 * }
 * </pre>
 * 
 * This will return <tt>&lt;R:Ljava/lang/Object;>(ILjava/lang/Integer;)Ljava/util/List&lt;TR;>;</tt> if
 * your {@code typeArgMapper} contains {@code T=Ljava/lang/Integer;}.
 * 
 * @param method the method you want the signature for.
 * @param typeArgMapper a mapping between type argument names and their bytecode signature.
 * @return a bytecode signature for that method.
 */
public static String getSignature(MethodInfo method, Function<String, String> typeArgMapper) {
    List<Type> parameters = method.parameters();

    StringBuilder signature = new StringBuilder("");
    for (TypeVariable typeVariable : method.typeParameters()) {
        if (signature.length() == 0)
            signature.append("<");
        else
            signature.append(",");
        signature.append(typeVariable.identifier()).append(":");
        // FIXME: only use the first bound
        toSignature(signature, typeVariable.bounds().get(0), typeArgMapper, false);
    }
    if (signature.length() > 0)
        signature.append(">");
    signature.append("(");
    for (Type type : parameters) {
        toSignature(signature, type, typeArgMapper, false);
    }
    signature.append(")");
    toSignature(signature, method.returnType(), typeArgMapper, false);
    return signature.toString();
}
 
Example #11
Source File: SchemaFactory.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
/**
 * Introspect into the given Class to generate a Schema model. The boolean indicates
 * whether this class type should be turned into a reference.
 *
 * @param index the index of classes being scanned
 * @param type the implementation type of the item to scan
 * @param schemaReferenceSupported
 */
static Schema readClassSchema(IndexView index, Type type, boolean schemaReferenceSupported) {
    if (type == null) {
        return null;
    }
    Schema schema;
    if (type.kind() == Type.Kind.ARRAY) {
        schema = new SchemaImpl().type(SchemaType.ARRAY);
        ArrayType array = type.asArrayType();
        int dimensions = array.dimensions();
        Type componentType = array.component();

        if (dimensions > 1) {
            // Recurse using a new array type with dimensions decremented
            schema.items(readClassSchema(index, ArrayType.create(componentType, dimensions - 1), schemaReferenceSupported));
        } else {
            // Recurse using the type of the array elements
            schema.items(readClassSchema(index, componentType, schemaReferenceSupported));
        }
    } else if (type.kind() == Type.Kind.PRIMITIVE) {
        schema = OpenApiDataObjectScanner.process(type.asPrimitiveType());
    } else {
        schema = introspectClassToSchema(index, type.asClassType(), schemaReferenceSupported);
    }
    return schema;
}
 
Example #12
Source File: Types.java    From quarkus with Apache License 2.0 6 votes vote down vote up
static Type box(Primitive primitive) {
    switch (primitive) {
        case BOOLEAN:
            return Type.create(DotNames.BOOLEAN, Kind.CLASS);
        case DOUBLE:
            return Type.create(DotNames.DOUBLE, Kind.CLASS);
        case FLOAT:
            return Type.create(DotNames.FLOAT, Kind.CLASS);
        case LONG:
            return Type.create(DotNames.LONG, Kind.CLASS);
        case INT:
            return Type.create(DotNames.INTEGER, Kind.CLASS);
        case BYTE:
            return Type.create(DotNames.BYTE, Kind.CLASS);
        case CHAR:
            return Type.create(DotNames.CHARACTER, Kind.CLASS);
        case SHORT:
            return Type.create(DotNames.SHORT, Kind.CLASS);
        default:
            throw new IllegalArgumentException("Unsupported primitive: " + primitive);
    }
}
 
Example #13
Source File: HibernateSearchElasticsearchProcessor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static void addReflectiveType(IndexView index, Set<DotName> reflectiveClassCollector,
        Set<Type> reflectiveTypeCollector, Type type) {
    if (type instanceof VoidType || type instanceof PrimitiveType || type instanceof UnresolvedTypeVariable) {
        return;
    } else if (type instanceof ClassType) {
        ClassInfo classInfo = index.getClassByName(type.name());
        addReflectiveClass(index, reflectiveClassCollector, reflectiveTypeCollector, classInfo);
    } else if (type instanceof ArrayType) {
        addReflectiveType(index, reflectiveClassCollector, reflectiveTypeCollector, type.asArrayType().component());
    } else if (type instanceof ParameterizedType) {
        ParameterizedType parameterizedType = type.asParameterizedType();
        addReflectiveType(index, reflectiveClassCollector, reflectiveTypeCollector, parameterizedType.owner());
        for (Type typeArgument : parameterizedType.arguments()) {
            addReflectiveType(index, reflectiveClassCollector, reflectiveTypeCollector, typeArgument);
        }
    }
}
 
Example #14
Source File: Classes.java    From smallrye-graphql with Apache License 2.0 6 votes vote down vote up
/**
 * Check if this type is a Number (or collection of numbers)
 * 
 * @param type the type to check
 * @return true if it is
 */
public static boolean isNumberLikeTypeOrCollectionThereOf(Type type) {
    return isTypeOrCollectionThereOf(type,
            BYTE,
            BYTE_PRIMATIVE,
            SHORT,
            SHORT_PRIMATIVE,
            INTEGER,
            INTEGER_PRIMATIVE,
            BIG_INTEGER,
            DOUBLE,
            DOUBLE_PRIMATIVE,
            BIG_DECIMAL,
            LONG,
            LONG_PRIMATIVE,
            FLOAT,
            FLOAT_PRIMATIVE);
}
 
Example #15
Source File: JaxRsAnnotationScanner.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isAsyncResponse(final MethodInfo method) {
    return method.parameters()
            .stream()
            .map(Type::name)
            .anyMatch(JaxRsConstants.ASYNC_RESPONSE::equals);
}
 
Example #16
Source File: ExpectationTests.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
/**
 * Unresolvable type parameter.
 */
@Test
public void testUnresolvable() throws IOException, JSONException {
    DotName bar = createSimple(Bar.class.getName());
    OpenApiDataObjectScanner scanner = new OpenApiDataObjectScanner(index, ClassType.create(bar, Type.Kind.CLASS));

    Schema result = scanner.process();

    printToConsole(bar.local(), result);
    assertJsonEquals(bar.local(), "unresolvable.expected.json", result);
}
 
Example #17
Source File: TypeUtilTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsA_IndexedSubjectImplementsObject() {
    final Class<?> subjectClass = CustomCollection.class;
    Index index = indexOf(subjectClass);
    Type testSubject = Type.create(DotName.createSimple(subjectClass.getName()), Type.Kind.CLASS);
    boolean result = TypeUtil.isA(index, testSubject, TYPE_COLLECTION);
    assertTrue(result);
}
 
Example #18
Source File: IndexClassLookupUtils.java    From quarkus with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param index
 * @param type
 * @return the class for the given type or {@code null} for primitives, arrays and
 */
static ClassInfo getClassByName(IndexView index, Type type) {
    if (type != null && (type.kind() == Kind.CLASS || type.kind() == Kind.PARAMETERIZED_TYPE)) {
        return getClassByName(index, type.name());
    }
    return null;
}
 
Example #19
Source File: HibernateOrmPanacheRestProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep
void findEntityResources(CombinedIndexBuildItem index, BuildProducer<RestDataResourceBuildItem> resourcesProducer) {
    for (ClassInfo classInfo : index.getIndex().getKnownDirectImplementors(PANACHE_ENTITY_RESOURCE_INTERFACE)) {
        validateResource(index.getIndex(), classInfo);
        List<Type> generics = getGenericTypes(classInfo);
        String entityClassName = generics.get(0).toString();
        String idClassName = generics.get(1).toString();
        RestDataResourceInfo resourceInfo = HibernateOrmRestDataResourceInfo
                .withEntityAccess(classInfo, idClassName, entityClassName);
        resourcesProducer.produce(new RestDataResourceBuildItem(resourceInfo));
    }
}
 
Example #20
Source File: ExpectationTests.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenericsWithBounds() throws IOException, JSONException {
    String name = GenericTypeTestContainer.class.getName();
    Type pType = getFieldFromKlazz(name, "genericWithBounds").type();
    OpenApiDataObjectScanner scanner = new OpenApiDataObjectScanner(index, pType);

    Schema result = scanner.process();

    printToConsole(name, result);
    assertJsonEquals(name, "generic.withBounds.expected.json", result);
}
 
Example #21
Source File: TypeUtil.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
public static boolean isPrimitiveWrapper(PrimitiveType primitive, Type wrapped) {
    Class<?> wrapperType;

    switch (primitive.primitive()) {
        case BOOLEAN:
            wrapperType = Boolean.class;
            break;
        case BYTE:
            wrapperType = Byte.class;
            break;
        case CHAR:
            wrapperType = Character.class;
            break;
        case DOUBLE:
            wrapperType = Double.class;
            break;
        case FLOAT:
            wrapperType = Float.class;
            break;
        case INT:
            wrapperType = Integer.class;
            break;
        case LONG:
            wrapperType = Long.class;
            break;
        case SHORT:
            wrapperType = Short.class;
            break;
        default:
            throw UtilMessages.msg.unknownPrimitive(primitive);
    }

    return DotName.createSimple(wrapperType.getName()).equals(wrapped.name());
}
 
Example #22
Source File: IgnoreTests.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testIgnore_jsonbTransientField() throws IOException, JSONException {
    DotName name = DotName.createSimple(JsonbTransientOnFieldExample.class.getName());
    OpenApiDataObjectScanner scanner = new OpenApiDataObjectScanner(index,
            ClassType.create(name, Type.Kind.CLASS));

    Schema result = scanner.process();

    printToConsole(name.local(), result);
    assertJsonEquals(name.local(), "ignore.jsonbTransientField.expected.json", result);
}
 
Example #23
Source File: TypeUtilTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsA_UnindexedPrimitiveWrapperSubjectUnrelatedToObject() {
    final Class<?> subjectClass = Integer.class;
    final DotName subjectName = DotName.createSimple(subjectClass.getName());
    Index index = indexOf();
    Type testSubject = Type.create(subjectName, Type.Kind.CLASS);
    boolean result = TypeUtil.isA(index, testSubject, TYPE_COLLECTION);
    assertFalse(result);
}
 
Example #24
Source File: Classes.java    From smallrye-graphql with Apache License 2.0 5 votes vote down vote up
/**
 * Check if this type is a Date (or collection of numbers)
 * 
 * @param type the type to check
 * @return true if it is
 */
public static boolean isDateLikeTypeOrCollectionThereOf(Type type) {
    return isTypeOrCollectionThereOf(type,
            LOCALDATE,
            LOCALTIME,
            LOCALDATETIME,
            ZONEDDATETIME,
            OFFSETDATETIME,
            OFFSETTIME,
            UTIL_DATE,
            SQL_DATE,
            SQL_TIMESTAMP,
            SQL_TIME);
}
 
Example #25
Source File: SmallRyeOpenApiProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep
public void registerOpenApiSchemaClassesForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
        BuildProducer<ReflectiveHierarchyBuildItem> reflectiveHierarchy,
        OpenApiFilteredIndexViewBuildItem openApiFilteredIndexViewBuildItem,
        Capabilities capabilities) {

    if (shouldScanAnnotations(capabilities)) {
        FilteredIndexView index = openApiFilteredIndexViewBuildItem.getIndex();
        // Generate reflection declaration from MP OpenAPI Schema definition
        // They are needed for serialization.
        Collection<AnnotationInstance> schemaAnnotationInstances = index.getAnnotations(OPENAPI_SCHEMA);
        for (AnnotationInstance schemaAnnotationInstance : schemaAnnotationInstances) {
            AnnotationTarget typeTarget = schemaAnnotationInstance.target();
            if (typeTarget.kind() != AnnotationTarget.Kind.CLASS) {
                continue;
            }
            reflectiveHierarchy
                    .produce(new ReflectiveHierarchyBuildItem(Type.create(typeTarget.asClass().name(), Type.Kind.CLASS),
                            IgnoreDotNames.IGNORE_FOR_REFLECTION_PREDICATE));
        }

        // Generate reflection declaration from MP OpenAPI APIResponse schema definition
        // They are needed for serialization
        Collection<AnnotationInstance> apiResponseAnnotationInstances = index.getAnnotations(OPENAPI_RESPONSE);
        registerReflectionForApiResponseSchemaSerialization(reflectiveClass, reflectiveHierarchy,
                apiResponseAnnotationInstances);

        // Generate reflection declaration from MP OpenAPI APIResponses schema definition
        // They are needed for serialization
        Collection<AnnotationInstance> apiResponsesAnnotationInstances = index.getAnnotations(OPENAPI_RESPONSES);
        for (AnnotationInstance apiResponsesAnnotationInstance : apiResponsesAnnotationInstances) {
            AnnotationValue apiResponsesAnnotationValue = apiResponsesAnnotationInstance.value();
            if (apiResponsesAnnotationValue == null) {
                continue;
            }
            registerReflectionForApiResponseSchemaSerialization(reflectiveClass, reflectiveHierarchy,
                    Arrays.asList(apiResponsesAnnotationValue.asNestedArray()));
        }
    }
}
 
Example #26
Source File: EventBusCodecProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static Type extractPayloadTypeFromReturn(MethodInfo method) {
    Type returnType = method.returnType();
    if (returnType.kind() == Type.Kind.CLASS) {
        return returnType;
    } else if (returnType.kind() == Type.Kind.PARAMETERIZED_TYPE) {
        ParameterizedType returnedParamType = returnType.asParameterizedType();
        if (!returnedParamType.arguments().isEmpty()
                && (returnedParamType.name().equals(COMPLETION_STAGE) || returnedParamType.name().equals(UNI))) {
            return returnedParamType.arguments().get(0);
        } else {
            return returnedParamType;
        }
    }
    return null;
}
 
Example #27
Source File: DataObjectDeque.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
private boolean argsEqual(PathEntry otherPair) {
    ParameterizedType thisClazzPType = clazzType.asParameterizedType();
    ParameterizedType otherClazzPType = otherPair.clazzType.asParameterizedType();

    List<Type> thisArgs = thisClazzPType.arguments();
    List<Type> otherArgs = otherClazzPType.arguments();
    return thisArgs.equals(otherArgs);
}
 
Example #28
Source File: Types.java    From quarkus with Apache License 2.0 5 votes vote down vote up
static <T extends Type> Map<TypeVariable, Type> buildResolvedMap(List<T> resolvedArguments,
        List<TypeVariable> typeVariables,
        Map<TypeVariable, Type> resolvedTypeParameters, IndexView index) {
    Map<TypeVariable, Type> resolvedMap = new HashMap<>();
    for (int i = 0; i < resolvedArguments.size(); i++) {
        resolvedMap.put(typeVariables.get(i), resolveTypeParam(resolvedArguments.get(i), resolvedTypeParameters, index));
    }
    return resolvedMap;
}
 
Example #29
Source File: SimpleGeneratorTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@BeforeAll
public static void init() throws IOException {
    TestClassOutput classOutput = new TestClassOutput();
    Index index = index(MyService.class, PublicMyService.class, BaseService.class, MyItem.class, String.class,
            CompletionStage.class,
            List.class);
    ValueResolverGenerator generator = new ValueResolverGenerator(index, classOutput, Collections.emptyMap());
    ClassInfo myServiceClazz = index.getClassByName(DotName.createSimple(MyService.class.getName()));
    generator.generate(myServiceClazz);
    generator.generate(index.getClassByName(DotName.createSimple(PublicMyService.class.getName())));
    generator.generate(index.getClassByName(DotName.createSimple(MyItem.class.getName())));
    generator.generate(index.getClassByName(DotName.createSimple(String.class.getName())));
    generator.generate(index.getClassByName(DotName.createSimple(List.class.getName())));
    generatedTypes.addAll(generator.getGeneratedTypes());

    ExtensionMethodGenerator extensionMethodGenerator = new ExtensionMethodGenerator(classOutput);
    MethodInfo extensionMethod = index.getClassByName(DotName.createSimple(MyService.class.getName())).method(
            "getDummy", Type.create(myServiceClazz.name(), Kind.CLASS), PrimitiveType.INT,
            Type.create(DotName.createSimple(String.class.getName()), Kind.CLASS));
    extensionMethodGenerator.generate(extensionMethod, null, null);
    extensionMethod = index.getClassByName(DotName.createSimple(MyService.class.getName())).method(
            "getDummy", Type.create(myServiceClazz.name(), Kind.CLASS), PrimitiveType.INT,
            PrimitiveType.LONG);
    extensionMethodGenerator.generate(extensionMethod, null, null);
    extensionMethod = index.getClassByName(DotName.createSimple(MyService.class.getName())).method(
            "getDummyVarargs", Type.create(myServiceClazz.name(), Kind.CLASS), PrimitiveType.INT,
            Type.create(DotName.createSimple("[L" + String.class.getName() + ";"), Kind.ARRAY));
    extensionMethodGenerator.generate(extensionMethod, null, null);
    generatedTypes.addAll(extensionMethodGenerator.getGeneratedTypes());
}
 
Example #30
Source File: ArrayCreatorTest.java    From smallrye-graphql with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotCreateArrayForCompletableFuture() {
    final ParameterizedType completableFuture = ParameterizedType.create(Classes.COMPLETABLE_FUTURE,
            new Type[] { STRING_TYPE }, null);

    assertFalse(ArrayCreator.createArray(completableFuture).isPresent());
}