Skip to content

Commit fb6c325

Browse files
committed
Document @AliasFor support in AnnotatedTypeMetadata.getAnnotationAttributes()
The Javadoc for getAnnotationAttributes() states that it supports "attribute overrides on composed annotations"; however, it actually supports @AliasFor in general, including attribute aliases within a given annotation. This commit updates the Javadoc and corresponding tests to reflect that. Closes gh-31042
1 parent c52bfc0 commit fb6c325

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

spring-core/src/main/java/org/springframework/core/type/AnnotatedTypeMetadata.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ default boolean isAnnotated(String annotationName) {
6969

7070
/**
7171
* Retrieve the attributes of the annotation of the given type, if any (i.e. if
72-
* defined on the underlying element, as direct annotation or meta-annotation),
73-
* also taking attribute overrides on composed annotations into account.
72+
* defined on the underlying element, as direct annotation or meta-annotation).
73+
* <p>{@link org.springframework.core.annotation.AliasFor @AliasFor} semantics
74+
* are fully supported, both within a single annotation and within annotation
75+
* hierarchies.
7476
* @param annotationName the fully-qualified class name of the annotation
7577
* type to look for
7678
* @return a {@link Map} of attributes, with each annotation attribute name
@@ -84,8 +86,10 @@ default Map<String, Object> getAnnotationAttributes(String annotationName) {
8486

8587
/**
8688
* Retrieve the attributes of the annotation of the given type, if any (i.e. if
87-
* defined on the underlying element, as direct annotation or meta-annotation),
88-
* also taking attribute overrides on composed annotations into account.
89+
* defined on the underlying element, as direct annotation or meta-annotation).
90+
* <p>{@link org.springframework.core.annotation.AliasFor @AliasFor} semantics
91+
* are fully supported, both within a single annotation and within annotation
92+
* hierarchies.
8993
* @param annotationName the fully-qualified class name of the annotation
9094
* type to look for
9195
* @param classValuesAsString whether to convert class references to String

spring-core/src/test/java/org/springframework/core/type/AnnotationMetadataTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ void metaAnnotationOverridesUsingSimpleAnnotationMetadata() throws Exception {
214214
private void assertMetaAnnotationOverrides(AnnotationMetadata metadata) {
215215
AnnotationAttributes attributes = (AnnotationAttributes) metadata.getAnnotationAttributes(
216216
TestComponentScan.class.getName(), false);
217+
assertThat(attributes.getStringArray("value")).containsExactly("org.example.componentscan");
217218
assertThat(attributes.getStringArray("basePackages")).containsExactly("org.example.componentscan");
218-
assertThat(attributes.getStringArray("value")).isEmpty();
219219
assertThat(attributes.getClassArray("basePackageClasses")).isEmpty();
220220
}
221221

@@ -536,8 +536,10 @@ private static class AnnotatedComponentSubClass extends AnnotatedComponent {
536536
@Target(ElementType.TYPE)
537537
public @interface TestComponentScan {
538538

539+
@AliasFor("basePackages")
539540
String[] value() default {};
540541

542+
@AliasFor("value")
541543
String[] basePackages() default {};
542544

543545
Class<?>[] basePackageClasses() default {};

0 commit comments

Comments
 (0)