001 package net.sourceforge.retroweaver.runtime.java.lang.reflect; 002 003 import static org.objectweb.asm.Opcodes.ACC_SYNTHETIC; 004 005 import java.lang.reflect.Field; 006 007 import net.sourceforge.retroweaver.runtime.java.lang.annotation.AIB; 008 import net.sourceforge.retroweaver.runtime.java.lang.annotation.Annotation; 009 010 /** 011 * A mirror of java.lang.reflect.Field. 012 * 013 * @author Toby Reyelts Date: Feb 21, 2005 Time: 2:29:41 AM 014 */ 015 public class Field_ { 016 017 private Field_() { 018 // private constructor 019 } 020 021 // Returns this element's annotation for the specified type if such an 022 // annotation is present, else null. 023 public static <T extends Annotation> T getAnnotation(final Field f, final Class<T> annotationType) { 024 final Class c = f.getDeclaringClass(); 025 return AIB.getAib(c).getFieldAnnotation(f.getName(), annotationType); 026 } 027 028 // Returns all annotations present on this element. 029 // 030 public static Annotation[] getAnnotations(final Field f) { 031 return getDeclaredAnnotations(f); 032 } 033 034 // Returns all annotations that are directly present on this element. 035 public static Annotation[] getDeclaredAnnotations(final Field field) { 036 final Class c = field.getDeclaringClass(); 037 return AIB.getAib(c).getFieldAnnotations(field.getName()); 038 } 039 040 // Returns true if an annotation for the specified type is present on this 041 // element, else false. 042 public static boolean isAnnotationPresent(final Field field, final Class<? extends Annotation> annotationType) { 043 return getAnnotation(field, annotationType) != null; 044 } 045 046 // Returns true if this field is a synthetic field; returns false otherwise. 047 public static boolean isSynthetic(final Field f) { 048 final Class c = f.getDeclaringClass(); 049 return ReflectionDescriptor.getReflectionDescriptor(c).testFieldAccess(f, ACC_SYNTHETIC); 050 } 051 052 }