diff options
author | shifujun <shifujun@foxmail.com> | 2019-02-01 17:26:07 +0800 |
---|---|---|
committer | shifujun <shifujun@foxmail.com> | 2019-02-01 17:33:00 +0800 |
commit | c85bc4f090044d657419f82b5fc33434ab911c62 (patch) | |
tree | 0ab0bd3ecc8d9370abb62f4ea13df00fb8e19bf9 /src/test | |
parent | 6ea8021f1517ee2923bd5d50dc466594ac7f68bf (diff) | |
download | javassist-c85bc4f090044d657419f82b5fc33434ab911c62.tar.gz javassist-c85bc4f090044d657419f82b5fc33434ab911c62.zip |
add a new CodeConverter method:redirectMethodCallToStatic
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/javassist/JvstTest3.java | 14 | ||||
-rw-r--r-- | src/test/test3/MethodRedirectToStatic.java | 22 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/test/javassist/JvstTest3.java b/src/test/javassist/JvstTest3.java index 46f06b16..c065170c 100644 --- a/src/test/javassist/JvstTest3.java +++ b/src/test/javassist/JvstTest3.java @@ -586,6 +586,20 @@ public class JvstTest3 extends JvstTestRoot { assertEquals(524, invoke(obj, "test")); } + public void testMethodRedirectToStatic() throws Exception { + CtClass targetClass = sloader.get("test3.MethodRedirectToStatic"); + CtClass staticClass = sloader.get("test3.MethodRedirectToStatic2"); + CtMethod targetMethod = targetClass.getDeclaredMethod("add"); + CtMethod staticMethod = staticClass.getDeclaredMethod("add2"); + CodeConverter conv = new CodeConverter(); + + conv.redirectMethodCallToStatic(targetMethod, staticMethod); + targetClass.instrument(conv); + targetClass.writeFile(); + Object obj = make(targetClass.getName()); + assertEquals(30, invoke(obj, "test")); + } + public void testClassMap() throws Exception { ClassMap map = new ClassMap(); map.put("aa", "AA"); diff --git a/src/test/test3/MethodRedirectToStatic.java b/src/test/test3/MethodRedirectToStatic.java new file mode 100644 index 00000000..f1d68e35 --- /dev/null +++ b/src/test/test3/MethodRedirectToStatic.java @@ -0,0 +1,22 @@ +package test3; + +public class MethodRedirectToStatic { + + public static void main(String[] args) { + System.out.println(new MethodRedirectToStatic().test()); + } + + int add(int a, int b) { + return a + b; + } + + public int test() { + return add(1, 2); + } +} + +class MethodRedirectToStatic2 { + public static int add2(MethodRedirectToStatic target, int a, int b) { + return target.add(a * 10, b * 10); + } +} |