KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > aspectwerkz > annotation > AsmAnnotations


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.aspectwerkz.annotation;
5
6 import com.tc.backport175.Annotation;
7 import com.tc.aspectwerkz.reflect.MethodInfo;
8 import com.tc.aspectwerkz.reflect.ClassInfo;
9 import com.tc.aspectwerkz.reflect.FieldInfo;
10 import com.tc.aspectwerkz.reflect.ConstructorInfo;
11
12 /**
13  * Helper class to extract annotations by their name from a ClassInfo structure using backport API.
14  *
15  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
16  * @author <a HREF="mailto:alex@gnilux.com">Alexandre Vasseur</a>
17  */

18 public class AsmAnnotations {
19   /**
20    * Return the annotation with a specific name for a specific class.
21    *
22    * @param annotationName the annotation name
23    * @param classInfo the ClassInfo object to find the annotation on.
24    * @return the annotation or null
25    */

26   public static Annotation getAnnotation(final String JavaDoc annotationName, final ClassInfo classInfo) {
27     return classInfo.getAnnotationReader().getAnnotation(annotationName);
28   }
29
30   /**
31    * Return the annotation with a specific name for a specific method.
32    *
33    * @param annotationName the annotation name
34    * @param methodInfo the MethodInfo object to find the annotation on.
35    * @return the annotation or null
36    */

37   public static Annotation getAnnotation(final String JavaDoc annotationName, final MethodInfo methodInfo) {
38     return methodInfo.getDeclaringType().getAnnotationReader().getMethodAnnotation(
39             annotationName,
40             methodInfo.getName(),
41             methodInfo.getSignature(),
42             methodInfo.getDeclaringType().getClassLoader()
43     );
44   }
45
46   /**
47    * Return the annotation with a specific name for a specific constructor.
48    *
49    * @param annotationName the annotation name
50    * @param constructorInfo the ConstructorInfo object to find the annotation on.
51    * @return the annotation or null
52    */

53   public static Annotation getAnnotation(final String JavaDoc annotationName, final ConstructorInfo constructorInfo) {
54     return constructorInfo.getDeclaringType().getAnnotationReader().getConstructorAnnotation(
55             annotationName,
56             constructorInfo.getSignature(),
57             constructorInfo.getDeclaringType().getClassLoader()
58     );
59   }
60
61   /**
62    * Return the annotation with a specific name for a specific field.
63    *
64    * @param annotationName the annotation name
65    * @param fieldInfo the FieldInfo object to find the annotation on.
66    * @return the annotation or null
67    */

68   public static Annotation getAnnotation(final String JavaDoc annotationName, final FieldInfo fieldInfo) {
69     return fieldInfo.getDeclaringType().getAnnotationReader().getFieldAnnotation(
70             annotationName,
71             fieldInfo.getName(),
72             fieldInfo.getSignature(),
73             fieldInfo.getDeclaringType().getClassLoader()
74     );
75   }
76 }
77
Popular Tags