[jboss-cvs] jbossretro/src/main/org/jboss/lang ...
David Lloyd
david.lloyd at jboss.com
Tue Oct 31 09:11:55 EST 2006
User: dlloyd
Date: 06/10/31 09:11:55
Modified: src/main/org/jboss/lang AnnotationHelper.java
Log:
Add getDeclaredAnnotations methods... incidentally, the difference is that getAnnotations is supposed to list inherited annotations, whereas getDeclaredAnnotations is not; as far as I can ascertain, the jbossretro version of getAnnotations is behaving as getDeclaredAnnotations is supposed to. Therefore I just copied getAnnotations to getDeclaredAnnotations, but as a second stage to this, getAnnotations probably should be enhanced to recursively search base types.
Revision Changes Path
1.11 +90 -2 jbossretro/src/main/org/jboss/lang/AnnotationHelper.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: AnnotationHelper.java
===================================================================
RCS file: /cvsroot/jboss/jbossretro/src/main/org/jboss/lang/AnnotationHelper.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- AnnotationHelper.java 18 Jul 2006 08:57:48 -0000 1.10
+++ AnnotationHelper.java 31 Oct 2006 14:11:55 -0000 1.11
@@ -42,7 +42,7 @@
* AnnotationHelper.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.10 $
+ * @version $Revision: 1.11 $
*/
public class AnnotationHelper
{
@@ -99,6 +99,22 @@
}
/**
+ * Get declared annotations
+ *
+ * @param clazz the class
+ * @return the annotations
+ */
+ public static Annotation[] getDeclaredAnnotations(Class clazz)
+ {
+ return convertAnnotationArray(getDeclaredAnnotationsInternal(clazz));
+ }
+
+ static Object[] getDeclaredAnnotationsInternal(Class clazz)
+ {
+ return getCtClass(clazz).getAvailableAnnotations();
+ }
+
+ /**
* Get the javassist class
*
* @param clazz the class
@@ -191,6 +207,30 @@
throw new RuntimeException("Invalid AccessibleObject passed in " + ao);
}
+ /**
+ * Get declared annotations
+ *
+ * @param ao the accessible object
+ * @return the annotations
+ */
+ public static Annotation[] getDeclaredAnnotations(AccessibleObject ao)
+ {
+ if (ao instanceof Method)
+ {
+ return getDeclaredAnnotations((Method)ao);
+ }
+ else if (ao instanceof Constructor)
+ {
+ return getDeclaredAnnotations((Constructor)ao);
+ }
+ else if (ao instanceof Field)
+ {
+ return getDeclaredAnnotations((Field)ao);
+ }
+ //Should not happen
+ throw new RuntimeException("Invalid AccessibleObject passed in " + ao);
+ }
+
/**
@@ -243,6 +283,22 @@
}
/**
+ * Get declared annotations
+ *
+ * @param method the method
+ * @return the annotations
+ */
+ public static Annotation[] getDeclaredAnnotations(Method method)
+ {
+ return convertAnnotationArray(getAnnotationsInternal(method));
+ }
+
+ public static Object[] getDeclaredAnnotationsInternal(Method method)
+ {
+ return getCtMethod(method).getAvailableAnnotations();
+ }
+
+ /**
* Get the parameter annotations
*
* @param method the method
@@ -331,6 +387,22 @@
}
/**
+ * Get declared annotations
+ *
+ * @param constructor the constructor
+ * @return the annotations
+ */
+ public static Annotation[] getDeclaredAnnotations(Constructor constructor)
+ {
+ return convertAnnotationArray(getDeclaredAnnotationsInternal(constructor));
+ }
+
+ static Object[] getDeclaredAnnotationsInternal(Constructor constructor)
+ {
+ return getCtConstructor(constructor).getAvailableAnnotations();
+ }
+
+ /**
* Get the parameter annotations
*
* @param constructor the constructor
@@ -418,6 +490,22 @@
}
/**
+ * Get declared annotations
+ *
+ * @param field the field
+ * @return the annotations
+ */
+ public static Annotation[] getDeclaredAnnotations(Field field)
+ {
+ return convertAnnotationArray(getDeclaredAnnotationsInternal(field));
+ }
+
+ static Object[] getDeclaredAnnotationsInternal(Field field)
+ {
+ return getCtField(field).getAvailableAnnotations();
+ }
+
+ /**
* Get the javassist field
*
* @param field the field
More information about the jboss-cvs-commits
mailing list