|
21 | 21 | import java.util.LinkedHashSet;
|
22 | 22 | import java.util.Map;
|
23 | 23 | import java.util.Set;
|
| 24 | +import java.util.function.Predicate; |
24 | 25 | import java.util.stream.Collectors;
|
25 | 26 | import java.util.stream.Stream;
|
26 | 27 |
|
@@ -181,6 +182,7 @@ default MultiValueMap<String, Object> getAllAnnotationAttributes(
|
181 | 182 | * or an empty set if none were found
|
182 | 183 | * @since 6.1
|
183 | 184 | * @see #getMergedRepeatableAnnotationAttributes(Class, Class, boolean, boolean)
|
| 185 | + * @see #getMergedRepeatableAnnotationAttributes(Class, Class, Predicate, boolean, boolean) |
184 | 186 | */
|
185 | 187 | default Set<AnnotationAttributes> getMergedRepeatableAnnotationAttributes(
|
186 | 188 | Class<? extends Annotation> annotationType, Class<? extends Annotation> containerType,
|
@@ -216,12 +218,58 @@ default Set<AnnotationAttributes> getMergedRepeatableAnnotationAttributes(
|
216 | 218 | * or an empty set if none were found
|
217 | 219 | * @since 6.1
|
218 | 220 | * @see #getMergedRepeatableAnnotationAttributes(Class, Class, boolean)
|
| 221 | + * @see #getMergedRepeatableAnnotationAttributes(Class, Class, Predicate, boolean, boolean) |
219 | 222 | */
|
220 | 223 | default Set<AnnotationAttributes> getMergedRepeatableAnnotationAttributes(
|
221 | 224 | Class<? extends Annotation> annotationType, Class<? extends Annotation> containerType,
|
222 | 225 | boolean classValuesAsString, boolean sortByReversedMetaDistance) {
|
223 | 226 |
|
| 227 | + return getMergedRepeatableAnnotationAttributes(annotationType, containerType, |
| 228 | + mergedAnnotation -> true, classValuesAsString, sortByReversedMetaDistance); |
| 229 | + } |
| 230 | + |
| 231 | + /** |
| 232 | + * Retrieve all <em>repeatable annotations</em> of the given type within the |
| 233 | + * annotation hierarchy <em>above</em> the underlying element (as direct |
| 234 | + * annotation or meta-annotation); and for each annotation found, merge that |
| 235 | + * annotation's attributes with <em>matching</em> attributes from annotations |
| 236 | + * in lower levels of the annotation hierarchy and store the results in an |
| 237 | + * instance of {@link AnnotationAttributes}. |
| 238 | + * <p>{@link org.springframework.core.annotation.AliasFor @AliasFor} semantics |
| 239 | + * are fully supported, both within a single annotation and within annotation |
| 240 | + * hierarchies. |
| 241 | + * <p>The supplied {@link Predicate} will be used to filter the results. For |
| 242 | + * example, supply {@code mergedAnnotation -> true} to include all annotations |
| 243 | + * in the results; supply {@code MergedAnnotation::isDirectlyPresent} to limit |
| 244 | + * the results to directly declared annotations, etc. |
| 245 | + * <p>If the {@code sortByReversedMetaDistance} flag is set to {@code true}, |
| 246 | + * the results will be sorted in {@link Comparator#reversed() reversed} order |
| 247 | + * based on each annotation's {@linkplain MergedAnnotation#getDistance() |
| 248 | + * meta distance}, which effectively orders meta-annotations before annotations |
| 249 | + * that are declared directly on the underlying element. |
| 250 | + * @param annotationType the annotation type to find |
| 251 | + * @param containerType the type of the container that holds the annotations |
| 252 | + * @param predicate a {@code Predicate} to apply to each {@code MergedAnnotation} |
| 253 | + * to determine if it should be included in the results |
| 254 | + * @param classValuesAsString whether to convert class references to {@code String} |
| 255 | + * class names for exposure as values in the returned {@code AnnotationAttributes}, |
| 256 | + * instead of {@code Class} references which might potentially have to be loaded |
| 257 | + * first |
| 258 | + * @param sortByReversedMetaDistance {@code true} if the results should be |
| 259 | + * sorted in reversed order based on each annotation's meta distance |
| 260 | + * @return the set of all merged repeatable {@code AnnotationAttributes} found, |
| 261 | + * or an empty set if none were found |
| 262 | + * @since 6.1.2 |
| 263 | + * @see #getMergedRepeatableAnnotationAttributes(Class, Class, boolean) |
| 264 | + * @see #getMergedRepeatableAnnotationAttributes(Class, Class, boolean, boolean) |
| 265 | + */ |
| 266 | + default Set<AnnotationAttributes> getMergedRepeatableAnnotationAttributes( |
| 267 | + Class<? extends Annotation> annotationType, Class<? extends Annotation> containerType, |
| 268 | + Predicate<MergedAnnotation<? extends Annotation>> predicate, boolean classValuesAsString, |
| 269 | + boolean sortByReversedMetaDistance) { |
| 270 | + |
224 | 271 | Stream<MergedAnnotation<Annotation>> stream = getAnnotations().stream()
|
| 272 | + .filter(predicate) |
225 | 273 | .filter(MergedAnnotationPredicates.typeIn(containerType, annotationType));
|
226 | 274 |
|
227 | 275 | if (sortByReversedMetaDistance) {
|
|
0 commit comments