|
68 | 68 | */
|
69 | 69 | public abstract class MetaAnnotationUtils {
|
70 | 70 |
|
71 |
| - private static final ConcurrentLruCache<Class<?>, SearchStrategy> cachedSearchStrategies = |
72 |
| - new ConcurrentLruCache<>(32, MetaAnnotationUtils::lookUpSearchStrategy); |
| 71 | + private static final ConcurrentLruCache<Class<?>, EnclosingConfiguration> cachedSearchStrategies = |
| 72 | + new ConcurrentLruCache<>(32, MetaAnnotationUtils::lookUpEnclosingConfiguration); |
73 | 73 |
|
74 | 74 |
|
75 | 75 | /**
|
@@ -301,35 +301,29 @@ private static UntypedAnnotationDescriptor findAnnotationDescriptorForTypes(@Nul
|
301 | 301 | * class should be searched
|
302 | 302 | * @since 5.3
|
303 | 303 | * @see ClassUtils#isInnerClass(Class)
|
304 |
| - * @see #getSearchStrategy(Class) |
305 | 304 | */
|
306 | 305 | public static boolean searchEnclosingClass(Class<?> clazz) {
|
307 | 306 | return (ClassUtils.isInnerClass(clazz) &&
|
308 |
| - getSearchStrategy(clazz) == SearchStrategy.TYPE_HIERARCHY_AND_ENCLOSING_CLASSES); |
| 307 | + getEnclosingConfiguration(clazz) == EnclosingConfiguration.INHERIT); |
309 | 308 | }
|
310 | 309 |
|
311 | 310 | /**
|
312 |
| - * Get the {@link SearchStrategy} for the supplied class. |
| 311 | + * Get the {@link EnclosingConfiguration} mode for the supplied class. |
313 | 312 | * @param clazz the class for which the search strategy should be resolved
|
314 | 313 | * @return the resolved search strategy
|
315 | 314 | * @since 5.3
|
316 | 315 | */
|
317 |
| - private static SearchStrategy getSearchStrategy(Class<?> clazz) { |
| 316 | + private static EnclosingConfiguration getEnclosingConfiguration(Class<?> clazz) { |
318 | 317 | return cachedSearchStrategies.get(clazz);
|
319 | 318 | }
|
320 | 319 |
|
321 |
| - private static SearchStrategy lookUpSearchStrategy(Class<?> clazz) { |
322 |
| - EnclosingConfiguration enclosingConfiguration = |
323 |
| - MergedAnnotations.from(clazz, SearchStrategy.TYPE_HIERARCHY_AND_ENCLOSING_CLASSES) |
| 320 | + private static EnclosingConfiguration lookUpEnclosingConfiguration(Class<?> clazz) { |
| 321 | + // TODO Make the default EnclosingConfiguration mode globally configurable via SpringProperties. |
| 322 | + return MergedAnnotations.from(clazz, SearchStrategy.TYPE_HIERARCHY_AND_ENCLOSING_CLASSES) |
324 | 323 | .stream(NestedTestConfiguration.class)
|
325 | 324 | .map(mergedAnnotation -> mergedAnnotation.getEnum("value", EnclosingConfiguration.class))
|
326 | 325 | .findFirst()
|
327 |
| - .orElse(EnclosingConfiguration.OVERRIDE); |
328 |
| - // TODO Switch the default EnclosingConfiguration mode to INHERIT. |
329 |
| - // TODO Make the default EnclosingConfiguration mode globally configurable via SpringProperties. |
330 |
| - return (enclosingConfiguration == EnclosingConfiguration.INHERIT ? |
331 |
| - SearchStrategy.TYPE_HIERARCHY_AND_ENCLOSING_CLASSES : |
332 |
| - SearchStrategy.TYPE_HIERARCHY); |
| 326 | + .orElse(EnclosingConfiguration.INHERIT); |
333 | 327 | }
|
334 | 328 |
|
335 | 329 | private static void assertNonEmptyAnnotationTypeArray(Class<?>[] annotationTypes, String message) {
|
@@ -505,10 +499,12 @@ public AnnotationDescriptor<T> next() {
|
505 | 499 | */
|
506 | 500 | @SuppressWarnings("unchecked")
|
507 | 501 | public Set<T> findAllLocalMergedAnnotations() {
|
508 |
| - Class<T> annotationType = (Class<T>) getAnnotationType(); |
509 |
| - SearchStrategy searchStrategy = getSearchStrategy(getRootDeclaringClass()); |
| 502 | + SearchStrategy searchStrategy = |
| 503 | + (getEnclosingConfiguration(getRootDeclaringClass()) == EnclosingConfiguration.INHERIT ? |
| 504 | + SearchStrategy.TYPE_HIERARCHY_AND_ENCLOSING_CLASSES : |
| 505 | + SearchStrategy.TYPE_HIERARCHY); |
510 | 506 | return MergedAnnotations.from(getRootDeclaringClass(), searchStrategy, RepeatableContainers.none())
|
511 |
| - .stream(annotationType) |
| 507 | + .stream((Class<T>) getAnnotationType()) |
512 | 508 | .filter(MergedAnnotationPredicates.firstRunOf(MergedAnnotation::getAggregateIndex))
|
513 | 509 | .collect(MergedAnnotationCollectors.toAnnotationSet());
|
514 | 510 | }
|
|
0 commit comments