-
Notifications
You must be signed in to change notification settings - Fork 38k
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
Create replacement API for handling merged annotations [SPR-17161] #21697
Comments
Phil Webb commented Some initial prototype work for this is here: https://github.com/philwebb/spring-framework/tree/annotations The new API tries to separate the representation of merged annotations from the way that they're discovered. This helps to reduce the surface area of the API since
The // is an annotation present or meta-present
mergedAnnotations.isPresent(ExampleAnnotation.class);
// get the merged "value" attribute of ExampleAnnotation (either direct or meta-present)
mergedAnnotations.get(ExampleAnnotation.class).getString("value");
// get all meta-annotations but no direct annotations
mergedAnnotations.stream().anyMatch(MergedAnnotation::isMetaPresent);
// get all ExampleAnnotation declarations (include any meta-annotations) and print the merged "value" attributes
mergedAnnotations.stream(ExampleAnnotation.class).map(a -> a.getString("value")).forEach(System.out::println);
|
Add a new test class to help cover annotation introspection failure handling. These tests were previously missing and are important to ensure that annotation util code changes don't introduce regressions. See spring-projectsgh-21697
Add new `MergedAnnotations` and `MergedAnnotation` interfaces that attempt to provide a uniform way for dealing with merged annotations. Specifically, the new API provides alternatives for the static methods in `AnnotationUtils` and `AnnotatedElementUtils` and supports Spring's comprehensive annotation attribute `@AliasFor` features. The interfaces also open the possibility of the same API being exposed from the `AnnotationMetadata` interface. Additional utility classes for collecting, filtering and selecting annotations have also been added. Typical usage for the new API would be something like: MergedAnnotations.from(Example.class) .stream(MyAnnotation.class) .map(a -> a.getString("value")) .forEach(System.out::println); Closes spring-projectsgh-21697
Add `createIfAnnotationPresent` method to `AnnotationAttributes` so that a `MergedAnnotation` instance can be quickly converted to an `AnnotationAttributes` Map. The method is specifically designed to work with the `asMap` method when the new API is not being used directly. For example: AnnotationAttributes attributes = mergedAnnotation.asMap( AnnotationAttributes::createIfAnnotationPresent); See spring-projectsgh-21697
Refine the element filtering performed by `AnnotationsScanner` to also cover `org.springframework.util` and most `com.sun` classes which turn out to be referenced quite frequently and which we know contain no useful annotations. See spring-projectsgh-21697
Add a new test class to help cover annotation introspection failure handling. These tests were previously missing and are important to ensure that annotation util code changes don't introduce regressions. See spring-projectsgh-21697
Add new `MergedAnnotations` and `MergedAnnotation` interfaces that attempt to provide a uniform way for dealing with merged annotations. Specifically, the new API provides alternatives for the static methods in `AnnotationUtils` and `AnnotatedElementUtils` and supports Spring's comprehensive annotation attribute `@AliasFor` features. The interfaces also open the possibility of the same API being exposed from the `AnnotationMetadata` interface. Additional utility classes for collecting, filtering and selecting annotations have also been added. Typical usage for the new API would be something like: MergedAnnotations.from(Example.class) .stream(MyAnnotation.class) .map(a -> a.getString("value")) .forEach(System.out::println); Closes spring-projectsgh-21697
Refine the element filtering performed by `AnnotationsScanner` to also cover `org.springframework.util` and most `com.sun` classes which turn out to be referenced quite frequently and which we know contain no useful annotations. See spring-projectsgh-21697
Add a new test class to help cover annotation introspection failure handling. These tests were previously missing and are important to ensure that annotation util code changes don't introduce regressions. See gh-21697
Refine the element filtering performed by `AnnotationsScanner` to also cover `org.springframework.util` and most `com.sun` classes which turn out to be referenced quite frequently and which we know contain no useful annotations. See gh-21697
For consistency within the framework, this commit renames the SUPER_CLASS enum constant to SUPERCLASS. See gh-21697
Add tests for `MissingMergedAnnotation` See gh-21697
Phil Webb opened SPR-17161 and commented
The existing
AnnotationUtils
andAnnotatedElementUtils
have grown quite a bit over the years and could do with being revisited now that we have pretty comprehensive support for merged annotations throughout the framework.Some common issues with the current utils classes include:
AnnotatedTypeMetadata
and the utils and the meta-data API is different.A new API could help us to determine which methods are really needed and provide the potential for more intelligent caching or pre-computed data.
Affects: 5.1 RC1
The text was updated successfully, but these errors were encountered: