Skip to content

Commit d4a761a

Browse files
philwebbjhoeller
authored andcommitted
Rename some MergedAnnotation from methods to of
Rename `from` to `of` for the `MergedAnnotation` factory methods that work with Maps. The previous name was a little confusing, especially when an annotation source parameter was specified. The new method name helps to make it clearer when the user is explicitly defining the attributes of the annotation, as opposed to picking them up from the source.
1 parent 3b145a5 commit d4a761a

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ private static Map<String, DefaultValueHolder> computeDefaultValues(
905905
}
906906
else {
907907
// If we have nested annotations, we need them as nested maps
908-
AnnotationAttributes attributes = MergedAnnotation.from(annotationType)
908+
AnnotationAttributes attributes = MergedAnnotation.of(annotationType)
909909
.asMap(annotation ->
910910
new AnnotationAttributes(annotation.getType(), true), Adapt.ANNOTATION_TO_MAP);
911911
for (Map.Entry<String, Object> element : attributes.entrySet()) {
@@ -1151,7 +1151,7 @@ public static Object getDefaultValue(
11511151
if (annotationType == null || !StringUtils.hasText(attributeName)) {
11521152
return null;
11531153
}
1154-
return MergedAnnotation.from(annotationType).getDefaultValue(attributeName).orElse(null);
1154+
return MergedAnnotation.of(annotationType).getDefaultValue(attributeName).orElse(null);
11551155
}
11561156

11571157
/**
@@ -1232,7 +1232,7 @@ public static <A extends Annotation> A synthesizeAnnotation(Map<String, Object>
12321232
Class<A> annotationType, @Nullable AnnotatedElement annotatedElement) {
12331233

12341234
try {
1235-
return MergedAnnotation.from(annotatedElement, annotationType, attributes).synthesize();
1235+
return MergedAnnotation.of(annotatedElement, annotationType, attributes).synthesize();
12361236
}
12371237
catch (NoSuchElementException | IllegalStateException ex) {
12381238
throw new IllegalArgumentException(ex);

spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotation.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -523,34 +523,34 @@ static <A extends Annotation> MergedAnnotation<A> from(@Nullable Object source,
523523
}
524524

525525
/**
526-
* Create a new {@link MergedAnnotation} instance from the specified
526+
* Create a new {@link MergedAnnotation} instance of the specified
527527
* annotation type. The resulting annotation will not have any attribute
528528
* values but may still be used to query default values.
529529
* @param annotationType the annotation type
530530
* @return a {@link MergedAnnotation} instance for the annotation
531531
*/
532-
static <A extends Annotation> MergedAnnotation<A> from(Class<A> annotationType) {
533-
return from(null, annotationType, null);
532+
static <A extends Annotation> MergedAnnotation<A> of(Class<A> annotationType) {
533+
return of(null, annotationType, null);
534534
}
535535

536536
/**
537-
* Create a new {@link MergedAnnotation} instance from the specified
538-
* annotation type and attributes map.
537+
* Create a new {@link MergedAnnotation} instance of the specified
538+
* annotation type with attributes values supplied by a map.
539539
* @param annotationType the annotation type
540540
* @param attributes the annotation attributes or {@code null} if just default
541541
* values should be used
542542
* @return a {@link MergedAnnotation} instance for the annotation and attributes
543-
* @see #from(AnnotatedElement, Class, Map)
543+
* @see #of(AnnotatedElement, Class, Map)
544544
*/
545-
static <A extends Annotation> MergedAnnotation<A> from(
545+
static <A extends Annotation> MergedAnnotation<A> of(
546546
Class<A> annotationType, @Nullable Map<String, ?> attributes) {
547547

548-
return from(null, annotationType, attributes);
548+
return of(null, annotationType, attributes);
549549
}
550550

551551
/**
552-
* Create a new {@link MergedAnnotation} instance from the specified
553-
* annotation type and attributes map.
552+
* Create a new {@link MergedAnnotation} instance of the specified
553+
* annotation type with attributes values supplied by a map.
554554
* @param source the source for the annotation. This source is used only for
555555
* information and logging. It does not need to <em>actually</em> contain
556556
* the specified annotations and it will not be searched.
@@ -559,10 +559,10 @@ static <A extends Annotation> MergedAnnotation<A> from(
559559
* values should be used
560560
* @return a {@link MergedAnnotation} instance for the annotation and attributes
561561
*/
562-
static <A extends Annotation> MergedAnnotation<A> from(
562+
static <A extends Annotation> MergedAnnotation<A> of(
563563
@Nullable AnnotatedElement source, Class<A> annotationType, @Nullable Map<String, ?> attributes) {
564564

565-
return TypeMappedAnnotation.from(source, annotationType, attributes);
565+
return TypeMappedAnnotation.of(source, annotationType, attributes);
566566
}
567567

568568

spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ static <A extends Annotation> MergedAnnotation<A> from(@Nullable Object source,
547547
return new TypeMappedAnnotation<>(mappings.get(0), source, annotation, ReflectionUtils::invokeMethod, 0);
548548
}
549549

550-
static <A extends Annotation> MergedAnnotation<A> from(@Nullable Object source,
550+
static <A extends Annotation> MergedAnnotation<A> of(@Nullable Object source,
551551
Class<A> annotationType, @Nullable Map<String, ?> attributes) {
552552

553553
Assert.notNull(annotationType, "Annotation type must not be null");

spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,7 @@ public void getDefaultValueFromNonPublicAnnotation() {
12621262

12631263
@Test
12641264
public void getDefaultValueFromAnnotationType() {
1265-
MergedAnnotation<?> annotation = MergedAnnotation.from(Order.class);
1265+
MergedAnnotation<?> annotation = MergedAnnotation.of(Order.class);
12661266
assertThat(annotation.getDefaultValue("value")).contains(
12671267
Ordered.LOWEST_PRECEDENCE);
12681268
}
@@ -1681,7 +1681,7 @@ public void synthesizeFromMapWithoutAttributeAliases() throws Exception {
16811681
Component component = WebController.class.getAnnotation(Component.class);
16821682
assertThat(component).isNotNull();
16831683
Map<String, Object> map = Collections.singletonMap("value", "webController");
1684-
MergedAnnotation<Component> annotation = MergedAnnotation.from(Component.class,
1684+
MergedAnnotation<Component> annotation = MergedAnnotation.of(Component.class,
16851685
map);
16861686
Component synthesizedComponent = annotation.synthesize();
16871687
assertThat(synthesizedComponent).isInstanceOf(SynthesizedAnnotation.class);
@@ -1702,7 +1702,7 @@ public void synthesizeFromMapWithNestedMap() throws Exception {
17021702
assertThat(filterMap.get("pattern")).isEqualTo("*Foo");
17031703
filterMap.put("pattern", "newFoo");
17041704
filterMap.put("enigma", 42);
1705-
MergedAnnotation<ComponentScanSingleFilter> annotation = MergedAnnotation.from(
1705+
MergedAnnotation<ComponentScanSingleFilter> annotation = MergedAnnotation.of(
17061706
ComponentScanSingleFilter.class, map);
17071707
ComponentScanSingleFilter synthesizedComponentScan = annotation.synthesize();
17081708
assertThat(synthesizedComponentScan).isInstanceOf(SynthesizedAnnotation.class);
@@ -1726,7 +1726,7 @@ public void synthesizeFromMapWithNestedArrayOfMaps() throws Exception {
17261726
filters[0].put("enigma", 42);
17271727
filters[1].put("pattern", "newBar");
17281728
filters[1].put("enigma", 42);
1729-
MergedAnnotation<ComponentScan> annotation = MergedAnnotation.from(
1729+
MergedAnnotation<ComponentScan> annotation = MergedAnnotation.of(
17301730
ComponentScan.class, map);
17311731
ComponentScan synthesizedComponentScan = annotation.synthesize();
17321732
assertThat(synthesizedComponentScan).isInstanceOf(SynthesizedAnnotation.class);
@@ -1736,7 +1736,7 @@ public void synthesizeFromMapWithNestedArrayOfMaps() throws Exception {
17361736

17371737
@Test
17381738
public void synthesizeFromDefaultsWithoutAttributeAliases() throws Exception {
1739-
MergedAnnotation<AnnotationWithDefaults> annotation = MergedAnnotation.from(
1739+
MergedAnnotation<AnnotationWithDefaults> annotation = MergedAnnotation.of(
17401740
AnnotationWithDefaults.class);
17411741
AnnotationWithDefaults synthesized = annotation.synthesize();
17421742
assertThat(synthesized.text()).isEqualTo("enigma");
@@ -1746,7 +1746,7 @@ public void synthesizeFromDefaultsWithoutAttributeAliases() throws Exception {
17461746

17471747
@Test
17481748
public void synthesizeFromDefaultsWithAttributeAliases() throws Exception {
1749-
MergedAnnotation<TestConfiguration> annotation = MergedAnnotation.from(
1749+
MergedAnnotation<TestConfiguration> annotation = MergedAnnotation.of(
17501750
TestConfiguration.class);
17511751
TestConfiguration synthesized = annotation.synthesize();
17521752
assertThat(synthesized.value()).isEqualTo("");
@@ -1764,7 +1764,7 @@ public void synthesizeWhenAttributeAliasesWithDifferentValues() throws Exception
17641764
public void synthesizeFromMapWithMinimalAttributesWithAttributeAliases()
17651765
throws Exception {
17661766
Map<String, Object> map = Collections.singletonMap("location", "test.xml");
1767-
MergedAnnotation<TestConfiguration> annotation = MergedAnnotation.from(
1767+
MergedAnnotation<TestConfiguration> annotation = MergedAnnotation.of(
17681768
TestConfiguration.class, map);
17691769
TestConfiguration synthesized = annotation.synthesize();
17701770
assertThat(synthesized.value()).isEqualTo("test.xml");
@@ -1782,7 +1782,7 @@ public void synthesizeFromMapWithAttributeAliasesThatOverrideArraysWithSingleEle
17821782

17831783
private void synthesizeFromMapWithAttributeAliasesThatOverrideArraysWithSingleElements(
17841784
Map<String, Object> map) {
1785-
MergedAnnotation<GetMapping> annotation = MergedAnnotation.from(GetMapping.class,
1785+
MergedAnnotation<GetMapping> annotation = MergedAnnotation.of(GetMapping.class,
17861786
map);
17871787
GetMapping synthesized = annotation.synthesize();
17881788
assertThat(synthesized.value()).isEqualTo("/foo");
@@ -1803,7 +1803,7 @@ private void testSynthesisFromMapWithImplicitAliases(String attributeNameAndValu
18031803
throws Exception {
18041804
Map<String, Object> map = Collections.singletonMap(attributeNameAndValue,
18051805
attributeNameAndValue);
1806-
MergedAnnotation<ImplicitAliasesTestConfiguration> annotation = MergedAnnotation.from(
1806+
MergedAnnotation<ImplicitAliasesTestConfiguration> annotation = MergedAnnotation.of(
18071807
ImplicitAliasesTestConfiguration.class, map);
18081808
ImplicitAliasesTestConfiguration synthesized = annotation.synthesize();
18091809
assertThat(synthesized.value()).isEqualTo(attributeNameAndValue);
@@ -1828,7 +1828,7 @@ public void synthesizeFromMapWithNullAttributeValue() throws Exception {
18281828

18291829
private void testMissingTextAttribute(Map<String, Object> attributes) {
18301830
assertThatExceptionOfType(NoSuchElementException.class).isThrownBy(() -> {
1831-
MergedAnnotation<AnnotationWithoutDefaults> annotation = MergedAnnotation.from(
1831+
MergedAnnotation<AnnotationWithoutDefaults> annotation = MergedAnnotation.of(
18321832
AnnotationWithoutDefaults.class, attributes);
18331833
annotation.synthesize();
18341834
}).withMessage("No value found for attribute named 'text' in merged annotation "
@@ -1838,7 +1838,7 @@ private void testMissingTextAttribute(Map<String, Object> attributes) {
18381838
@Test
18391839
public void synthesizeFromMapWithAttributeOfIncorrectType() throws Exception {
18401840
Map<String, Object> map = Collections.singletonMap("value", 42L);
1841-
MergedAnnotation<Component> annotation = MergedAnnotation.from(Component.class,
1841+
MergedAnnotation<Component> annotation = MergedAnnotation.of(Component.class,
18421842
map);
18431843
// annotation.synthesize();
18441844
assertThatIllegalStateException().isThrownBy(
@@ -1853,7 +1853,7 @@ public void synthesizeFromAnnotationAttributesWithoutAttributeAliases()
18531853
Component component = WebController.class.getAnnotation(Component.class);
18541854
assertThat(component).isNotNull();
18551855
Map<String, Object> attributes = MergedAnnotation.from(component).asMap();
1856-
Component synthesized = MergedAnnotation.from(Component.class,
1856+
Component synthesized = MergedAnnotation.of(Component.class,
18571857
attributes).synthesize();
18581858
assertThat(synthesized).isInstanceOf(SynthesizedAnnotation.class);
18591859
assertThat(synthesized).isEqualTo(component);

0 commit comments

Comments
 (0)