]> source.dussan.org Git - javassist.git/commitdiff
implement removal of annotations 100/head
authororeissig <oreissig+github@gmail.com>
Sat, 20 Aug 2016 12:46:14 +0000 (14:46 +0200)
committeroreissig <oreissig+github@gmail.com>
Sat, 20 Aug 2016 12:46:14 +0000 (14:46 +0200)
src/main/javassist/bytecode/AnnotationsAttribute.java

index d1d5b9886dfdcea6f742fdeacd4ab4d3ec04c27a..c4d5f3deaa6ff06f13553548ae3a1fba0a01d8c3 100644 (file)
@@ -213,6 +213,29 @@ public class AnnotationsAttribute extends AttributeInfo {
         setAnnotations(newlist);
     }
 
+    /**
+     * Removes an annotation by type.
+     *
+     * @param type        of annotation to remove
+     * @return whether an annotation with the given type has been removed
+     */
+    public boolean removeAnnotation(String type) {
+        Annotation[] annotations = getAnnotations();
+        for (int i = 0; i < annotations.length; i++) {
+            if (annotations[i].getTypeName().equals(type)) {
+                Annotation[] newlist = new Annotation[annotations.length - 1];
+                System.arraycopy(annotations, 0, newlist, 0, i);
+                if (i < annotations.length - 1) {
+                    System.arraycopy(annotations, i + 1, newlist, i,
+                                     annotations.length - i - 1);
+                }
+                setAnnotations(newlist);
+                return true;
+            }
+        }
+        return false;
+    }
+
     /**
      * Parses the annotations and returns a data structure representing
      * that parsed annotations.  Note that changes of the node values of the