001
002 package net.sourceforge.retroweaver.runtime.java.lang.reflect;
003
004 import net.sourceforge.retroweaver.runtime.java.lang.annotation.Annotation;
005 import java.lang.reflect.*;
006
007 /**
008 * @author Toby Reyelts
009 * Date: Feb 21, 2005
010 * Time: 10:30:37 PM
011 */
012 public class AccessibleObject_ {
013
014 private AccessibleObject_() {
015 // private constructor
016 }
017
018 public static <T extends Annotation> T getAnnotation(final AccessibleObject obj, final Class<T> annotationClass) {
019 if ( obj instanceof Constructor ) {
020 return Constructor_.getAnnotation( ( Constructor ) obj, annotationClass );
021 }
022 else if ( obj instanceof Method ) {
023 return Method_.getAnnotation( ( Method ) obj, annotationClass );
024 }
025 else if ( obj instanceof Field ) {
026 return Field_.getAnnotation( ( Field ) obj, annotationClass );
027 }
028 else {
029 throw new UnsupportedOperationException( "Unexpected AccessibleObject type: " + obj.getClass() );
030 }
031 }
032
033 public static Annotation[] getAnnotations(final AccessibleObject obj) {
034 return getDeclaredAnnotations( obj );
035 }
036
037 public static Annotation[] getDeclaredAnnotations(final AccessibleObject obj) {
038 if ( obj instanceof Constructor ) {
039 return Constructor_.getDeclaredAnnotations( ( Constructor ) obj );
040 }
041 else if ( obj instanceof Method ) {
042 return Method_.getDeclaredAnnotations( ( Method ) obj );
043 }
044 else if ( obj instanceof Field ) {
045 return Field_.getDeclaredAnnotations( ( Field ) obj );
046 }
047 else {
048 throw new UnsupportedOperationException( "Unexpected AccessibleObject type: " + obj.getClass() );
049 }
050 }
051
052 public static boolean isAnnotationPresent(final AccessibleObject obj, final Class<? extends Annotation> annotationClass) {
053 if ( obj instanceof Constructor ) {
054 return Constructor_.isAnnotationPresent( ( Constructor ) obj, annotationClass );
055 }
056 else if ( obj instanceof Method ) {
057 return Method_.isAnnotationPresent( ( Method ) obj, annotationClass );
058 }
059 else if ( obj instanceof Field ) {
060 return Field_.isAnnotationPresent( ( Field ) obj, annotationClass );
061 }
062 else {
063 throw new UnsupportedOperationException( "Unexpected AccessibleObject type: " + obj.getClass() );
064 }
065 }
066
067 }
068