|
41 | 41 | * hierarchy. In fact, with {@code @AliasFor} it is even possible to declare
|
42 | 42 | * an alias for the {@code value} attribute of a meta-annotation.</li>
|
43 | 43 | * <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> |
48 | 49 | * </ul>
|
49 | 50 | *
|
50 | 51 | * <h3>Usage Requirements</h3>
|
|
86 | 87 | * </li>
|
87 | 88 | * <li><strong>Implicit aliases within an annotation</strong>:
|
88 | 89 | * <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 |
90 | 91 | * 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> |
92 | 95 | * <li>Aliased attributes must declare the same return type.</li>
|
93 | 96 | * <li>Aliased attributes must declare a default value.</li>
|
94 | 97 | * <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> |
96 | 99 | * <li>The referenced meta-annotation must be <em>meta-present</em> on the
|
97 | 100 | * annotation class that declares {@code @AliasFor}.</li>
|
98 | 101 | * </ol>
|
99 | 102 | * </li>
|
100 | 103 | * </ul>
|
101 | 104 | *
|
102 | 105 | * <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 | + * |
103 | 109 | * <pre class="code"> public @interface ContextConfiguration {
|
104 | 110 | *
|
105 | 111 | * @AliasFor("locations")
|
|
112 | 118 | * }</pre>
|
113 | 119 | *
|
114 | 120 | * <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 | + * |
115 | 126 | * <pre class="code"> @ContextConfiguration
|
116 |
| - * public @interface MyTestConfig { |
| 127 | + * public @interface XmlTestConfig { |
117 | 128 | *
|
118 | 129 | * @AliasFor(annotation = ContextConfiguration.class, attribute = "locations")
|
119 | 130 | * String[] xmlFiles();
|
120 | 131 | * }</pre>
|
121 | 132 | *
|
122 | 133 | * <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 | + * |
123 | 139 | * <pre class="code"> @ContextConfiguration
|
124 | 140 | * public @interface MyTestConfig {
|
125 | 141 | *
|
|
133 | 149 | * String[] xmlFiles() default {};
|
134 | 150 | * }</pre>
|
135 | 151 | *
|
| 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"> @MyTestConfig |
| 162 | + * public @interface GroovyOrXmlTestConfig { |
| 163 | + * |
| 164 | + * @AliasFor(annotation = MyTestConfig.class, attribute = "groovyScripts") |
| 165 | + * String[] groovy() default {}; |
| 166 | + * |
| 167 | + * @AliasFor(annotation = ContextConfiguration.class, attribute = "locations") |
| 168 | + * String[] xml() default {}; |
| 169 | + * }</pre> |
| 170 | + * |
136 | 171 | * <h3>Spring Annotations Supporting Attribute Aliases</h3>
|
137 | 172 | * <p>As of Spring Framework 4.2, several annotations within core Spring
|
138 | 173 | * have been updated to use {@code @AliasFor} to configure their internal
|
|
0 commit comments