01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.aspectwerkz.annotation;
05:
06: import com.tc.backport175.Annotation;
07: import com.tc.aspectwerkz.reflect.MethodInfo;
08: import com.tc.aspectwerkz.reflect.ClassInfo;
09: 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 annotationName,
27: final ClassInfo classInfo) {
28: return classInfo.getAnnotationReader().getAnnotation(
29: annotationName);
30: }
31:
32: /**
33: * Return the annotation with a specific name for a specific method.
34: *
35: * @param annotationName the annotation name
36: * @param methodInfo the MethodInfo object to find the annotation on.
37: * @return the annotation or null
38: */
39: public static Annotation getAnnotation(final String annotationName,
40: final MethodInfo methodInfo) {
41: return methodInfo.getDeclaringType().getAnnotationReader()
42: .getMethodAnnotation(annotationName,
43: methodInfo.getName(),
44: methodInfo.getSignature(),
45: methodInfo.getDeclaringType().getClassLoader());
46: }
47:
48: /**
49: * Return the annotation with a specific name for a specific constructor.
50: *
51: * @param annotationName the annotation name
52: * @param constructorInfo the ConstructorInfo object to find the annotation on.
53: * @return the annotation or null
54: */
55: public static Annotation getAnnotation(final String annotationName,
56: final ConstructorInfo constructorInfo) {
57: return constructorInfo.getDeclaringType().getAnnotationReader()
58: .getConstructorAnnotation(
59: annotationName,
60: constructorInfo.getSignature(),
61: constructorInfo.getDeclaringType()
62: .getClassLoader());
63: }
64:
65: /**
66: * Return the annotation with a specific name for a specific field.
67: *
68: * @param annotationName the annotation name
69: * @param fieldInfo the FieldInfo object to find the annotation on.
70: * @return the annotation or null
71: */
72: public static Annotation getAnnotation(final String annotationName,
73: final FieldInfo fieldInfo) {
74: return fieldInfo.getDeclaringType().getAnnotationReader()
75: .getFieldAnnotation(annotationName,
76: fieldInfo.getName(), fieldInfo.getSignature(),
77: fieldInfo.getDeclaringType().getClassLoader());
78: }
79: }
|