aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/javassist/bytecode/AnnotationsAttribute.java
diff options
context:
space:
mode:
authorchibash <chiba@javassist.org>2016-09-29 20:43:05 +0900
committerchibash <chiba@javassist.org>2016-09-29 20:43:05 +0900
commit5ea5b6695cf3ecb9896b9e9ce02f089b893101a4 (patch)
tree52997d8c299d2774c05d755e745013a630c16431 /src/main/javassist/bytecode/AnnotationsAttribute.java
parentfb93ae8b8f6e0646ed9b95d4d8d0abe77d601a62 (diff)
parent0e9ff9fd2bdf9ae928c7596714672a2baec01281 (diff)
downloadjavassist-5ea5b6695cf3ecb9896b9e9ce02f089b893101a4.tar.gz
javassist-5ea5b6695cf3ecb9896b9e9ce02f089b893101a4.zip
Merge branch 'master' into test/java9-jigsawtest/java9-jigsaw
Diffstat (limited to 'src/main/javassist/bytecode/AnnotationsAttribute.java')
-rw-r--r--src/main/javassist/bytecode/AnnotationsAttribute.java26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/main/javassist/bytecode/AnnotationsAttribute.java b/src/main/javassist/bytecode/AnnotationsAttribute.java
index d1d5b988..be69fe8b 100644
--- a/src/main/javassist/bytecode/AnnotationsAttribute.java
+++ b/src/main/javassist/bytecode/AnnotationsAttribute.java
@@ -214,6 +214,32 @@ public class AnnotationsAttribute extends AttributeInfo {
}
/**
+ * Removes an annotation by type.
+ * After removing an annotation, if {@link #numAnnotations()} returns 0,
+ * this annotations attribute has to be removed.
+ *
+ * @param type of annotation to remove
+ * @return whether an annotation with the given type has been removed
+ * @since 3.21
+ */
+ 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