|
18 | 18 |
|
19 | 19 | import java.lang.annotation.Annotation;
|
20 | 20 | import java.lang.reflect.AnnotatedElement;
|
| 21 | +import java.lang.reflect.Array; |
21 | 22 | import java.lang.reflect.InvocationHandler;
|
22 | 23 | import java.lang.reflect.InvocationTargetException;
|
23 | 24 | import java.lang.reflect.Method;
|
@@ -926,10 +927,7 @@ else if (value instanceof Class[]) {
|
926 | 927 | return mappedAnnotations;
|
927 | 928 | }
|
928 | 929 | else {
|
929 |
| - for (int i = 0; i < annotations.length; i++) { |
930 |
| - annotations[i] = synthesizeAnnotation(annotations[i], annotatedElement); |
931 |
| - } |
932 |
| - return annotations; |
| 930 | + return synthesizeAnnotationArray(annotations, annotatedElement); |
933 | 931 | }
|
934 | 932 | }
|
935 | 933 |
|
@@ -1124,6 +1122,35 @@ public static <A extends Annotation> A synthesizeAnnotation(Map<String, Object>
|
1124 | 1122 | return synthesizedAnnotation;
|
1125 | 1123 | }
|
1126 | 1124 |
|
| 1125 | + /** |
| 1126 | + * <em>Synthesize</em> the supplied array of {@code annotations} by |
| 1127 | + * creating a new array of the same size and type and populating it |
| 1128 | + * with {@linkplain #synthesizeAnnotation(Annotation) synthesized} |
| 1129 | + * versions of the annotations from the input array. |
| 1130 | + * |
| 1131 | + * @param annotations the array of annotations to synthesize |
| 1132 | + * @param annotatedElement the element that is annotated with the supplied |
| 1133 | + * array of annotations; may be {@code null} if unknown |
| 1134 | + * @return a new array of synthesized annotations, or {@code null} if |
| 1135 | + * the supplied array is {@code null} |
| 1136 | + * @throws AnnotationConfigurationException if invalid configuration of |
| 1137 | + * {@code @AliasFor} is detected |
| 1138 | + * @since 4.2 |
| 1139 | + * @see #synthesizeAnnotation(Annotation, AnnotatedElement) |
| 1140 | + * @see #synthesizeAnnotation(Map, Class, AnnotatedElement) |
| 1141 | + */ |
| 1142 | + public static Annotation[] synthesizeAnnotationArray(Annotation[] annotations, AnnotatedElement annotatedElement) { |
| 1143 | + if (annotations == null) { |
| 1144 | + return null; |
| 1145 | + } |
| 1146 | + |
| 1147 | + Annotation[] synthesized = (Annotation[]) Array.newInstance(annotations.getClass().getComponentType(), annotations.length); |
| 1148 | + for (int i = 0; i < annotations.length; i++) { |
| 1149 | + synthesized[i] = synthesizeAnnotation(annotations[i], annotatedElement); |
| 1150 | + } |
| 1151 | + return synthesized; |
| 1152 | + } |
| 1153 | + |
1127 | 1154 | /**
|
1128 | 1155 | * Get a map of all attribute alias pairs, declared via {@code @AliasFor}
|
1129 | 1156 | * in the supplied annotation type.
|
|
0 commit comments