1 | package net.sourceforge.retroweaver.runtime.java.lang.reflect; |
2 | |
3 | import static org.objectweb.asm.Opcodes.ACC_SYNTHETIC; |
4 | |
5 | import java.lang.reflect.Field; |
6 | |
7 | import net.sourceforge.retroweaver.runtime.java.lang.annotation.AIB; |
8 | import net.sourceforge.retroweaver.runtime.java.lang.annotation.Annotation; |
9 | |
10 | /** |
11 | * A mirror of java.lang.reflect.Field. |
12 | * |
13 | * @author Toby Reyelts Date: Feb 21, 2005 Time: 2:29:41 AM |
14 | */ |
15 | public class Field_ { |
16 | |
17 | private Field_() { |
18 | // private constructor |
19 | } |
20 | |
21 | // Returns this element's annotation for the specified type if such an |
22 | // annotation is present, else null. |
23 | public static <T extends Annotation> T getAnnotation(final Field f, final Class<T> annotationType) { |
24 | final Class c = f.getDeclaringClass(); |
25 | return AIB.getAib(c).getFieldAnnotation(f.getName(), annotationType); |
26 | } |
27 | |
28 | // Returns all annotations present on this element. |
29 | // |
30 | public static Annotation[] getAnnotations(final Field f) { |
31 | return getDeclaredAnnotations(f); |
32 | } |
33 | |
34 | // Returns all annotations that are directly present on this element. |
35 | public static Annotation[] getDeclaredAnnotations(final Field field) { |
36 | final Class c = field.getDeclaringClass(); |
37 | return AIB.getAib(c).getFieldAnnotations(field.getName()); |
38 | } |
39 | |
40 | // Returns true if an annotation for the specified type is present on this |
41 | // element, else false. |
42 | public static boolean isAnnotationPresent(final Field field, final Class<? extends Annotation> annotationType) { |
43 | return getAnnotation(field, annotationType) != null; |
44 | } |
45 | |
46 | // Returns true if this field is a synthetic field; returns false otherwise. |
47 | public static boolean isSynthetic(final Field f) { |
48 | final Class c = f.getDeclaringClass(); |
49 | return ReflectionDescriptor.getReflectionDescriptor(c).testFieldAccess(f, ACC_SYNTHETIC); |
50 | } |
51 | |
52 | } |