diff options
author | chibash <chiba@javassist.org> | 2016-09-18 23:49:43 +0900 |
---|---|---|
committer | chibash <chiba@javassist.org> | 2016-09-18 23:49:43 +0900 |
commit | 0e9ff9fd2bdf9ae928c7596714672a2baec01281 (patch) | |
tree | 43578517e2a79e27ac5732b6f31b6b337dc988db /src/test/javassist/JvstTest5.java | |
parent | 460d41808ae623c5e60c89bcafb0aa79176d2dd8 (diff) | |
download | javassist-0e9ff9fd2bdf9ae928c7596714672a2baec01281.tar.gz javassist-0e9ff9fd2bdf9ae928c7596714672a2baec01281.zip |
enables removal of attributes
Diffstat (limited to 'src/test/javassist/JvstTest5.java')
-rw-r--r-- | src/test/javassist/JvstTest5.java | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/test/javassist/JvstTest5.java b/src/test/javassist/JvstTest5.java index 779df525..c20a85f2 100644 --- a/src/test/javassist/JvstTest5.java +++ b/src/test/javassist/JvstTest5.java @@ -4,6 +4,7 @@ import java.lang.annotation.Annotation; import java.lang.reflect.TypeVariable; import javassist.bytecode.AnnotationsAttribute; +import javassist.bytecode.AttributeInfo; import javassist.bytecode.ClassFile; import javassist.bytecode.ConstPool; import javassist.bytecode.InnerClassesAttribute; @@ -251,4 +252,36 @@ public class JvstTest5 extends JvstTestRoot { fail(); } catch (CannotCompileException e) {} } + + public void testRemoveAnnotatino() throws Exception { + CtClass cc = sloader.get("test5.RemoveAnnotation"); + AnnotationsAttribute aa + = (AnnotationsAttribute)cc.getClassFile().getAttribute(AnnotationsAttribute.invisibleTag); + assertTrue(aa.removeAnnotation("test5.RemoveAnno1")); + AttributeInfo ai = cc.getClassFile().removeAttribute(AnnotationsAttribute.invisibleTag); + assertEquals(ai.getName(), AnnotationsAttribute.invisibleTag); + + CtMethod foo = cc.getDeclaredMethod("foo"); + AnnotationsAttribute aa2 = (AnnotationsAttribute)foo.getMethodInfo().getAttribute(AnnotationsAttribute.invisibleTag); + assertTrue(aa2.removeAnnotation("test5.RemoveAnno1")); + + CtMethod bar = cc.getDeclaredMethod("bar"); + AnnotationsAttribute aa3 = (AnnotationsAttribute)bar.getMethodInfo().getAttribute(AnnotationsAttribute.invisibleTag); + assertFalse(aa3.removeAnnotation("test5.RemoveAnno1")); + assertTrue(aa3.removeAnnotation("test5.RemoveAnno2")); + AttributeInfo ai2 = bar.getMethodInfo().removeAttribute(AnnotationsAttribute.invisibleTag); + assertEquals(ai2.getName(), AnnotationsAttribute.invisibleTag); + + CtMethod run = cc.getDeclaredMethod("run"); + AttributeInfo ai3 = run.getMethodInfo().removeAttribute(AnnotationsAttribute.invisibleTag); + assertNull(ai3); + + CtField baz = cc.getDeclaredField("baz"); + AttributeInfo ai4 = baz.getFieldInfo().removeAttribute(AnnotationsAttribute.invisibleTag); + assertEquals(ai4.getName(), AnnotationsAttribute.invisibleTag); + + cc.writeFile(); + Object obj = make(cc.getName()); + assertEquals(3, invoke(obj, "run")); + } } |