|
29 | 29 | * |
30 | 30 | * <h3>Usage Scenarios</h3> |
31 | 31 | * <ul> |
32 | | - * <li><strong>Aliases within an annotation</strong>: within a single |
| 32 | + * <li><strong>Explicit aliases within an annotation</strong>: within a single |
33 | 33 | * annotation, {@code @AliasFor} can be declared on a pair of attributes to |
34 | 34 | * signal that they are interchangeable aliases for each other.</li> |
35 | | - * <li><strong>Alias for attribute in meta-annotation</strong>: if the |
| 35 | + * <li><strong>Explicit alias for attribute in meta-annotation</strong>: if the |
36 | 36 | * {@link #annotation} attribute of {@code @AliasFor} is set to a different |
37 | 37 | * annotation than the one that declares it, the {@link #attribute} is |
38 | 38 | * interpreted as an alias for an attribute in a meta-annotation (i.e., an |
39 | 39 | * explicit meta-annotation attribute override). This enables fine-grained |
40 | 40 | * control over exactly which attributes are overridden within an annotation |
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 | + * <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> |
43 | 48 | * </ul> |
44 | 49 | * |
45 | 50 | * <h3>Usage Requirements</h3> |
|
57 | 62 | * |
58 | 63 | * <h3>Implementation Requirements</h3> |
59 | 64 | * <ul> |
60 | | - * <li><strong>Aliases within an annotation</strong>: |
| 65 | + * <li><strong>Explicit aliases within an annotation</strong>: |
61 | 66 | * <ol> |
62 | 67 | * <li>Each attribute that makes up an aliased pair must be annotated with |
63 | | - * {@code @AliasFor}, and either the {@link #attribute} or the {@link #value} |
64 | | - * attribute must reference the <em>other</em> attribute in the pair.</li> |
| 68 | + * {@code @AliasFor}, and either {@link #attribute} or {@link #value} must |
| 69 | + * reference the <em>other</em> attribute in the pair.</li> |
65 | 70 | * <li>Aliased attributes must declare the same return type.</li> |
66 | 71 | * <li>Aliased attributes must declare a default value.</li> |
67 | 72 | * <li>Aliased attributes must declare the same default value.</li> |
68 | | - * <li>The {@link #annotation} attribute should remain set to the default.</li> |
| 73 | + * <li>{@link #annotation} should not be declared.</li> |
69 | 74 | * </ol> |
70 | 75 | * </li> |
71 | | - * <li><strong>Alias for attribute in meta-annotation</strong>: |
| 76 | + * <li><strong>Explicit alias for attribute in meta-annotation</strong>: |
72 | 77 | * <ol> |
73 | 78 | * <li>The attribute that is an alias for an attribute in a meta-annotation |
74 | | - * must be annotated with {@code @AliasFor}, and the {@link #attribute} must |
75 | | - * reference the aliased attribute in the meta-annotation.</li> |
| 79 | + * must be annotated with {@code @AliasFor}, and {@link #attribute} must |
| 80 | + * reference the attribute in the meta-annotation.</li> |
76 | 81 | * <li>Aliased attributes must declare the same return type.</li> |
77 | | - * <li>The {@link #annotation} must reference the meta-annotation.</li> |
| 82 | + * <li>{@link #annotation} must reference the meta-annotation.</li> |
| 83 | + * <li>The referenced meta-annotation must be <em>meta-present</em> on the |
| 84 | + * annotation class that declares {@code @AliasFor}.</li> |
| 85 | + * </ol> |
| 86 | + * </li> |
| 87 | + * <li><strong>Implicit aliases within an annotation</strong>: |
| 88 | + * <ol> |
| 89 | + * <li>Each attribute that belongs to the set of implicit aliases must be |
| 90 | + * annotated with {@code @AliasFor}, and {@link #attribute} must reference |
| 91 | + * the same attribute in the same meta-annotation.</li> |
| 92 | + * <li>Aliased attributes must declare the same return type.</li> |
| 93 | + * <li>Aliased attributes must declare a default value.</li> |
| 94 | + * <li>Aliased attributes must declare the same default value.</li> |
| 95 | + * <li>{@link #annotation} must reference the meta-annotation.</li> |
78 | 96 | * <li>The referenced meta-annotation must be <em>meta-present</em> on the |
79 | 97 | * annotation class that declares {@code @AliasFor}.</li> |
80 | 98 | * </ol> |
81 | 99 | * </li> |
82 | 100 | * </ul> |
83 | 101 | * |
84 | | - * <h3>Example: Aliases within an Annotation</h3> |
| 102 | + * <h3>Example: Explicit Aliases within an Annotation</h3> |
85 | 103 | * <pre class="code"> public @interface ContextConfiguration { |
86 | 104 | * |
87 | 105 | * @AliasFor("locations") |
|
93 | 111 | * // ... |
94 | 112 | * }</pre> |
95 | 113 | * |
96 | | - * <h3>Example: Alias for Attribute in Meta-annotation</h3> |
| 114 | + * <h3>Example: Explicit Alias for Attribute in Meta-annotation</h3> |
97 | 115 | * <pre class="code"> @ContextConfiguration |
98 | 116 | * public @interface MyTestConfig { |
99 | 117 | * |
100 | 118 | * @AliasFor(annotation = ContextConfiguration.class, attribute = "locations") |
101 | 119 | * String[] xmlFiles(); |
102 | 120 | * }</pre> |
103 | 121 | * |
| 122 | + * <h3>Example: Implicit Aliases within an Annotation</h3> |
| 123 | + * <pre class="code"> @ContextConfiguration |
| 124 | + * public @interface MyTestConfig { |
| 125 | + * |
| 126 | + * @AliasFor(annotation = ContextConfiguration.class, attribute = "locations") |
| 127 | + * String[] value() default {}; |
| 128 | + * |
| 129 | + * @AliasFor(annotation = ContextConfiguration.class, attribute = "locations") |
| 130 | + * String[] groovyScripts() default {}; |
| 131 | + * |
| 132 | + * @AliasFor(annotation = ContextConfiguration.class, attribute = "locations") |
| 133 | + * String[] xmlFiles() default {}; |
| 134 | + * }</pre> |
| 135 | + * |
104 | 136 | * <h3>Spring Annotations Supporting Attribute Aliases</h3> |
105 | 137 | * <p>As of Spring Framework 4.2, several annotations within core Spring |
106 | 138 | * have been updated to use {@code @AliasFor} to configure their internal |
|
0 commit comments