private Stream register()

in arthur-impl/src/main/java/org/apache/geronimo/arthur/impl/nativeimage/generator/extension/AnnotationExtension.java [123:199]


    private Stream<ClassReflectionModel> register(final Class<?> clazz, final RegisterClass config) {
        final ClassReflectionModel reflectionModel = new ClassReflectionModel();
        reflectionModel.setName(clazz.getName());
        if (config.all()) {
            reflectionModel.setAllDeclaredClasses(true);
            reflectionModel.setAllDeclaredConstructors(true);
            reflectionModel.setAllDeclaredMethods(true);
            reflectionModel.setAllDeclaredFields(true);
        } else {
            if (config.allDeclaredClasses()) {
                reflectionModel.setAllDeclaredClasses(true);
            }
            if (config.allDeclaredConstructors()) {
                reflectionModel.setAllDeclaredConstructors(true);
            }
            if (config.allDeclaredMethods()) {
                reflectionModel.setAllDeclaredMethods(true);
            }
            if (config.allPublicClasses()) {
                reflectionModel.setAllPublicClasses(true);
            }
            if (config.allPublicConstructors()) {
                reflectionModel.setAllPublicConstructors(true);
            }
            if (config.allPublicMethods()) {
                reflectionModel.setAllPublicMethods(true);
            }
            if (config.allDeclaredFields()) {
                reflectionModel.setAllDeclaredFields(true);
            }
            if (config.allPublicFields()) {
                reflectionModel.setAllPublicFields(true);
            }
        }

        final List<ClassReflectionModel.FieldReflectionModel> registeredFields = Stream.of(clazz.getDeclaredFields())
                .filter(field -> field.isAnnotationPresent(RegisterField.class))
                .map(field -> {
                    final ClassReflectionModel.FieldReflectionModel fieldReflectionModel = new ClassReflectionModel.FieldReflectionModel();
                    fieldReflectionModel.setName(field.getName());
                    if (field.getAnnotation(RegisterField.class).allowWrite()) {
                        fieldReflectionModel.setAllowWrite(true);
                    }
                    return fieldReflectionModel;
                })
                .collect(toList());
        if ((config.allDeclaredFields() || config.allPublicFields()) && !registeredFields.isEmpty()) {
            throw new IllegalArgumentException("Don't use allDeclaredFields and allPublicFields with @RegisterField: " + clazz);
        } else if (!registeredFields.isEmpty()) {
            reflectionModel.setFields(registeredFields);
        }

        final List<ClassReflectionModel.MethodReflectionModel> registeredMethods = Stream.of(clazz.getDeclaredMethods())
                .filter(method -> method.isAnnotationPresent(RegisterMethod.class))
                .map(field -> {
                    final ClassReflectionModel.MethodReflectionModel methodReflectionModel = new ClassReflectionModel.MethodReflectionModel();
                    methodReflectionModel.setName(field.getName());
                    methodReflectionModel.setParameterTypes(asList(field.getParameterTypes()));
                    return methodReflectionModel;
                })
                .collect(toList());
        if ((config.allDeclaredMethods() || config.allPublicMethods()) && !registeredMethods.isEmpty()) {
            throw new IllegalArgumentException("Don't use allDeclaredFields and allDeclaredMethods with @RegisterMethod: " + clazz);
        } else if (!registeredMethods.isEmpty()) {
            reflectionModel.setMethods(registeredMethods);
        }

        final Stream<ClassReflectionModel> model = Stream.of(reflectionModel);
        final Class<?> superclass = clazz.getSuperclass();
        if (superclass != null && superclass != Object.class && superclass != clazz) {
            return Stream.concat(
                    register(superclass, ofNullable(superclass.getAnnotation(RegisterClass.class)).orElse(config)),
                    model);
        }

        return model;
    }