org.jboss.jandex.Type.Kind Java Examples

The following examples show how to use org.jboss.jandex.Type.Kind. 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: ConfigBuildStep.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@BuildStep
@Record(RUNTIME_INIT)
void validateConfigProperties(ConfigRecorder recorder, List<ConfigPropertyBuildItem> configProperties,
        BeanContainerBuildItem beanContainer, BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
    // IMPL NOTE: we do depend on BeanContainerBuildItem to make sure that the BeanDeploymentValidator finished its processing

    // the non-primitive types need to be registered for reflection since Class.forName is used at runtime to load the class
    for (ConfigPropertyBuildItem item : configProperties) {
        Type requiredType = item.getPropertyType();
        String propertyType = requiredType.name().toString();
        if (requiredType.kind() != Kind.PRIMITIVE) {
            reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, propertyType));
        }
    }

    Map<String, Set<String>> propNamesToClasses = configProperties.stream().collect(
            groupingBy(ConfigPropertyBuildItem::getPropertyName,
                    mapping(c -> c.getPropertyType().name().toString(), toSet())));
    recorder.validateConfigProperties(propNamesToClasses);
}
 
Example #2
Source File: ConfigBuildStep.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private boolean isHandledByProducers(Type type) {
    if (type.kind() == Kind.ARRAY) {
        return false;
    }
    if (type.kind() == Kind.PRIMITIVE) {
        return true;
    }
    return DotNames.STRING.equals(type.name()) ||
            DotNames.OPTIONAL.equals(type.name()) ||
            SET_NAME.equals(type.name()) ||
            LIST_NAME.equals(type.name()) ||
            DotNames.LONG.equals(type.name()) ||
            DotNames.FLOAT.equals(type.name()) ||
            DotNames.INTEGER.equals(type.name()) ||
            DotNames.BOOLEAN.equals(type.name()) ||
            DotNames.DOUBLE.equals(type.name()) ||
            DotNames.SHORT.equals(type.name()) ||
            DotNames.BYTE.equals(type.name()) ||
            DotNames.CHARACTER.equals(type.name());
}
 
Example #3
Source File: MethodNameParser.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private List<ClassInfo> getMappedSuperClassInfos(IndexView indexView, ClassInfo entityClass) {
    List<ClassInfo> mappedSuperClassInfos = new ArrayList<>(3);
    Type superClassType = entityClass.superClassType();
    while (superClassType != null && !superClassType.name().equals(DotNames.OBJECT)) {
        ClassInfo superClass = indexView.getClassByName(entityClass.superName());
        if (superClass.classAnnotation(DotNames.JPA_MAPPED_SUPERCLASS) != null) {
            mappedSuperClassInfos.add(superClass);
        }

        if (superClassType.kind() == Kind.CLASS) {
            superClassType = indexView.getClassByName(superClassType.name()).superClassType();
        } else if (superClassType.kind() == Kind.PARAMETERIZED_TYPE) {
            ParameterizedType parameterizedType = superClassType.asParameterizedType();
            superClassType = parameterizedType.owner();
        }
    }
    if (mappedSuperClassInfos.size() > 0) {
        return mappedSuperClassInfos;
    }
    return Collections.emptyList();
}
 
Example #4
Source File: CustomQueryMethodsAdder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private Type verifyQueryResultType(Type t) {
    if (isIntLongOrBoolean(t.name())) {
        return t;
    }
    if (t.kind() == Kind.ARRAY) {
        return verifyQueryResultType(t.asArrayType().component());
    } else if (t.kind() == Kind.PARAMETERIZED_TYPE) {
        List<Type> list = t.asParameterizedType().arguments();
        if (list.size() == 1) {
            return verifyQueryResultType(list.get(0));
        } else {
            for (Type x : list) {
                verifyQueryResultType(x);
            }
            return t;
        }
    } else if (!DotNames.OBJECT.equals(t.name())) {
        ClassInfo typeClassInfo = index.getClassByName(t.name());
        if (typeClassInfo == null) {
            throw new IllegalStateException(t.name() + " was not part of the Quarkus index");
        }
    }
    return t;
}
 
Example #5
Source File: Types.java    From quarkus with Apache License 2.0 6 votes vote down vote up
static Set<Type> getProducerFieldTypeClosure(FieldInfo producerField, BeanDeployment beanDeployment) {
    Set<Type> types;
    Type fieldType = producerField.type();
    if (fieldType.kind() == Kind.PRIMITIVE || fieldType.kind() == Kind.ARRAY) {
        types = new HashSet<>();
        types.add(fieldType);
        types.add(OBJECT_TYPE);
    } else {
        ClassInfo fieldClassInfo = getClassByName(beanDeployment.getIndex(), producerField.type());
        if (fieldClassInfo == null) {
            throw new IllegalArgumentException("Producer field type not found in index: " + producerField.type().name());
        }
        if (Kind.CLASS.equals(fieldType.kind())) {
            types = getTypeClosure(fieldClassInfo, producerField, Collections.emptyMap(), beanDeployment, null);
        } else if (Kind.PARAMETERIZED_TYPE.equals(fieldType.kind())) {
            types = getTypeClosure(fieldClassInfo, producerField,
                    buildResolvedMap(fieldType.asParameterizedType().arguments(), fieldClassInfo.typeParameters(),
                            Collections.emptyMap(), beanDeployment.getIndex()),
                    beanDeployment, null);
        } else {
            throw new IllegalArgumentException("Unsupported return type");
        }
    }
    return restrictBeanTypes(types, beanDeployment.getAnnotations(producerField));
}
 
Example #6
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 #7
Source File: AsmUtil.java    From quarkus with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the bytecode instruction to load the given Jandex Type. This returns the specialised
 * bytecodes <tt>ILOAD, DLOAD, FLOAD and LLOAD</tt> for primitives, or <tt>ALOAD</tt> otherwise.
 * 
 * @param jandexType The Jandex Type whose load instruction to return.
 * @return The bytecode instruction to load the given Jandex Type.
 */
public static int getLoadOpcode(Type jandexType) {
    if (jandexType.kind() == Kind.PRIMITIVE) {
        switch (jandexType.asPrimitiveType().primitive()) {
            case BOOLEAN:
            case BYTE:
            case SHORT:
            case INT:
            case CHAR:
                return Opcodes.ILOAD;
            case DOUBLE:
                return Opcodes.DLOAD;
            case FLOAT:
                return Opcodes.FLOAD;
            case LONG:
                return Opcodes.LLOAD;
            default:
                throw new IllegalArgumentException("Unknown primitive type: " + jandexType);
        }
    }
    return Opcodes.ALOAD;
}
 
Example #8
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 #9
Source File: BeanDeploymentValidatorTest.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Override
public void validate(ValidationContext context) {
    assertFalse(context.removedBeans().withBeanClass(UselessBean.class).isEmpty());

    assertFalse(context.beans().classBeans().withBeanClass(Alpha.class).isEmpty());
    assertFalse(context.beans().syntheticBeans().withBeanType(EmptyStringListCreator.listStringType())
            .isEmpty());
    List<BeanInfo> namedAlpha = context.beans().withName("alpha").collect();
    assertEquals(1, namedAlpha.size());
    assertEquals(Alpha.class.getName(), namedAlpha.get(0).getBeanClass().toString());

    Collection<ObserverInfo> observers = context.get(Key.OBSERVERS);

    List<BeanInfo> namedClassWithObservers = context.beans().classBeans().namedBeans().stream()
            .filter(b -> observers.stream().anyMatch(o -> o.getDeclaringBean().equals(b))).collect(Collectors.toList());
    assertEquals(1, namedClassWithObservers.size());
    assertEquals(Alpha.class.getName(), namedClassWithObservers.get(0).getBeanClass().toString());

    assertTrue(observers
            .stream()
            .anyMatch(o -> o.getObservedType()
                    .equals(Type.create(DotName.createSimple(Object.class.getName()), Kind.CLASS))));
    // We do not test a validation problem - ArcTestContainer rule would fail
}
 
Example #10
Source File: AsmUtil.java    From quarkus with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a return bytecode instruction suitable for the given return Jandex Type. This will return
 * specialised return instructions <tt>IRETURN, LRETURN, FRETURN, DRETURN, RETURN</tt> for primitives/void,
 * and <tt>ARETURN</tt> otherwise;
 * 
 * @param typeDescriptor the return Jandex Type.
 * @return the correct bytecode return instruction for that return type descriptor.
 */
public static int getReturnInstruction(Type jandexType) {
    if (jandexType.kind() == Kind.PRIMITIVE) {
        switch (jandexType.asPrimitiveType().primitive()) {
            case BOOLEAN:
            case BYTE:
            case SHORT:
            case INT:
            case CHAR:
                return Opcodes.IRETURN;
            case DOUBLE:
                return Opcodes.DRETURN;
            case FLOAT:
                return Opcodes.FRETURN;
            case LONG:
                return Opcodes.LRETURN;
            default:
                throw new IllegalArgumentException("Unknown primitive type: " + jandexType);
        }
    } else if (jandexType.kind() == Kind.VOID) {
        return Opcodes.RETURN;
    }
    return Opcodes.ARETURN;
}
 
Example #11
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 = index.getClassByName(parameterizedType.name());
        if (classInfo != null) {
            List<TypeVariable> typeParameters = classInfo.typeParameters();
            List<Type> arguments = parameterizedType.arguments();
            Type[] typeParams = new Type[typeParameters.size()];
            for (int i = 0; i < typeParameters.size(); i++) {
                typeParams[i] = resolveTypeParam(arguments.get(i), resolvedTypeParameters, index);
            }
            return ParameterizedType.create(parameterizedType.name(), typeParams, null);
        }
    }
    return typeParam;
}
 
Example #12
Source File: Types.java    From quarkus with Apache License 2.0 6 votes vote down vote up
static boolean containsTypeVariable(Type type) {
    if (type.kind() == Type.Kind.TYPE_VARIABLE) {
        return true;
    }
    if (type instanceof ParameterizedType) {
        for (Type t : type.asParameterizedType().arguments()) {
            if (containsTypeVariable(t)) {
                return true;
            }
        }
    }
    if (type.kind() == Type.Kind.ARRAY) {
        return containsTypeVariable(type.asArrayType().component());
    }
    return false;
}
 
Example #13
Source File: SchedulerProcessor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@BuildStep
AnnotationsTransformerBuildItem annotationTransformer(CustomScopeAnnotationsBuildItem scopes) {
    return new AnnotationsTransformerBuildItem(new AnnotationsTransformer() {

        @Override
        public boolean appliesTo(org.jboss.jandex.AnnotationTarget.Kind kind) {
            return kind == org.jboss.jandex.AnnotationTarget.Kind.CLASS;
        }

        @Override
        public void transform(TransformationContext context) {
            ClassInfo target = context.getTarget().asClass();
            if (!scopes.isScopeIn(context.getAnnotations())
                    && (target.annotations().containsKey(SCHEDULED_NAME)
                            || target.annotations().containsKey(SCHEDULES_NAME))) {
                // Class with no scope annotation but with @Scheduled method
                LOGGER.debugf("Found scheduled business methods on a class %s with no scope defined - adding @Singleton",
                        context.getTarget());
                context.transform().add(Singleton.class).done();
            }
        }
    });
}
 
Example #14
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 #15
Source File: AbstractGenerator.java    From quarkus with Apache License 2.0 6 votes vote down vote up
protected String getPackageName(BeanInfo bean) {
    DotName providerTypeName;
    if (bean.isProducerMethod() || bean.isProducerField()) {
        providerTypeName = bean.getDeclaringBean().getProviderType().name();
    } else {
        if (bean.getProviderType().kind() == Kind.ARRAY || bean.getProviderType().kind() == Kind.PRIMITIVE) {
            providerTypeName = bean.getImplClazz().name();
        } else {
            providerTypeName = bean.getProviderType().name();
        }
    }
    String packageName = DotNames.packageName(providerTypeName);
    if (packageName.isEmpty() || packageName.startsWith("java.")) {
        // It is not possible to place a class in a JDK package or in default package
        packageName = DEFAULT_PACKAGE;
    }
    return packageName;
}
 
Example #16
Source File: SchedulerProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep
void validateScheduledBusinessMethods(SchedulerConfig config, List<ScheduledBusinessMethodItem> scheduledMethods,
        ValidationPhaseBuildItem validationPhase, BuildProducer<ValidationErrorBuildItem> validationErrors) {
    List<Throwable> errors = new ArrayList<>();
    Map<String, AnnotationInstance> encounteredIdentities = new HashMap<>();

    for (ScheduledBusinessMethodItem scheduledMethod : scheduledMethods) {
        MethodInfo method = scheduledMethod.getMethod();

        // Validate method params and return type
        List<Type> params = method.parameters();
        if (params.size() > 1
                || (params.size() == 1 && !params.get(0).equals(SCHEDULED_EXECUTION_TYPE))) {
            errors.add(new IllegalStateException(String.format(
                    "Invalid scheduled business method parameters %s [method: %s, bean: %s]", params,
                    method, scheduledMethod.getBean())));
        }
        if (!method.returnType().kind().equals(Type.Kind.VOID)) {
            errors.add(new IllegalStateException(
                    String.format("Scheduled business method must return void [method: %s, bean: %s]",
                            method, scheduledMethod.getBean())));
        }
        // Validate cron() and every() expressions
        CronParser parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(config.cronType));
        for (AnnotationInstance scheduled : scheduledMethod.getSchedules()) {
            Throwable error = validateScheduled(parser, scheduled, encounteredIdentities);
            if (error != null) {
                errors.add(error);
            }
        }
    }

    if (!errors.isEmpty()) {
        validationErrors.produce(new ValidationErrorBuildItem(errors));
    }
}
 
Example #17
Source File: TypeInfos.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static Type resolveType(String value) {
    int angleIdx = value.indexOf(LEFT_ANGLE);
    if (angleIdx == -1) {
        return Type.create(DotName.createSimple(value), Kind.CLASS);
    } else {
        String name = value.substring(0, angleIdx);
        DotName rawName = DotName.createSimple(name);
        String[] parts = value.substring(angleIdx + 1, value.length() - 1).split(",");
        Type[] arguments = new Type[parts.length];
        for (int i = 0; i < arguments.length; i++) {
            arguments[i] = resolveType(parts[i]);
        }
        return ParameterizedType.create(rawName, arguments, null);
    }
}
 
Example #18
Source File: CacheMethodValidator.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public static void validateAnnotations(AnnotationStore annotationStore, BeanInfo bean, MethodInfo method,
        List<Throwable> throwables) {

    AnnotationInstance cacheResult = annotationStore.getAnnotation(method, CACHE_RESULT);
    if (cacheResult != null && method.returnType().kind() == Kind.VOID) {
        String exceptionMessage = "The @CacheResult annotation is not allowed on a method returning void: [class= "
                + bean.getBeanClass() + ", method= " + method + "]";
        throwables.add(new IllegalReturnTypeException(exceptionMessage));
    }
}
 
Example #19
Source File: TypeUtil.java    From serianalyzer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param i
 * @return
 * @throws SerianalyzerException
 */
static String makeSignature ( MethodInfo i, boolean fix ) throws SerianalyzerException {

    StringBuilder sb = new StringBuilder();
    sb.append('(');
    ClassInfo declaringImpl = i.declaringClass();
    if ( fix && "<init>".equals(i.name()) && declaringImpl.nestingType() == NestingType.INNER ) { //$NON-NLS-1$
        // there seems to be some sort of bug, missing the the outer instance parameter in the constructor
        if ( !Modifier.isStatic(declaringImpl.flags()) ) {
            org.jboss.jandex.Type enclosingClass = org.jboss.jandex.Type.create(declaringImpl.enclosingClass(), Kind.CLASS);
            org.jboss.jandex.Type firstArg = i.parameters().size() > 0 ? i.parameters().get(0) : null;
            if ( firstArg instanceof TypeVariable ) {
                firstArg = firstArg.asTypeVariable().bounds().get(0);
            }
            if ( firstArg == null || !firstArg.equals(enclosingClass) ) {
                sb.append(toString(enclosingClass));
            }
        }
    }

    for ( org.jboss.jandex.Type p : i.parameters() ) {
        sb.append(toString(p));
    }
    sb.append(')');
    sb.append(toString(i.returnType()));
    return sb.toString();
}
 
Example #20
Source File: PanacheRepositoryEnhancer.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private boolean needsJvmBridge(org.jboss.jandex.Type type) {
    if (type.kind() == Kind.TYPE_VARIABLE) {
        String typeParamName = type.asTypeVariable().identifier();
        return typeArguments.containsKey(typeParamName);
    }
    return false;
}
 
Example #21
Source File: AsmUtil.java    From quarkus with Apache License 2.0 5 votes vote down vote up
/**
 * Calls the right boxing method for the given Jandex Type if it is a primitive.
 * 
 * @param mv The MethodVisitor on which to visit the boxing instructions
 * @param jandexType The Jandex Type to box if it is a primitive.
 */
public static void boxIfRequired(MethodVisitor mv, Type jandexType) {
    if (jandexType.kind() == Kind.PRIMITIVE) {
        switch (jandexType.asPrimitiveType().primitive()) {
            case BOOLEAN:
                mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;", false);
                break;
            case BYTE:
                mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;", false);
                break;
            case CHAR:
                mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Character", "valueOf", "(C)Ljava/lang/Character;",
                        false);
                break;
            case DOUBLE:
                mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;", false);
                break;
            case FLOAT:
                mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;", false);
                break;
            case INT:
                mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false);
                break;
            case LONG:
                mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false);
                break;
            case SHORT:
                mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;", false);
                break;
            default:
                throw new IllegalArgumentException("Unknown primitive type: " + jandexType);
        }
    }
}
 
Example #22
Source File: AsmUtil.java    From quarkus with Apache License 2.0 5 votes vote down vote up
/**
 * Calls the right unboxing method for the given Jandex Type if it is a primitive.
 * 
 * @param mv The MethodVisitor on which to visit the unboxing instructions
 * @param jandexType The Jandex Type to unbox if it is a primitive.
 */
public static void unboxIfRequired(MethodVisitor mv, Type jandexType) {
    if (jandexType.kind() == Kind.PRIMITIVE) {
        switch (jandexType.asPrimitiveType().primitive()) {
            case BOOLEAN:
                unbox(mv, "java/lang/Boolean", "booleanValue", "Z");
                break;
            case BYTE:
                unbox(mv, "java/lang/Byte", "byteValue", "B");
                break;
            case CHAR:
                unbox(mv, "java/lang/Character", "charValue", "C");
                break;
            case DOUBLE:
                unbox(mv, "java/lang/Double", "doubleValue", "D");
                break;
            case FLOAT:
                unbox(mv, "java/lang/Float", "floatValue", "F");
                break;
            case INT:
                unbox(mv, "java/lang/Integer", "intValue", "I");
                break;
            case LONG:
                unbox(mv, "java/lang/Long", "longValue", "J");
                break;
            case SHORT:
                unbox(mv, "java/lang/Short", "shortValue", "S");
                break;
            default:
                throw new IllegalArgumentException("Unknown primitive type: " + jandexType);
        }
    }
}
 
Example #23
Source File: AsmUtil.java    From quarkus with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the number of underlying bytecode parameters taken by the given Jandex parameter Type.
 * This will be 2 for doubles and longs, 1 otherwise.
 * 
 * @param paramType the Jandex parameter Type
 * @return the number of underlying bytecode parameters required.
 */
public static int getParameterSize(Type paramType) {
    if (paramType.kind() == Kind.PRIMITIVE) {
        switch (paramType.asPrimitiveType().primitive()) {
            case DOUBLE:
            case LONG:
                return 2;
        }
    }
    return 1;
}
 
Example #24
Source File: JandexUtil.java    From quarkus with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a type for a ClassInfo
 */
private static Type getType(ClassInfo inputClassInfo, IndexView index) {
    List<TypeVariable> typeParameters = inputClassInfo.typeParameters();
    if (typeParameters.isEmpty())
        return ClassType.create(inputClassInfo.name(), Kind.CLASS);
    Type owner = null;
    // ignore owners for non-static classes
    if (inputClassInfo.enclosingClass() != null && !Modifier.isStatic(inputClassInfo.flags())) {
        owner = getType(fetchFromIndex(inputClassInfo.enclosingClass(), index), index);
    }
    return ParameterizedType.create(inputClassInfo.name(), typeParameters.toArray(new Type[0]), owner);
}
 
Example #25
Source File: JandexUtilTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testAbstractSingle() {
    final Index index = index(Single.class, AbstractSingle.class);
    final DotName impl = DotName.createSimple(AbstractSingle.class.getName());
    List<Type> ret = JandexUtil.resolveTypeParameters(impl, SIMPLE, index);
    assertThat(ret).hasSize(1).allMatch(t -> t.kind() == Kind.TYPE_VARIABLE && t.asTypeVariable().identifier().equals("S"));
}
 
Example #26
Source File: KafkaProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep
public void withSasl(BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
        BuildProducer<ReflectiveHierarchyBuildItem> reflectiveHierarchy) {

    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, AbstractLogin.DefaultLoginCallbackHandler.class));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, SaslClientCallbackHandler.class));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, DefaultLogin.class));

    final Type loginModuleType = Type
            .create(DotName.createSimple(LoginModule.class.getName()), Kind.CLASS);

    reflectiveHierarchy.produce(new ReflectiveHierarchyBuildItem(loginModuleType));
}
 
Example #27
Source File: JaxRsAnnotationScannerTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Override
public void registerCustomSchemas(SchemaRegistry schemaRegistry) {
    Type uuidType = Type.create(componentize(UUID.class.getName()), Kind.CLASS);
    Schema schema = new SchemaImpl();
    schema.setType(Schema.SchemaType.STRING);
    schema.setFormat("uuid");
    schema.setPattern("^[a-f0-9]{8}-?[a-f0-9]{4}-?[1-5][a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}$");
    schema.setTitle("UUID");
    schema.setDescription("Universally Unique Identifier");
    schema.setExample("de8681db-b4d6-4c47-a428-4b959c1c8e9a");
    schemaRegistry.register(uuidType, schema);
}
 
Example #28
Source File: Types.java    From quarkus with Apache License 2.0 5 votes vote down vote up
static Type getProviderType(ClassInfo classInfo) {
    List<TypeVariable> typeParameters = classInfo.typeParameters();
    if (!typeParameters.isEmpty()) {
        return ParameterizedType.create(classInfo.name(), typeParameters.toArray(new Type[] {}), null);
    } else {
        return Type.create(classInfo.name(), Kind.CLASS);
    }
}
 
Example #29
Source File: Types.java    From quarkus with Apache License 2.0 5 votes vote down vote up
static Set<Type> getProducerMethodTypeClosure(MethodInfo producerMethod, BeanDeployment beanDeployment) {
    Set<Type> types;
    Type returnType = producerMethod.returnType();
    if (returnType.kind() == Kind.PRIMITIVE || returnType.kind() == Kind.ARRAY) {
        types = new HashSet<>();
        types.add(returnType);
        types.add(OBJECT_TYPE);
        return types;
    } else {
        ClassInfo returnTypeClassInfo = getClassByName(beanDeployment.getIndex(), returnType);
        if (returnTypeClassInfo == null) {
            throw new IllegalArgumentException(
                    "Producer method return type not found in index: " + producerMethod.returnType().name());
        }
        if (Kind.CLASS.equals(returnType.kind())) {
            types = getTypeClosure(returnTypeClassInfo, producerMethod, Collections.emptyMap(), beanDeployment, null);
        } else if (Kind.PARAMETERIZED_TYPE.equals(returnType.kind())) {
            types = getTypeClosure(returnTypeClassInfo, producerMethod,
                    buildResolvedMap(returnType.asParameterizedType().arguments(), returnTypeClassInfo.typeParameters(),
                            Collections.emptyMap(), beanDeployment.getIndex()),
                    beanDeployment, null);
        } else {
            throw new IllegalArgumentException("Unsupported return type");
        }
    }
    return restrictBeanTypes(types, beanDeployment.getAnnotations(producerMethod));
}
 
Example #30
Source File: BeanResolver.java    From quarkus with Apache License 2.0 5 votes vote down vote up
static boolean containsUnboundedTypeVariablesOrObjects(List<Type> types) {
    for (Type type : types) {
        if (ClassType.OBJECT_TYPE.equals(type)) {
            continue;
        }
        if (Kind.TYPE_VARIABLE.equals(type.kind())) {
            List<Type> bounds = type.asTypeVariable().bounds();
            if (bounds.isEmpty() || bounds.size() == 1 && ClassType.OBJECT_TYPE.equals(bounds.get(0))) {
                continue;
            }
        }
        return false;
    }
    return true;
}