Permalink
Browse files

Added a method for checking if a CtMethod has a specific Annotation

  • Loading branch information...
1 parent 51fd0ca commit 772d764222591c15654f1222f92258eafd1ea701 @omaroman omaroman committed Sep 7, 2011
Showing with 17 additions and 0 deletions.
  1. +17 −0 framework/src/play/classloading/enhancers/Enhancer.java
@@ -120,6 +120,23 @@ protected boolean hasAnnotation(CtField ctField, String annotation) throws Class
}
return false;
}
+
+ /**
+ * Test if a method has the provided annotation
+ * @param ctMethod the javassist method representation
+ * @param annotation fully qualified name of the annotation class eg."javax.persistence.Entity"
+ * @return true if field has the annotation
+ * @throws java.lang.ClassNotFoundException
+ */
+ protected boolean hasAnnotation(CtMethod ctMethod, String annotation) throws ClassNotFoundException {
+ for (Object object : ctMethod.getAvailableAnnotations()) {
+ Annotation ann = (Annotation) object;
+ if (ann.annotationType().getName().equals(annotation)) {
+ return true;
+ }
+ }
+ return false;
+ }
/**
* Create a new annotation to be dynamically inserted in the byte code.

0 comments on commit 772d764

Please sign in to comment.