diff --git a/spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java b/spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java index e65187543d..e891b58a24 100644 --- a/spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java +++ b/spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,7 +48,8 @@ import org.springframework.util.StringUtils; @SuppressWarnings("serial") public class SpringCacheAnnotationParser implements CacheAnnotationParser, Serializable { - private static final Set> CACHE_OPERATION_ANNOTATIONS = Set.of(Cacheable.class, CacheEvict.class, CachePut.class, Caching.class); + private static final Set> CACHE_OPERATION_ANNOTATIONS = + Set.of(Cacheable.class, CacheEvict.class, CachePut.class, Caching.class); @Override diff --git a/spring-core/src/main/java/org/springframework/aot/hint/annotation/ReflectiveRuntimeHintsRegistrar.java b/spring-core/src/main/java/org/springframework/aot/hint/annotation/ReflectiveRuntimeHintsRegistrar.java index eb7ed7ed68..f860745a50 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/annotation/ReflectiveRuntimeHintsRegistrar.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/annotation/ReflectiveRuntimeHintsRegistrar.java @@ -25,7 +25,6 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.Consumer; -import java.util.stream.Stream; import org.springframework.aot.hint.ReflectionHints; import org.springframework.aot.hint.RuntimeHints; @@ -33,8 +32,10 @@ import org.springframework.core.annotation.MergedAnnotations; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; +import static org.springframework.core.annotation.MergedAnnotations.SearchStrategy.TYPE_HIERARCHY; + /** - * Process {@link Reflective} annotated elements. + * Process {@link Reflective @Reflective} annotated elements. * * @author Stephane Nicoll * @author Andy Wilkinson @@ -53,12 +54,12 @@ public class ReflectiveRuntimeHintsRegistrar { */ public void registerRuntimeHints(RuntimeHints runtimeHints, Class... types) { Set entries = new HashSet<>(); - Arrays.stream(types).forEach(type -> { + for (Class type : types) { processType(entries, type); for (Class implementedInterface : ClassUtils.getAllInterfacesForClass(type)) { processType(entries, implementedInterface); } - }); + } entries.forEach(entry -> { AnnotatedElement element = entry.element(); entry.processor().registerReflectionHints(runtimeHints.reflection(), element); @@ -86,20 +87,21 @@ public class ReflectiveRuntimeHintsRegistrar { } private boolean isReflective(AnnotatedElement element) { - return MergedAnnotations.from(element, MergedAnnotations.SearchStrategy.TYPE_HIERARCHY).isPresent(Reflective.class); + return MergedAnnotations.from(element, TYPE_HIERARCHY).isPresent(Reflective.class); } @SuppressWarnings("unchecked") private Entry createEntry(AnnotatedElement element) { - List processors = - MergedAnnotations.from(element, MergedAnnotations.SearchStrategy.TYPE_HIERARCHY) - .stream(Reflective.class).flatMap(annotation -> Stream.of(annotation.getClassArray("value"))) - .map(type -> (Class) type) - .distinct() - .map(processorClass -> this.processors.computeIfAbsent(processorClass, this::instantiateClass)) - .toList(); + List processors = MergedAnnotations.from(element, TYPE_HIERARCHY) + .stream(Reflective.class) + .map(annotation -> annotation.getClassArray("value")) + .flatMap(Arrays::stream) + .map(type -> (Class) type) + .distinct() + .map(processorClass -> this.processors.computeIfAbsent(processorClass, this::instantiateClass)) + .toList(); ReflectiveProcessor processorToUse = (processors.size() == 1 ? processors.get(0) - : new DelegateReflectiveProcessor(processors)); + : new DelegatingReflectiveProcessor(processors)); return new Entry(element, processorToUse); } @@ -114,11 +116,11 @@ public class ReflectiveRuntimeHintsRegistrar { } } - static class DelegateReflectiveProcessor implements ReflectiveProcessor { + private static class DelegatingReflectiveProcessor implements ReflectiveProcessor { private final Iterable processors; - public DelegateReflectiveProcessor(Iterable processors) { + DelegatingReflectiveProcessor(Iterable processors) { this.processors = processors; } diff --git a/spring-core/src/test/java/org/springframework/aot/hint/annotation/ReflectiveRuntimeHintsRegistrarTests.java b/spring-core/src/test/java/org/springframework/aot/hint/annotation/ReflectiveRuntimeHintsRegistrarTests.java index 9db9c47737..2ab6d86a7f 100644 --- a/spring-core/src/test/java/org/springframework/aot/hint/annotation/ReflectiveRuntimeHintsRegistrarTests.java +++ b/spring-core/src/test/java/org/springframework/aot/hint/annotation/ReflectiveRuntimeHintsRegistrarTests.java @@ -132,6 +132,7 @@ class ReflectiveRuntimeHintsRegistrarTests { this.registrar.registerRuntimeHints(this.runtimeHints, beanClass); } + @Reflective @SuppressWarnings("unused") static class SampleTypeAnnotatedBean { @@ -139,7 +140,6 @@ class ReflectiveRuntimeHintsRegistrarTests { private String notManaged; public void notManaged() { - } } @@ -148,13 +148,10 @@ class ReflectiveRuntimeHintsRegistrarTests { @Reflective SampleConstructorAnnotatedBean(String name) { - } SampleConstructorAnnotatedBean(Integer nameAsNumber) { - } - } @SuppressWarnings("unused") @@ -176,7 +173,6 @@ class ReflectiveRuntimeHintsRegistrarTests { void notManaged() { } - } @SuppressWarnings("unused") @@ -188,7 +184,6 @@ class ReflectiveRuntimeHintsRegistrarTests { void notManaged() { } - } @SuppressWarnings("unused") @@ -200,7 +195,6 @@ class ReflectiveRuntimeHintsRegistrarTests { void notManaged() { } - } static class SampleMethodAnnotatedBeanWithInterface implements SampleInterface { @@ -211,7 +205,6 @@ class ReflectiveRuntimeHintsRegistrarTests { public void notManaged() { } - } static class SampleMethodAnnotatedBeanWithInheritance extends SampleInheritedClass { @@ -222,7 +215,6 @@ class ReflectiveRuntimeHintsRegistrarTests { public void notManaged() { } - } @Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE }) @@ -251,7 +243,6 @@ class ReflectiveRuntimeHintsRegistrarTests { @Documented @Reflective(TestTypeHintReflectiveProcessor.class) @interface ReflectiveWithCustomProcessor { - } interface SampleInterface { @@ -273,7 +264,6 @@ class ReflectiveRuntimeHintsRegistrarTests { public String managed() { return "test"; } - } @Reflective @@ -283,7 +273,6 @@ class ReflectiveRuntimeHintsRegistrarTests { public String managed() { return "test"; } - } private static class TestMethodHintReflectiveProcessor extends SimpleReflectiveProcessor { @@ -293,7 +282,6 @@ class ReflectiveRuntimeHintsRegistrarTests { super.registerMethodHint(hints, method); hints.registerType(method.getReturnType(), MemberCategory.INVOKE_DECLARED_METHODS); } - } private static class TestTypeHintReflectiveProcessor extends SimpleReflectiveProcessor { @@ -303,7 +291,6 @@ class ReflectiveRuntimeHintsRegistrarTests { super.registerTypeHint(hints, type); hints.registerType(type, MemberCategory.INVOKE_DECLARED_METHODS); } - } } diff --git a/spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Encoder.java b/spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Encoder.java index 5f5f815a37..4819610bd3 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Encoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Encoder.java @@ -61,7 +61,7 @@ import org.springframework.util.MimeType; /** * Base class providing support methods for Jackson 2.9 encoding. For non-streaming use * cases, {@link Flux} elements are collected into a {@link List} before serialization for - * performance reason. + * performance reasons. * * @author Sebastien Deleuze * @author Arjen Poutsma @@ -347,13 +347,13 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple } /** - * Subclasses can use this method to customize {@link ObjectWriter} used + * Subclasses can use this method to customize the {@link ObjectWriter} used * for writing values. * @param writer the writer instance to customize * @param mimeType the selected MIME type * @param elementType the type of element values to write - * @param hints a map with serialization hints; - * the Reactor Context, when available, may be accessed under the key + * @param hints a map with serialization hints; the Reactor Context, when + * available, may be accessed under the key * {@code ContextView.class.getName()} * @return the customized {@code ObjectWriter} to use */