Skip to content

Introduce support for synthesizing AnnotationAttributes into an annotation [SPR-13067] #17659

Closed

Description

@spring-projects-issues

Sam Brannen opened SPR-13067 and commented

This issue picks up where #16137 and #16138 left off, with the primary goal of providing support for synthesizing an annotation from merged AnnotationAttributes like those returned from the getAnnotationAttributes(\*) and findAnnotationAttributes(\*) methods in AnnotatedElementUtils.


Issue Links:

Activity

  1. spring-projects-issues commented on May 25, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    The "holy grail of annotation processing" is in the air... ;)

    I have pushed a working prototype for this issue to a #17659 feature branch.

    Fee free to follow along or make comments!

  2. spring-projects-issues commented on May 28, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    Update: the latest and greatest has been pushed to #17659.

    Feedback is welcome!

  3. spring-projects-issues commented on May 28, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    This has been implemented as described in the comments for GitHub commit e30c9b2:

    Synthesize annotation from a map of attributes

    Spring Framework 4.2 RC1 introduced support for synthesizing an
    annotation from an existing annotation in order to provide additional
    functionality above and beyond that provided by Java. Specifically,
    such synthesized annotations provide support for @AliasFor semantics.
    As luck would have it, the same principle can be used to synthesize an
    annotation from any map of attributes, and in particular, from an
    instance of AnnotationAttributes.

    The following highlight the major changes in this commit toward
    achieving this goal.

    • Introduced AnnotationAttributeExtractor abstraction and refactored
      SynthesizedAnnotationInvocationHandler to delegate to an
      AnnotationAttributeExtractor.

    • Extracted code from SynthesizedAnnotationInvocationHandler into new
      AbstractAliasAwareAnnotationAttributeExtractor and
      DefaultAnnotationAttributeExtractor implementation classes.

    • Introduced MapAnnotationAttributeExtractor for synthesizing an
      annotation that is backed by a map or AnnotationAttributes instance.

    • Introduced a variant of synthesizeAnnotation() in AnnotationUtils
      that accepts a map.

    • Introduced findAnnotation(*) methods in AnnotatedElementUtils that
      synthesize merged AnnotationAttributes back into an annotation of the
      target type.

    The following classes have been refactored to use the new support for
    synthesizing AnnotationAttributes back into an annotation.

    • ApplicationListenerMethodAdapter
    • TestAnnotationUtils
    • AbstractTestContextBootstrapper
    • ActiveProfilesUtils
    • ContextLoaderUtils
    • DefaultActiveProfilesResolver
    • DirtiesContextTestExecutionListener
    • TestPropertySourceAttributes
    • TestPropertySourceUtils
    • TransactionalTestExecutionListener
    • MetaAnnotationUtils
    • MvcUriComponentsBuilder
    • RequestMappingHandlerMapping

    In addition, this commit also includes changes to ensure that arrays
    returned by synthesized annotations are properly cloned first.

  4. added
    type: enhancement
    in: core
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coretype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions