Java Code Examples for org.jboss.jandex.Type.Kind#VOID

The following examples show how to use org.jboss.jandex.Type.Kind#VOID . 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: 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 2
Source File: Beans.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static void collectCallbacks(ClassInfo clazz, List<MethodInfo> callbacks, DotName annotation, IndexView index) {
    for (MethodInfo method : clazz.methods()) {
        if (method.hasAnnotation(annotation) && method.returnType().kind() == Kind.VOID && method.parameters().isEmpty()) {
            callbacks.add(method);
        }
    }
    if (clazz.superName() != null) {
        ClassInfo superClass = getClassByName(index, clazz.superName());
        if (superClass != null) {
            collectCallbacks(superClass, callbacks, annotation, index);
        }
    }
}
 
Example 3
Source File: ExtensionMethodGenerator.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public static void validate(MethodInfo method) {
    if (!Modifier.isStatic(method.flags())) {
        throw new IllegalStateException("Template extension method must be static: " + method);
    }
    if (method.returnType().kind() == Kind.VOID) {
        throw new IllegalStateException("Template extension method must not return void: " + method);
    }
    if (method.parameters().isEmpty()) {
        throw new IllegalStateException("Template extension method must declare at least one parameter: " + method);
    }
}
 
Example 4
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 5
Source File: ReflectiveHierarchyStep.java    From quarkus with Apache License 2.0 4 votes vote down vote up
private void addClassTypeHierarchy(CombinedIndexBuildItem combinedIndexBuildItem,
        ReflectiveHierarchyBuildItem reflectiveHierarchyBuildItem,
        String source,
        DotName name,
        Set<DotName> processedReflectiveHierarchies,
        Map<DotName, Set<String>> unindexedClasses,
        Predicate<ClassInfo> finalFieldsWritable,
        BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
    if (reflectiveHierarchyBuildItem.getIgnorePredicate().test(name)) {
        return;
    }

    ClassInfo info = (reflectiveHierarchyBuildItem.getIndex() != null ? reflectiveHierarchyBuildItem.getIndex()
            : combinedIndexBuildItem.getIndex()).getClassByName(name);

    if (info == null) {
        unindexedClasses.putIfAbsent(name, new TreeSet<>());
        unindexedClasses.get(name).add(source);
    }

    if (processedReflectiveHierarchies.contains(name)) {
        return;
    }

    reflectiveClass.produce(
            ReflectiveClassBuildItem
                    .builder(name.toString())
                    .methods(true)
                    .fields(true)
                    .finalFieldsWritable(doFinalFieldsNeedToBeWritable(info, finalFieldsWritable))
                    .build());

    processedReflectiveHierarchies.add(name);

    if (info == null) {
        return;
    }

    addClassTypeHierarchy(combinedIndexBuildItem, reflectiveHierarchyBuildItem, source, info.superName(),
            processedReflectiveHierarchies,
            unindexedClasses, finalFieldsWritable, reflectiveClass);
    for (FieldInfo field : info.fields()) {
        if (Modifier.isStatic(field.flags()) || field.name().startsWith("this$") || field.name().startsWith("val$")) {
            // skip the static fields (especially loggers)
            // also skip the outer class elements (unfortunately, we don't have a way to test for synthetic fields in Jandex)
            continue;
        }
        addReflectiveHierarchy(combinedIndexBuildItem, reflectiveHierarchyBuildItem, source, field.type(),
                processedReflectiveHierarchies,
                unindexedClasses, finalFieldsWritable, reflectiveClass);
    }
    for (MethodInfo method : info.methods()) {
        if (method.parameters().size() > 0 || Modifier.isStatic(method.flags())
                || method.returnType().kind() == Kind.VOID) {
            // we will only consider potential getters
            continue;
        }
        addReflectiveHierarchy(combinedIndexBuildItem, reflectiveHierarchyBuildItem, source, method.returnType(),
                processedReflectiveHierarchies,
                unindexedClasses, finalFieldsWritable, reflectiveClass);
    }
}