Skip to content
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

MergedAnnotation meta-data support #22909

Merged
merged 14 commits into from
May 7, 2019
Merged

Conversation

philwebb
Copy link
Member

@philwebb philwebb commented May 6, 2019

This PR is primarily for #22884 but it also covers a few more issues. Since it's quite a large set of changes it feels better to have a PR that we can review, rather than just merging.

I've run a full Spring Framework and Spring Boot build locally with these changes applied without any obvious issues being found.

philwebb added 14 commits May 6, 2019 16:36
Extract the inner classes from package-info into their own files to
prevent local build problems and to make them easier to find.
Add a `getTypeHierarchy()` method to `MergedAnnotation` that can be used
to return the full type hierarchy information. This method is
specifically designed to be used in combination with
`MergedAnnotationPredicates.unique`.

This update also allows us to delete the `parentAndType` method
from `AnnotatedElementUtils`.

Closes spring-projectsgh-22908
Rename `from` to `of` for the `MergedAnnotation` factory methods that
work with Maps. The previous name was a little confusing, especially
when an annotation source parameter was specified. The new method name
helps to make it clearer when the user is explicitly defining the
attributes of the annotation, as opposed to picking them up from the
source.
Update TypeMappedAnnotation so that Strings can be used to represent
Class attribute values. This will allow ASM annotation readers to
present a `MergedAnnotation` instance without necessarily having the
actual class values on the classpath.

When the underlying value is a String, any calls to
`getValue(name, String.class)` or `asMap(Adapt.CLASS_TO_STRING)` will
simply return the original String. Calls that need the actual Class
result (such as `getClass`) will use `Class.forName` and may throw
a `ClassNotFoundException` at that point.

This commit also allows an empty Object[] to be used to represent
any empty primitive array.

See spring-projectsgh-22884
Add a factory method to `MergedAnnotation` that allows an instance to
be created for an explicit collection of root annotations. This method
will allow ASM based readers to expose a `MergedAnnotation` instance
that has root annotations loaded from bytecode, and meta-annotations
loaded using reflection.

See spring-projectsgh-22884
Update ASM based metadata readers so that only RetentionPolicy.RUNTIME
annotations are exposed. This aligned behavior with the reflection based
implementation.

Closes spring-projectsgh-22886
Update `StandardAnnotationMetadata` and `AnnotationMetadataReadingVisitor`
so that `java.lang.annotation` annotations are consistently skipped.

Closes spring-projectsgh-22885
Update `StandardAnnotationMetadata` to use `ReflectionUtils` when
obtaining declared methods. This update is primarily so that the common
method cache can be used.

Closes spring-projectsgh-22907
Add some additional tests to provide more coverage of class and method
meta-data support.

See spring-projectsgh-22884
Extract and pull-up some common method implementations and make them
default methods of the interface.

See spring-projectsgh-22884
Add `AnnotatedTypeMetaData.getAnnotations()` that can be used to access
annotation details using the `MergedAnnotations` interface.

Where possible, the existing annotation methods have been migrated to
call `getAnnotation()`, rather than needing their own implementation.

The existing ASM based meta-data implementations have not been updated
since they will be deprecated and replaced in a subsequent commit.

See spring-projectsgh-22884
Replace the existing ASM based readers with new implementations that
also support MergedAnnotations. The meta-data classes themselves are
now immutable, and constructed via separate reader classes.

The `SimpleMetadataReader` class has been updated to return the new
classes, however the old ones remain since some of them are public
and might be being used directly.

Closes spring-projectsgh-22884
Deprecate the public `StandardMetadata` constructors to make it clearer
that these classes should not be instantiated directly. A new
`AnnotationMetadata.introspect` factory method has been added which
can now be used to obtain instances.

This change will allow use to make the constructors package private
and drop the `nestedAnnotationsAsMap` parameter in a future release.

Closes spring-projectsgh-22906
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 6, 2019
@jhoeller jhoeller self-assigned this May 6, 2019
@jhoeller jhoeller added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels May 6, 2019
@jhoeller jhoeller added this to the 5.2 M2 milestone May 6, 2019
@jhoeller jhoeller merged commit 7031964 into spring-projects:master May 7, 2019
jhoeller added a commit that referenced this pull request May 7, 2019
Includes fix for typo in visitor class names.

See gh-22909
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

Successfully merging this pull request may close these issues.

3 participants