More lazy initialization done for FieldAttributes.

This commit is contained in:
Joel Leitch 2009-12-03 22:28:58 +00:00
parent 641390b1a1
commit 33e816dcf0

View File

@ -39,6 +39,7 @@ public final class FieldAttributes {
private Class<?> declaredType;
private Integer modifiers;
private Boolean isSynthetic;
private Annotation[] annotations;
/**
* Constructs a Field Attributes object from the {@code f}.
@ -114,7 +115,10 @@ public final class FieldAttributes {
* @return the annotation instance if it is bound to the field; otherwise {@code null}
*/
public <T extends Annotation> T getAnnotation(Class<T> annotation) {
return field.getAnnotation(annotation);
if (annotations == null) {
annotations = field.getAnnotations();
}
return getAnnotationFromArray(annotations, annotation);
}
/**
@ -145,4 +149,15 @@ public final class FieldAttributes {
}
return isSynthetic;
}
@SuppressWarnings("unchecked")
private static <T extends Annotation> T getAnnotationFromArray(
Annotation[] annotations, Class<T> annotation) {
for (Annotation a : annotations) {
if (a.annotationType() == annotation) {
return (T) a;
}
}
return null;
}
}