diff options
author | Shigeru Chiba <chibash@users.noreply.github.com> | 2016-09-18 22:45:41 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-18 22:45:41 +0900 |
commit | 460d41808ae623c5e60c89bcafb0aa79176d2dd8 (patch) | |
tree | c51ff46c519dfbbd662ee49a2a78a16d7bd70bde | |
parent | 0862511fae7a9594a5184b4bf65d5b84e12cd7a0 (diff) | |
parent | f68489dc1eccceeef4ad85e1eb5ad5e8704d8932 (diff) | |
download | javassist-460d41808ae623c5e60c89bcafb0aa79176d2dd8.tar.gz javassist-460d41808ae623c5e60c89bcafb0aa79176d2dd8.zip |
Merge pull request #100 from oreissig/remove-annotation
removal of annotations
-rw-r--r-- | src/main/javassist/bytecode/AnnotationsAttribute.java | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/main/javassist/bytecode/AnnotationsAttribute.java b/src/main/javassist/bytecode/AnnotationsAttribute.java index d1d5b988..c4d5f3de 100644 --- a/src/main/javassist/bytecode/AnnotationsAttribute.java +++ b/src/main/javassist/bytecode/AnnotationsAttribute.java @@ -214,6 +214,29 @@ public class AnnotationsAttribute extends AttributeInfo { } /** + * 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 * returned tree are not reflected on the annotations represented by |