void registerReflectiveClasses()

in extensions/bindy/deployment/src/main/java/org/apache/camel/quarkus/component/bindy/deployment/BindyProcessor.java [61:145]


    void registerReflectiveClasses(CombinedIndexBuildItem index, BuildProducer<ReflectiveClassBuildItem> producer) {

        // BreakIterators are needed when counting graphemes
        producer.produce(
                ReflectiveClassBuildItem.builder("com.ibm.icu.text.BreakIteratorFactory").build());

        IndexView idx = index.getIndex();

        // Registering the class for classes annotated with @CsvRecord, @FixedLengthRecord or @Message
        Stream.of(CsvRecord.class, FixedLengthRecord.class, Message.class)
                .map(clazz -> DotName.createSimple(clazz.getName()))
                .flatMap(dotName -> idx.getAnnotations(dotName).stream())
                .filter(anno -> anno.target() != null && anno.target().kind() == Kind.CLASS)
                .map(anno -> anno.target().asClass().name().toString())
                .forEach(className -> {
                    LOG.debugf("Registering root model class as reflective: %s", className);
                    producer.produce(ReflectiveClassBuildItem.builder(className).fields().build());
                });

        // Registering the class for fields annotated with @Link
        Stream.of(Link.class)
                .map(clazz -> DotName.createSimple(clazz.getName()))
                .flatMap(dotName -> idx.getAnnotations(dotName).stream())
                .filter(anno -> anno.target() != null && anno.target().kind() == Kind.FIELD)
                .forEach(anno -> {
                    String className = anno.target().asField().type().name().toString();
                    LOG.debugf("Registering @Link model class as reflective: %s", className);
                    producer.produce(ReflectiveClassBuildItem.builder(className).fields().build());
                });

        // Registering the class of the first parameterized type argument for fields annotated with @OnetoMany
        Stream.of(OneToMany.class)
                .map(clazz -> DotName.createSimple(clazz.getName()))
                .flatMap(dotName -> idx.getAnnotations(dotName).stream())
                .filter(anno -> anno.target() != null && anno.target().kind() == Kind.FIELD)
                .filter(anno -> anno.target().asField().type().kind() == org.jboss.jandex.Type.Kind.PARAMETERIZED_TYPE)
                .forEach(anno -> {
                    ParameterizedType fieldType = anno.target().asField().type().asParameterizedType();
                    if (fieldType.arguments().size() >= 1) {
                        String className = fieldType.arguments().get(0).name().toString();
                        LOG.debugf("Registering @OneToMany model class as reflective: %s", className);
                        producer.produce(ReflectiveClassBuildItem.builder(className).fields().build());
                    }
                });

        // Registering the @BindyConverter.value() class for fields annotated with @BindyConverter
        Stream.of(BindyConverter.class)
                .map(clazz -> DotName.createSimple(clazz.getName()))
                .flatMap(dotName -> idx.getAnnotations(dotName).stream())
                .forEach(anno -> {
                    String className = anno.value().asClass().name().toString();
                    LOG.debugf("Registering @BindyConverter class as reflective: %s", className);
                    producer.produce(ReflectiveClassBuildItem.builder(className).methods().build());
                });

        // Registering @FormatFactories.value() classes for fields annotated with @FormatFactories
        Stream.of(FormatFactories.class)
                .map(clazz -> DotName.createSimple(clazz.getName()))
                .flatMap(dotName -> idx.getAnnotations(dotName).stream())
                .forEach(anno -> {
                    for (org.jboss.jandex.Type t : anno.value().asClassArray()) {
                        LOG.debugf("Registering @FormatFactories class as reflective: %s", t.name().toString());
                        producer.produce(
                                ReflectiveClassBuildItem.builder(t.name().toString()).build());
                    }
                });

        // Registering @DataField.method() classes for fields annotated with @DataField and using the method parameter
        Stream.of(DataField.class)
                .map(clazz -> DotName.createSimple(clazz.getName()))
                .flatMap(dotName -> idx.getAnnotations(dotName).stream())
                .filter(anno -> anno.value("method") != null && !anno.value("method").asString().isEmpty())
                .filter(anno -> anno.target() != null && anno.target().kind() == Kind.FIELD)
                .forEach(anno -> {
                    String method = anno.value("method").asString();
                    String methodClazz;
                    if (method.contains(".")) {
                        methodClazz = method.substring(0, method.lastIndexOf('.'));
                    } else {
                        methodClazz = anno.target().asField().type().toString();
                    }
                    LOG.debugf("Registering @DataField.method() class as reflective: %s", methodClazz);
                    producer.produce(ReflectiveClassBuildItem.builder(methodClazz).methods().build());
                });
    }