<p>-version 3.11
<ul>
- <li>JIRA JASSIST-67, 68, 74, 75, 76, 83 were fixed.
+ <li>JIRA JASSIST-67, 68, 74, 75, 76, 81, 83, 84, 85 were fixed.
+ <li>Now javassist.bytecode.CodeIterator can insert a gap into
+ a large method body more than 32KB. (JIRA JASSIST-79, 80)
</ul>
<p>-version 3.10 on March 5, 2009
methodInfo.setAccessFlags(AccessFlag.of(mod));
}
+ /**
+ * 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) {
+ MethodInfo mi = getMethodInfo2();
+ AnnotationsAttribute ainfo = (AnnotationsAttribute)
+ mi.getAttribute(AnnotationsAttribute.invisibleTag);
+ AnnotationsAttribute ainfo2 = (AnnotationsAttribute)
+ mi.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 method/constructor, 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 {
+ MethodInfo mi = getMethodInfo2();
+ AnnotationsAttribute ainfo = (AnnotationsAttribute)
+ mi.getAttribute(AnnotationsAttribute.invisibleTag);
+ AnnotationsAttribute ainfo2 = (AnnotationsAttribute)
+ mi.getAttribute(AnnotationsAttribute.visibleTag);
+ return CtClassType.getAnnotationType(clz,
+ getDeclaringClass().getClassPool(),
+ ainfo, ainfo2);
+ }
+
/**
* Returns the annotations associated with this method or constructor.
*
return 0;
}
+ /**
+ * 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) {
+ return false;
+ }
+
+ /**
+ * Returns the annotation if the class has the specified annotation class.
+ * For example, if an annotation <code>@Author</code> is associated
+ * with this class, 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 {
+ return null;
+ }
+
/**
* Returns the annotations associated with this class.
* For example, if an annotation <code>@Author</code> is associated
cf.setAccessFlags(AccessFlag.of(mod));
}
+ public boolean hasAnnotation(Class clz) {
+ ClassFile cf = getClassFile2();
+ AnnotationsAttribute ainfo = (AnnotationsAttribute)
+ cf.getAttribute(AnnotationsAttribute.invisibleTag);
+ AnnotationsAttribute ainfo2 = (AnnotationsAttribute)
+ cf.getAttribute(AnnotationsAttribute.visibleTag);
+ return hasAnnotationType(clz, getClassPool(), ainfo, ainfo2);
+ }
+
+ static boolean hasAnnotationType(Class clz, ClassPool cp,
+ AnnotationsAttribute a1, AnnotationsAttribute a2)
+ {
+ Annotation[] anno1, anno2;
+
+ if (a1 == null)
+ anno1 = null;
+ else
+ anno1 = a1.getAnnotations();
+
+ if (a2 == null)
+ anno2 = null;
+ else
+ anno2 = a2.getAnnotations();
+
+ String typeName = clz.getName();
+ if (anno1 != null)
+ for (int i = 0; i < anno1.length; i++)
+ if (anno1[i].getTypeName().equals(typeName))
+ return true;
+
+ if (anno2 != null)
+ for (int i = 0; i < anno2.length; i++)
+ if (anno2[i].getTypeName().equals(typeName))
+ return true;
+
+ return false;
+ }
+
+ public Object getAnnotation(Class clz) throws ClassNotFoundException {
+ ClassFile cf = getClassFile2();
+ AnnotationsAttribute ainfo = (AnnotationsAttribute)
+ cf.getAttribute(AnnotationsAttribute.invisibleTag);
+ AnnotationsAttribute ainfo2 = (AnnotationsAttribute)
+ cf.getAttribute(AnnotationsAttribute.visibleTag);
+ return getAnnotationType(clz, getClassPool(), ainfo, ainfo2);
+ }
+
+ static Object getAnnotationType(Class clz, ClassPool cp,
+ AnnotationsAttribute a1, AnnotationsAttribute a2)
+ throws ClassNotFoundException
+ {
+ Annotation[] anno1, anno2;
+
+ if (a1 == null)
+ anno1 = null;
+ else
+ anno1 = a1.getAnnotations();
+
+ if (a2 == null)
+ anno2 = null;
+ else
+ anno2 = a2.getAnnotations();
+
+ String typeName = clz.getName();
+ if (anno1 != null)
+ for (int i = 0; i < anno1.length; i++)
+ if (anno1[i].getTypeName().equals(typeName))
+ return toAnnoType(anno1[i], cp);
+
+ if (anno2 != null)
+ for (int i = 0; i < anno2.length; i++)
+ if (anno2[i].getTypeName().equals(typeName))
+ return toAnnoType(anno2[i], cp);
+
+ return null;
+ }
+
public Object[] getAnnotations() throws ClassNotFoundException {
return getAnnotations(false);
}
fieldInfo.setAccessFlags(AccessFlag.of(mod));
}
+ /**
+ * 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.
*
*/
static class Cache extends CtMember {
protected void extendToString(StringBuffer buffer) {}
+ public boolean hasAnnotation(Class clz) { return false; }
+ public Object getAnnotation(Class clz)
+ throws ClassNotFoundException { return null; }
public Object[] getAnnotations()
throws ClassNotFoundException { return null; }
public byte[] getAttribute(String name) { return null; }
*/
public abstract void setModifiers(int mod);
+ /**
+ * 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 abstract boolean hasAnnotation(Class clz);
+
+ /**
+ * Returns the annotation if the class has the specified annotation class.
+ * For example, if an annotation <code>@Author</code> is associated
+ * with this member, 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 abstract Object getAnnotation(Class clz) throws ClassNotFoundException;
+
/**
* Returns the annotations associated with this member.
* For example, if an annotation <code>@Author</code> is associated