| 1 | |
| 2 | package net.sourceforge.retroweaver.runtime.java.lang.reflect; |
| 3 | |
| 4 | import net.sourceforge.retroweaver.runtime.java.lang.annotation.Annotation; |
| 5 | import java.lang.reflect.*; |
| 6 | |
| 7 | /** |
| 8 | * @author Toby Reyelts |
| 9 | * Date: Feb 21, 2005 |
| 10 | * Time: 10:30:37 PM |
| 11 | */ |
| 12 | public class AccessibleObject_ { |
| 13 | |
| 14 | private AccessibleObject_() { |
| 15 | // private constructor |
| 16 | } |
| 17 | |
| 18 | public static <T extends Annotation> T getAnnotation(final AccessibleObject obj, final Class<T> annotationClass) { |
| 19 | if ( obj instanceof Constructor ) { |
| 20 | return Constructor_.getAnnotation( ( Constructor ) obj, annotationClass ); |
| 21 | } |
| 22 | else if ( obj instanceof Method ) { |
| 23 | return Method_.getAnnotation( ( Method ) obj, annotationClass ); |
| 24 | } |
| 25 | else if ( obj instanceof Field ) { |
| 26 | return Field_.getAnnotation( ( Field ) obj, annotationClass ); |
| 27 | } |
| 28 | else { |
| 29 | throw new UnsupportedOperationException( "Unexpected AccessibleObject type: " + obj.getClass() ); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | public static Annotation[] getAnnotations(final AccessibleObject obj) { |
| 34 | return getDeclaredAnnotations( obj ); |
| 35 | } |
| 36 | |
| 37 | public static Annotation[] getDeclaredAnnotations(final AccessibleObject obj) { |
| 38 | if ( obj instanceof Constructor ) { |
| 39 | return Constructor_.getDeclaredAnnotations( ( Constructor ) obj ); |
| 40 | } |
| 41 | else if ( obj instanceof Method ) { |
| 42 | return Method_.getDeclaredAnnotations( ( Method ) obj ); |
| 43 | } |
| 44 | else if ( obj instanceof Field ) { |
| 45 | return Field_.getDeclaredAnnotations( ( Field ) obj ); |
| 46 | } |
| 47 | else { |
| 48 | throw new UnsupportedOperationException( "Unexpected AccessibleObject type: " + obj.getClass() ); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | public static boolean isAnnotationPresent(final AccessibleObject obj, final Class<? extends Annotation> annotationClass) { |
| 53 | if ( obj instanceof Constructor ) { |
| 54 | return Constructor_.isAnnotationPresent( ( Constructor ) obj, annotationClass ); |
| 55 | } |
| 56 | else if ( obj instanceof Method ) { |
| 57 | return Method_.isAnnotationPresent( ( Method ) obj, annotationClass ); |
| 58 | } |
| 59 | else if ( obj instanceof Field ) { |
| 60 | return Field_.isAnnotationPresent( ( Field ) obj, annotationClass ); |
| 61 | } |
| 62 | else { |
| 63 | throw new UnsupportedOperationException( "Unexpected AccessibleObject type: " + obj.getClass() ); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | } |
| 68 | |