1 8 package org.codehaus.aspectwerkz.annotation.instrumentation.asm; 9 10 import org.codehaus.aspectwerkz.annotation.Annotation; 11 import org.codehaus.aspectwerkz.annotation.AnnotationInfo; 12 import org.codehaus.aspectwerkz.reflect.ClassInfo; 13 import org.codehaus.aspectwerkz.reflect.MethodInfo; 14 import org.codehaus.aspectwerkz.reflect.ConstructorInfo; 15 import org.codehaus.aspectwerkz.reflect.FieldInfo; 16 17 import java.util.List ; 18 import java.util.Iterator ; 19 import java.util.ArrayList ; 20 21 27 public class AsmAnnotations { 28 35 public static Annotation getAnnotation(final String annotationName, final ClassInfo classInfo) { 36 List annotations = classInfo.getAnnotations(); 37 for (Iterator it = annotations.iterator(); it.hasNext();) { 38 AnnotationInfo annotationInfo = (AnnotationInfo) it.next(); 39 if (annotationInfo.getName().equals(annotationName)) { 40 return annotationInfo.getAnnotation(); 41 } 42 } 43 return null; 44 } 45 46 53 public static Annotation getAnnotation(final String annotationName, final MethodInfo methodInfo) { 54 List annotations = methodInfo.getAnnotations(); 55 for (Iterator it = annotations.iterator(); it.hasNext();) { 56 AnnotationInfo annotationInfo = (AnnotationInfo) it.next(); 57 if (annotationInfo.getName().equals(annotationName)) { 58 return annotationInfo.getAnnotation(); 59 } 60 } 61 return null; 62 } 63 64 71 public static Annotation getAnnotation(final String annotationName, final ConstructorInfo constructorInfo) { 72 List annotations = constructorInfo.getAnnotations(); 73 for (Iterator it = annotations.iterator(); it.hasNext();) { 74 AnnotationInfo annotationInfo = (AnnotationInfo) it.next(); 75 if (annotationInfo.getName().equals(annotationName)) { 76 return annotationInfo.getAnnotation(); 77 } 78 } 79 return null; 80 } 81 82 89 public static Annotation getAnnotation(final String annotationName, final FieldInfo fieldInfo) { 90 List annotations = fieldInfo.getAnnotations(); 91 for (Iterator it = annotations.iterator(); it.hasNext();) { 92 AnnotationInfo annotationInfo = (AnnotationInfo) it.next(); 93 if (annotationInfo.getName().equals(annotationName)) { 94 return annotationInfo.getAnnotation(); 95 } 96 } 97 return null; 98 } 99 100 107 public static List getAnnotations(final String annotationName, final ClassInfo classInfo) { 108 List annotations = new ArrayList (); 109 for (Iterator it = classInfo.getAnnotations().iterator(); it.hasNext();) { 110 AnnotationInfo annotationInfo = (AnnotationInfo) it.next(); 111 if (annotationInfo.getName().equals(annotationName)) { 112 annotations.add(annotationInfo.getAnnotation()); 113 } 114 } 115 return annotations; 116 } 117 118 125 public static List getAnnotations(final String annotationName, final MethodInfo methodInfo) { 126 List annotations = new ArrayList (); 127 for (Iterator it = methodInfo.getAnnotations().iterator(); it.hasNext();) { 128 AnnotationInfo annotationInfo = (AnnotationInfo) it.next(); 129 if (annotationInfo.getName().equals(annotationName)) { 130 annotations.add(annotationInfo.getAnnotation()); 131 } 132 } 133 return annotations; 134 } 135 136 143 public static List getAnnotations(final String annotationName, final ConstructorInfo constructorInfo) { 144 List annotations = new ArrayList (); 145 for (Iterator it = constructorInfo.getAnnotations().iterator(); it.hasNext();) { 146 AnnotationInfo annotationInfo = (AnnotationInfo) it.next(); 147 if (annotationInfo.getName().equals(annotationName)) { 148 annotations.add(annotationInfo.getAnnotation()); 149 } 150 } 151 return annotations; 152 } 153 154 161 public static List getAnnotations(final String annotationName, final FieldInfo fieldInfo) { 162 List annotations = new ArrayList (); 163 for (Iterator it = fieldInfo.getAnnotations().iterator(); it.hasNext();) { 164 AnnotationInfo annotationInfo = (AnnotationInfo) it.next(); 165 if (annotationInfo.getName().equals(annotationName)) { 166 annotations.add(annotationInfo.getAnnotation()); 167 } 168 } 169 return annotations; 170 } 171 172 } 173 | Popular Tags |