Skip to content

Commit 9b1178c

Browse files
committed
Document support for transitive implicit aliases in @AliasFor
Issue: SPR-13405
1 parent 542e21b commit 9b1178c

File tree

1 file changed

+43
-8
lines changed
  • spring-core/src/main/java/org/springframework/core/annotation

1 file changed

+43
-8
lines changed

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

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@
4141
* hierarchy. In fact, with {@code @AliasFor} it is even possible to declare
4242
* an alias for the {@code value} attribute of a meta-annotation.</li>
4343
* <li><strong>Implicit aliases within an annotation</strong>: if one or
44-
* more attributes within an annotation are declared as explicit
45-
* meta-annotation attribute overrides for the same attribute in the
46-
* meta-annotation, those attributes will be treated as a set of <em>implicit</em>
47-
* aliases for each other, analogous to explicit aliases within an annotation.</li>
44+
* more attributes within an annotation are declared as attribute overrides
45+
* for the same meta-annotation attribute (either directly or transitively),
46+
* those attributes will be treated as a set of <em>implicit</em> aliases
47+
* for each other, resulting in behavior analogous to that for explicit
48+
* aliases within an annotation.</li>
4849
* </ul>
4950
*
5051
* <h3>Usage Requirements</h3>
@@ -86,20 +87,25 @@
8687
* </li>
8788
* <li><strong>Implicit aliases within an annotation</strong>:
8889
* <ol>
89-
* <li>Each attribute that belongs to the set of implicit aliases must be
90+
* <li>Each attribute that belongs to a set of implicit aliases must be
9091
* annotated with {@code @AliasFor}, and {@link #attribute} must reference
91-
* the same attribute in the same meta-annotation.</li>
92+
* the same attribute in the same meta-annotation (either directly or
93+
* transitively via other explicit meta-annotation attribute overrides
94+
* within the annotation hierarchy).</li>
9295
* <li>Aliased attributes must declare the same return type.</li>
9396
* <li>Aliased attributes must declare a default value.</li>
9497
* <li>Aliased attributes must declare the same default value.</li>
95-
* <li>{@link #annotation} must reference the meta-annotation.</li>
98+
* <li>{@link #annotation} must reference an appropriate meta-annotation.</li>
9699
* <li>The referenced meta-annotation must be <em>meta-present</em> on the
97100
* annotation class that declares {@code @AliasFor}.</li>
98101
* </ol>
99102
* </li>
100103
* </ul>
101104
*
102105
* <h3>Example: Explicit Aliases within an Annotation</h3>
106+
* <p>In {@code @ContextConfiguration}, {@code value} and {@code locations}
107+
* are explicit aliases for each other.
108+
*
103109
* <pre class="code"> public &#064;interface ContextConfiguration {
104110
*
105111
* &#064;AliasFor("locations")
@@ -112,14 +118,24 @@
112118
* }</pre>
113119
*
114120
* <h3>Example: Explicit Alias for Attribute in Meta-annotation</h3>
121+
* <p>In {@code @XmlTestConfig}, {@code xmlFiles} is an explicit alias for
122+
* {@code locations} in {@code @ContextConfiguration}. In other words,
123+
* {@code xmlFiles} overrides the {@code locations} attribute in
124+
* {@code @ContextConfiguration}.
125+
*
115126
* <pre class="code"> &#064;ContextConfiguration
116-
* public &#064;interface MyTestConfig {
127+
* public &#064;interface XmlTestConfig {
117128
*
118129
* &#064;AliasFor(annotation = ContextConfiguration.class, attribute = "locations")
119130
* String[] xmlFiles();
120131
* }</pre>
121132
*
122133
* <h3>Example: Implicit Aliases within an Annotation</h3>
134+
* <p>In {@code @MyTestConfig}, {@code value}, {@code groovyScripts}, and
135+
* {@code xmlFiles} are all explicit meta-annotation attribute overrides for
136+
* the {@code locations} attribute in {@code @ContextConfiguration}. These
137+
* three attributes are therefore also implicit aliases for each other.
138+
*
123139
* <pre class="code"> &#064;ContextConfiguration
124140
* public &#064;interface MyTestConfig {
125141
*
@@ -133,6 +149,25 @@
133149
* String[] xmlFiles() default {};
134150
* }</pre>
135151
*
152+
* <h3>Example: Transitive Implicit Aliases within an Annotation</h3>
153+
* <p>In {@code @GroovyOrXmlTestConfig}, {@code groovy} is an explicit
154+
* override for the {@code groovyScripts} attribute in {@code @MyTestConfig};
155+
* whereas, {@code xml} is an explicit override for the {@code locations}
156+
* attribute in {@code @ContextConfiguration}. Furthermore, {@code groovy}
157+
* and {@code xml} are transitive implicit aliases for each other, since they
158+
* both effectively override the {@code locations} attribute in
159+
* {@code @ContextConfiguration}.
160+
*
161+
* <pre class="code"> &#064;MyTestConfig
162+
* public &#064;interface GroovyOrXmlTestConfig {
163+
*
164+
* &#064;AliasFor(annotation = MyTestConfig.class, attribute = "groovyScripts")
165+
* String[] groovy() default {};
166+
*
167+
* &#064;AliasFor(annotation = ContextConfiguration.class, attribute = "locations")
168+
* String[] xml() default {};
169+
* }</pre>
170+
*
136171
* <h3>Spring Annotations Supporting Attribute Aliases</h3>
137172
* <p>As of Spring Framework 4.2, several annotations within core Spring
138173
* have been updated to use {@code @AliasFor} to configure their internal

0 commit comments

Comments
 (0)