diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2009-06-26 15:29:48 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2009-06-26 15:29:48 +0000 |
commit | a690c8bf872c9e5fe4e14b6095ddb81de01a34c4 (patch) | |
tree | c48a75507a2a9f9ef16b7983821f8d6a6a6f3e70 /src/main/javassist/CtField.java | |
parent | 3fcf471e97d82d5f7ad17d554bdd582c8a1a6986 (diff) | |
download | javassist-a690c8bf872c9e5fe4e14b6095ddb81de01a34c4.tar.gz javassist-a690c8bf872c9e5fe4e14b6095ddb81de01a34c4.zip |
fixed JASSIST-84
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@484 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main/javassist/CtField.java')
-rw-r--r-- | src/main/javassist/CtField.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/main/javassist/CtField.java b/src/main/javassist/CtField.java index 6903daf2..af573d2c 100644 --- a/src/main/javassist/CtField.java +++ b/src/main/javassist/CtField.java @@ -241,6 +241,44 @@ public class CtField extends CtMember { } /** + * Returns true if the class has the specified annotation class. + * + * @param clz the annotation class. + * @return <code>true</code> if the annotation is found, otherwise <code>false</code>. + * @since 3.11 + */ + public boolean hasAnnotation(Class clz) { + FieldInfo fi = getFieldInfo2(); + AnnotationsAttribute ainfo = (AnnotationsAttribute) + fi.getAttribute(AnnotationsAttribute.invisibleTag); + AnnotationsAttribute ainfo2 = (AnnotationsAttribute) + fi.getAttribute(AnnotationsAttribute.visibleTag); + return CtClassType.hasAnnotationType(clz, getDeclaringClass().getClassPool(), + ainfo, ainfo2); + } + + /** + * Returns the annotation if the class has the specified annotation class. + * For example, if an annotation <code>@Author</code> is associated + * with this field, an <code>Author</code> object is returned. + * The member values can be obtained by calling methods on + * the <code>Author</code> object. + * + * @param clz the annotation class. + * @return the annotation if found, otherwise <code>null</code>. + * @since 3.11 + */ + public Object getAnnotation(Class clz) throws ClassNotFoundException { + FieldInfo fi = getFieldInfo2(); + AnnotationsAttribute ainfo = (AnnotationsAttribute) + fi.getAttribute(AnnotationsAttribute.invisibleTag); + AnnotationsAttribute ainfo2 = (AnnotationsAttribute) + fi.getAttribute(AnnotationsAttribute.visibleTag); + return CtClassType.getAnnotationType(clz, getDeclaringClass().getClassPool(), + ainfo, ainfo2); + } + + /** * Returns the annotations associated with this field. * * @return an array of annotation-type objects. |