diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java index fdceb174cea..cae01fb25c3 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java @@ -905,7 +905,7 @@ public abstract class AnnotationUtils { } else { // If we have nested annotations, we need them as nested maps - AnnotationAttributes attributes = MergedAnnotation.from(annotationType) + AnnotationAttributes attributes = MergedAnnotation.of(annotationType) .asMap(annotation -> new AnnotationAttributes(annotation.getType(), true), Adapt.ANNOTATION_TO_MAP); for (Map.Entry element : attributes.entrySet()) { @@ -1151,7 +1151,7 @@ public abstract class AnnotationUtils { if (annotationType == null || !StringUtils.hasText(attributeName)) { return null; } - return MergedAnnotation.from(annotationType).getDefaultValue(attributeName).orElse(null); + return MergedAnnotation.of(annotationType).getDefaultValue(attributeName).orElse(null); } /** @@ -1232,7 +1232,7 @@ public abstract class AnnotationUtils { Class annotationType, @Nullable AnnotatedElement annotatedElement) { try { - return MergedAnnotation.from(annotatedElement, annotationType, attributes).synthesize(); + return MergedAnnotation.of(annotatedElement, annotationType, attributes).synthesize(); } catch (NoSuchElementException | IllegalStateException ex) { throw new IllegalArgumentException(ex); diff --git a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotation.java b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotation.java index ecefd180993..cdc3c58a21c 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotation.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotation.java @@ -523,34 +523,34 @@ public interface MergedAnnotation { } /** - * Create a new {@link MergedAnnotation} instance from the specified + * Create a new {@link MergedAnnotation} instance of the specified * annotation type. The resulting annotation will not have any attribute * values but may still be used to query default values. * @param annotationType the annotation type * @return a {@link MergedAnnotation} instance for the annotation */ - static MergedAnnotation from(Class annotationType) { - return from(null, annotationType, null); + static MergedAnnotation of(Class annotationType) { + return of(null, annotationType, null); } /** - * Create a new {@link MergedAnnotation} instance from the specified - * annotation type and attributes map. + * Create a new {@link MergedAnnotation} instance of the specified + * annotation type with attributes values supplied by a map. * @param annotationType the annotation type * @param attributes the annotation attributes or {@code null} if just default * values should be used * @return a {@link MergedAnnotation} instance for the annotation and attributes - * @see #from(AnnotatedElement, Class, Map) + * @see #of(AnnotatedElement, Class, Map) */ - static MergedAnnotation from( + static MergedAnnotation of( Class annotationType, @Nullable Map attributes) { - return from(null, annotationType, attributes); + return of(null, annotationType, attributes); } /** - * Create a new {@link MergedAnnotation} instance from the specified - * annotation type and attributes map. + * Create a new {@link MergedAnnotation} instance of the specified + * annotation type with attributes values supplied by a map. * @param source the source for the annotation. This source is used only for * information and logging. It does not need to actually contain * the specified annotations and it will not be searched. @@ -559,10 +559,10 @@ public interface MergedAnnotation { * values should be used * @return a {@link MergedAnnotation} instance for the annotation and attributes */ - static MergedAnnotation from( + static MergedAnnotation of( @Nullable AnnotatedElement source, Class annotationType, @Nullable Map attributes) { - return TypeMappedAnnotation.from(source, annotationType, attributes); + return TypeMappedAnnotation.of(source, annotationType, attributes); } diff --git a/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotation.java b/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotation.java index 22bc15c6a4e..da348b3416f 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotation.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotation.java @@ -547,7 +547,7 @@ final class TypeMappedAnnotation extends AbstractMergedAnn return new TypeMappedAnnotation<>(mappings.get(0), source, annotation, ReflectionUtils::invokeMethod, 0); } - static MergedAnnotation from(@Nullable Object source, + static MergedAnnotation of(@Nullable Object source, Class annotationType, @Nullable Map attributes) { Assert.notNull(annotationType, "Annotation type must not be null"); diff --git a/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java index 9c1d374491b..e07a0cefebd 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java @@ -1262,7 +1262,7 @@ public class MergedAnnotationsTests { @Test public void getDefaultValueFromAnnotationType() { - MergedAnnotation annotation = MergedAnnotation.from(Order.class); + MergedAnnotation annotation = MergedAnnotation.of(Order.class); assertThat(annotation.getDefaultValue("value")).contains( Ordered.LOWEST_PRECEDENCE); } @@ -1681,7 +1681,7 @@ public class MergedAnnotationsTests { Component component = WebController.class.getAnnotation(Component.class); assertThat(component).isNotNull(); Map map = Collections.singletonMap("value", "webController"); - MergedAnnotation annotation = MergedAnnotation.from(Component.class, + MergedAnnotation annotation = MergedAnnotation.of(Component.class, map); Component synthesizedComponent = annotation.synthesize(); assertThat(synthesizedComponent).isInstanceOf(SynthesizedAnnotation.class); @@ -1702,7 +1702,7 @@ public class MergedAnnotationsTests { assertThat(filterMap.get("pattern")).isEqualTo("*Foo"); filterMap.put("pattern", "newFoo"); filterMap.put("enigma", 42); - MergedAnnotation annotation = MergedAnnotation.from( + MergedAnnotation annotation = MergedAnnotation.of( ComponentScanSingleFilter.class, map); ComponentScanSingleFilter synthesizedComponentScan = annotation.synthesize(); assertThat(synthesizedComponentScan).isInstanceOf(SynthesizedAnnotation.class); @@ -1726,7 +1726,7 @@ public class MergedAnnotationsTests { filters[0].put("enigma", 42); filters[1].put("pattern", "newBar"); filters[1].put("enigma", 42); - MergedAnnotation annotation = MergedAnnotation.from( + MergedAnnotation annotation = MergedAnnotation.of( ComponentScan.class, map); ComponentScan synthesizedComponentScan = annotation.synthesize(); assertThat(synthesizedComponentScan).isInstanceOf(SynthesizedAnnotation.class); @@ -1736,7 +1736,7 @@ public class MergedAnnotationsTests { @Test public void synthesizeFromDefaultsWithoutAttributeAliases() throws Exception { - MergedAnnotation annotation = MergedAnnotation.from( + MergedAnnotation annotation = MergedAnnotation.of( AnnotationWithDefaults.class); AnnotationWithDefaults synthesized = annotation.synthesize(); assertThat(synthesized.text()).isEqualTo("enigma"); @@ -1746,7 +1746,7 @@ public class MergedAnnotationsTests { @Test public void synthesizeFromDefaultsWithAttributeAliases() throws Exception { - MergedAnnotation annotation = MergedAnnotation.from( + MergedAnnotation annotation = MergedAnnotation.of( TestConfiguration.class); TestConfiguration synthesized = annotation.synthesize(); assertThat(synthesized.value()).isEqualTo(""); @@ -1764,7 +1764,7 @@ public class MergedAnnotationsTests { public void synthesizeFromMapWithMinimalAttributesWithAttributeAliases() throws Exception { Map map = Collections.singletonMap("location", "test.xml"); - MergedAnnotation annotation = MergedAnnotation.from( + MergedAnnotation annotation = MergedAnnotation.of( TestConfiguration.class, map); TestConfiguration synthesized = annotation.synthesize(); assertThat(synthesized.value()).isEqualTo("test.xml"); @@ -1782,7 +1782,7 @@ public class MergedAnnotationsTests { private void synthesizeFromMapWithAttributeAliasesThatOverrideArraysWithSingleElements( Map map) { - MergedAnnotation annotation = MergedAnnotation.from(GetMapping.class, + MergedAnnotation annotation = MergedAnnotation.of(GetMapping.class, map); GetMapping synthesized = annotation.synthesize(); assertThat(synthesized.value()).isEqualTo("/foo"); @@ -1803,7 +1803,7 @@ public class MergedAnnotationsTests { throws Exception { Map map = Collections.singletonMap(attributeNameAndValue, attributeNameAndValue); - MergedAnnotation annotation = MergedAnnotation.from( + MergedAnnotation annotation = MergedAnnotation.of( ImplicitAliasesTestConfiguration.class, map); ImplicitAliasesTestConfiguration synthesized = annotation.synthesize(); assertThat(synthesized.value()).isEqualTo(attributeNameAndValue); @@ -1828,7 +1828,7 @@ public class MergedAnnotationsTests { private void testMissingTextAttribute(Map attributes) { assertThatExceptionOfType(NoSuchElementException.class).isThrownBy(() -> { - MergedAnnotation annotation = MergedAnnotation.from( + MergedAnnotation annotation = MergedAnnotation.of( AnnotationWithoutDefaults.class, attributes); annotation.synthesize(); }).withMessage("No value found for attribute named 'text' in merged annotation " @@ -1838,7 +1838,7 @@ public class MergedAnnotationsTests { @Test public void synthesizeFromMapWithAttributeOfIncorrectType() throws Exception { Map map = Collections.singletonMap("value", 42L); - MergedAnnotation annotation = MergedAnnotation.from(Component.class, + MergedAnnotation annotation = MergedAnnotation.of(Component.class, map); // annotation.synthesize(); assertThatIllegalStateException().isThrownBy( @@ -1853,7 +1853,7 @@ public class MergedAnnotationsTests { Component component = WebController.class.getAnnotation(Component.class); assertThat(component).isNotNull(); Map attributes = MergedAnnotation.from(component).asMap(); - Component synthesized = MergedAnnotation.from(Component.class, + Component synthesized = MergedAnnotation.of(Component.class, attributes).synthesize(); assertThat(synthesized).isInstanceOf(SynthesizedAnnotation.class); assertThat(synthesized).isEqualTo(component);