hibernate / hibernate-models

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

Simplified creation and addition of AnnotationUsage references #54

Closed sebersole closed 3 months ago

sebersole commented 3 months ago
interface MutableAnnotationTarget ... {
    ...

    /**
     * Creates a usage and adds it to this target.
     */
    default <A extends Annotation> MutableAnnotationUsage<A> applyAnnotationUsage(
            AnnotationDescriptor<A> annotationType,
            SourceModelBuildingContext buildingContext) {
        return applyAnnotationUsage( annotationType, null, buildingContext );
    }

    /**
     * Creates a usage and adds it to this target, allowing for configuration of the created usage
     */
    default <A extends Annotation> MutableAnnotationUsage<A> applyAnnotationUsage(
            AnnotationDescriptor<A> annotationType,
            Consumer<MutableAnnotationUsage<A>> configuration,
            SourceModelBuildingContext buildingContext) {
        final MutableAnnotationUsage<A> usage = annotationType.createUsage( this, configuration, buildingContext );
        addAnnotationUsage( usage );
        return usage;
    }