Deprecate AnnotationFilter.NONE and document MergedAnnotations design
Closes gh-24932
This commit is contained in:
parent
e36a415994
commit
e5a292fb34
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -21,8 +21,15 @@ import java.lang.annotation.Annotation;
|
||||||
/**
|
/**
|
||||||
* Callback interface that can be used to filter specific annotation types.
|
* Callback interface that can be used to filter specific annotation types.
|
||||||
*
|
*
|
||||||
|
* <p>Note that the {@link MergedAnnotations} model (which this interface has been
|
||||||
|
* designed for) always ignores lang annotations according to the {@link #PLAIN}
|
||||||
|
* filter (for efficiency reasons). Any additional filters and even custom filter
|
||||||
|
* implementations apply within this boundary and may only narrow further from here.
|
||||||
|
*
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
|
* @author Juergen Hoeller
|
||||||
* @since 5.2
|
* @since 5.2
|
||||||
|
* @see MergedAnnotations
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface AnnotationFilter {
|
public interface AnnotationFilter {
|
||||||
|
@ -31,6 +38,7 @@ public interface AnnotationFilter {
|
||||||
* {@link AnnotationFilter} that matches annotations in the
|
* {@link AnnotationFilter} that matches annotations in the
|
||||||
* {@code java.lang} and {@code org.springframework.lang} packages
|
* {@code java.lang} and {@code org.springframework.lang} packages
|
||||||
* and their subpackages.
|
* and their subpackages.
|
||||||
|
* <p>This is the default filter in the {@link MergedAnnotations} model.
|
||||||
*/
|
*/
|
||||||
AnnotationFilter PLAIN = packages("java.lang", "org.springframework.lang");
|
AnnotationFilter PLAIN = packages("java.lang", "org.springframework.lang");
|
||||||
|
|
||||||
|
@ -66,7 +74,12 @@ public interface AnnotationFilter {
|
||||||
/**
|
/**
|
||||||
* {@link AnnotationFilter} that never matches and can be used when no
|
* {@link AnnotationFilter} that never matches and can be used when no
|
||||||
* filtering is needed (allowing for any annotation types to be present).
|
* filtering is needed (allowing for any annotation types to be present).
|
||||||
|
* @deprecated as of 5.2.6 since the {@link MergedAnnotations} model
|
||||||
|
* always ignores lang annotations according to the {@link #PLAIN} filter
|
||||||
|
* (for efficiency reasons)
|
||||||
|
* @see #PLAIN
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
AnnotationFilter NONE = new AnnotationFilter() {
|
AnnotationFilter NONE = new AnnotationFilter() {
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Annotation annotation) {
|
public boolean matches(Annotation annotation) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -119,6 +119,13 @@ import org.springframework.lang.Nullable;
|
||||||
* .forEach(System.out::println);
|
* .forEach(System.out::println);
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
* <p><b>NOTE: The {@code MergedAnnotations} API and its underlying model have
|
||||||
|
* been designed for composable annotations in Spring's common component model,
|
||||||
|
* with a focus on attribute aliasing and meta-annotation relationships.</b>
|
||||||
|
* There is no support for retrieving plain Java annotations with this API;
|
||||||
|
* please use standard Java reflection or Spring's {@link AnnotationUtils}
|
||||||
|
* for simple annotation retrieval purposes.
|
||||||
|
*
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
* @since 5.2
|
* @since 5.2
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -24,7 +24,6 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||||
import org.springframework.core.annotation.AnnotationFilter;
|
|
||||||
import org.springframework.core.annotation.AnnotationUtils;
|
import org.springframework.core.annotation.AnnotationUtils;
|
||||||
import org.springframework.core.annotation.MergedAnnotation;
|
import org.springframework.core.annotation.MergedAnnotation;
|
||||||
import org.springframework.core.annotation.MergedAnnotations;
|
import org.springframework.core.annotation.MergedAnnotations;
|
||||||
|
@ -85,8 +84,7 @@ public class StandardAnnotationMetadata extends StandardClassMetadata implements
|
||||||
public StandardAnnotationMetadata(Class<?> introspectedClass, boolean nestedAnnotationsAsMap) {
|
public StandardAnnotationMetadata(Class<?> introspectedClass, boolean nestedAnnotationsAsMap) {
|
||||||
super(introspectedClass);
|
super(introspectedClass);
|
||||||
this.mergedAnnotations = MergedAnnotations.from(introspectedClass,
|
this.mergedAnnotations = MergedAnnotations.from(introspectedClass,
|
||||||
SearchStrategy.INHERITED_ANNOTATIONS, RepeatableContainers.none(),
|
SearchStrategy.INHERITED_ANNOTATIONS, RepeatableContainers.none());
|
||||||
AnnotationFilter.NONE);
|
|
||||||
this.nestedAnnotationsAsMap = nestedAnnotationsAsMap;
|
this.nestedAnnotationsAsMap = nestedAnnotationsAsMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue