Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue May 24, 2015 · 3 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented May 24, 2015

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:

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented May 25, 2015

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!

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented May 28, 2015

Sam Brannen commented

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

Feedback is welcome!

@spring-projects-issues
Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants