278 int memberNameIndex = buf.getShort() & 0xFFFF;
279 String memberName = constPool.getUTF8At(memberNameIndex);
280 Class<?> memberType = memberTypes.get(memberName);
281
282 if (memberType == null) {
283 // Member is no longer present in annotation type; ignore it
284 skipMemberValue(buf);
285 } else {
286 Object value = parseMemberValue(memberType, buf, constPool, container);
287 if (value instanceof AnnotationTypeMismatchExceptionProxy)
288 ((AnnotationTypeMismatchExceptionProxy) value).
289 setMember(type.members().get(memberName));
290 memberValues.put(memberName, value);
291 }
292 }
293 return annotationForMap(annotationClass, memberValues);
294 }
295
296 /**
297 * Returns an annotation of the given type backed by the given
298 * member -> value map.
299 */
300 public static Annotation annotationForMap(final Class<? extends Annotation> type,
301 final Map<String, Object> memberValues)
302 {
303 return AccessController.doPrivileged(new PrivilegedAction<Annotation>() {
304 public Annotation run() {
305 return (Annotation) Proxy.newProxyInstance(
306 type.getClassLoader(), new Class<?>[] { type },
307 new AnnotationInvocationHandler(type, memberValues));
308 }});
309 }
310
311 /**
312 * Parses the annotation member value at the current position in the
313 * specified byte buffer, resolving constant references in the specified
314 * constant pool. The cursor of the byte buffer must point to a
315 * "member_value structure" as described in the
316 * RuntimeVisibleAnnotations_attribute:
317 *
318 * member_value {
|
278 int memberNameIndex = buf.getShort() & 0xFFFF;
279 String memberName = constPool.getUTF8At(memberNameIndex);
280 Class<?> memberType = memberTypes.get(memberName);
281
282 if (memberType == null) {
283 // Member is no longer present in annotation type; ignore it
284 skipMemberValue(buf);
285 } else {
286 Object value = parseMemberValue(memberType, buf, constPool, container);
287 if (value instanceof AnnotationTypeMismatchExceptionProxy)
288 ((AnnotationTypeMismatchExceptionProxy) value).
289 setMember(type.members().get(memberName));
290 memberValues.put(memberName, value);
291 }
292 }
293 return annotationForMap(annotationClass, memberValues);
294 }
295
296 /**
297 * Returns an annotation of the given type backed by the given
298 * member {@literal ->} value map.
299 */
300 public static Annotation annotationForMap(final Class<? extends Annotation> type,
301 final Map<String, Object> memberValues)
302 {
303 return AccessController.doPrivileged(new PrivilegedAction<Annotation>() {
304 public Annotation run() {
305 return (Annotation) Proxy.newProxyInstance(
306 type.getClassLoader(), new Class<?>[] { type },
307 new AnnotationInvocationHandler(type, memberValues));
308 }});
309 }
310
311 /**
312 * Parses the annotation member value at the current position in the
313 * specified byte buffer, resolving constant references in the specified
314 * constant pool. The cursor of the byte buffer must point to a
315 * "member_value structure" as described in the
316 * RuntimeVisibleAnnotations_attribute:
317 *
318 * member_value {
|