hibernate / hibernate-models

An abstraction over "reflection" and annotations
Apache License 2.0
2 stars 5 forks source link

Simplified creation of attributes for dynamic models #53

Closed sebersole closed 3 months ago

sebersole commented 3 months ago

E.g.

class DynamicClassDetails ... {
    ...

    public DynamicFieldDetails applyAttribute(
            String name,
            ClassDetails type,
            boolean isArray,
            boolean isPlural,
            Consumer<DynamicFieldDetails> configuration,
            SourceModelBuildingContext context) {
        return applyAttribute(
                name,
                new ClassTypeDetailsImpl( type, TypeDetails.Kind.CLASS ),
                isArray,
                isPlural,
                configuration,
                context
        );
    }

    public DynamicFieldDetails applyAttribute(
            String name,
            TypeDetails type,
            boolean isArray,
            boolean isPlural,
            Consumer<DynamicFieldDetails> configuration,
            SourceModelBuildingContext context) {
        final DynamicFieldDetails attribute = new DynamicFieldDetails(
                name,
                type,
                this,
                DYNAMIC_ATTRIBUTE_MODIFIERS,
                isArray,
                isPlural,
                context
        );
        if ( configuration != null ) {
            configuration.accept( attribute );
        }
        addField( attribute );
        return attribute;
    }
}