diff options
author | chibash <chiba@javassist.org> | 2014-11-19 05:49:27 +0900 |
---|---|---|
committer | chibash <chiba@javassist.org> | 2014-11-19 05:49:27 +0900 |
commit | 0ba6f9efdc82e386e8716d8f2b1f25a1b95580a8 (patch) | |
tree | a026009c0c5399659b9c09f43643800d76a1eb05 /src/test | |
parent | a0f4d935a20ffeefcfe4c66730ec702b7fff0928 (diff) | |
download | javassist-0ba6f9efdc82e386e8716d8f2b1f25a1b95580a8.tar.gz javassist-0ba6f9efdc82e386e8716d8f2b1f25a1b95580a8.zip |
for fixing JASSIST-236, I've added getDeclaredMethods(String) to CtClass.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/javassist/JvstTest4.java | 34 | ||||
-rw-r--r-- | src/test/test4/AnnoLoad.java | 5 | ||||
-rw-r--r-- | src/test/test4/DeclMethodsList.java | 7 |
3 files changed, 46 insertions, 0 deletions
diff --git a/src/test/javassist/JvstTest4.java b/src/test/javassist/JvstTest4.java index d92384b4..13784fd7 100644 --- a/src/test/javassist/JvstTest4.java +++ b/src/test/javassist/JvstTest4.java @@ -5,7 +5,10 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.HashSet; +import java.util.List; + import javassist.bytecode.*; +import javassist.bytecode.annotation.Annotation; import javassist.expr.*; public class JvstTest4 extends JvstTestRoot { @@ -1038,4 +1041,35 @@ public class JvstTest4 extends JvstTestRoot { assertEquals("test4.AnnoArg$B", a.value().getName()); System.out.println(a.value().getName()); } + + public void testDeclaredMethods() throws Exception { + CtClass cc = sloader.get("test4.DeclMethodsList"); + CtMethod[] meth = cc.getDeclaredMethods("foo"); + assertEquals(2, meth.length); + assertEquals("()V", meth[0].getSignature()); + assertEquals("(I)I", meth[1].getSignature()); + meth = cc.getDeclaredMethods("bar"); + assertEquals(1, meth.length); + assertEquals("()V", meth[0].getSignature()); + meth = cc.getDeclaredMethods("baz"); + assertEquals(0, meth.length); + } + + public void testAnnotationLoader() throws Exception { + CtClass anno = sloader.makeAnnotation("test4.AnnoLoadAnno", null); + anno.debugWriteFile(); + CtClass cc = sloader.get("test4.AnnoLoad"); + CtMethod m = cc.getDeclaredMethod("foo"); + ClassFile cf = cc.getClassFile(); + ConstPool cp = cf.getConstPool(); + AnnotationsAttribute attr + = new AnnotationsAttribute(cp, AnnotationsAttribute.visibleTag); + Annotation a = new Annotation(anno.getName(), cp); + attr.setAnnotation(a); + m.getMethodInfo().addAttribute(attr); + cc.writeFile(); + Object obj = m.getAnnotations()[0]; + String name = obj.getClass().getName(); + assertEquals(anno.getName(), name); + } } diff --git a/src/test/test4/AnnoLoad.java b/src/test/test4/AnnoLoad.java new file mode 100644 index 00000000..fba397cb --- /dev/null +++ b/src/test/test4/AnnoLoad.java @@ -0,0 +1,5 @@ +package test4; + +public class AnnoLoad { + public int foo() { return 0; } +} diff --git a/src/test/test4/DeclMethodsList.java b/src/test/test4/DeclMethodsList.java new file mode 100644 index 00000000..e762e4cc --- /dev/null +++ b/src/test/test4/DeclMethodsList.java @@ -0,0 +1,7 @@ +package test4; + +public class DeclMethodsList { + public void foo() {} + int foo(int i) { return i; } + public void bar() {} +} |