diff options
author | chibash <chiba@javassist.org> | 2019-09-20 23:20:39 +0900 |
---|---|---|
committer | chibash <chiba@javassist.org> | 2019-09-20 23:20:39 +0900 |
commit | 91086509023cb7cfac0132553ee2871859ad6721 (patch) | |
tree | c3ca739488cd20a2668caf0b9d330324fa4ed340 /src/test | |
parent | f7ef31ce8b723e425a66aafb8c0beddeabfe9a66 (diff) | |
download | javassist-91086509023cb7cfac0132553ee2871859ad6721.tar.gz javassist-91086509023cb7cfac0132553ee2871859ad6721.zip |
adds CtBehavior#insertAfter(String,boolean,boolean) for Issue #275
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/javassist/JvstTest5.java | 12 | ||||
-rw-r--r-- | src/test/test5/InsertAfter.java | 35 |
2 files changed, 47 insertions, 0 deletions
diff --git a/src/test/javassist/JvstTest5.java b/src/test/javassist/JvstTest5.java index 4d4fc719..c2ee9992 100644 --- a/src/test/javassist/JvstTest5.java +++ b/src/test/javassist/JvstTest5.java @@ -546,4 +546,16 @@ public class JvstTest5 extends JvstTestRoot { Object obj = make(cc.getName()); assertEquals(1, invoke(obj, "run")); } + + // Issue #275 + public void testRedundantInsertAfter() throws Exception { + CtClass cc = sloader.get(test5.InsertAfter.class.getName()); + CtMethod m = cc.getDeclaredMethod("foo"); + m.insertAfter("{ $_ += 1; }", false, true); + CtMethod m2 = cc.getDeclaredMethod("bar"); + m2.insertAfter("{ $_ += 1; }", true, true); + cc.writeFile(); + Object obj = make(cc.getName()); + assertEquals(1, invoke(obj, "run")); + } } diff --git a/src/test/test5/InsertAfter.java b/src/test/test5/InsertAfter.java new file mode 100644 index 00000000..6d62c06a --- /dev/null +++ b/src/test/test5/InsertAfter.java @@ -0,0 +1,35 @@ +package test5; + +public class InsertAfter { + public int run() { + return foo(7) + bar(20); + } + + public int foo(int k) { + if (k > 0) + if (k > 10) + return k + 1; + else + return k * 10; + else + return k * 100; + } + + public int bar(int k) { + if (k > 0) + try { + if (k > 10) + return k + 1; + else + return k * 10; + } + catch (Exception e) { + if (k > 0) + return k * 1000; + else + throw e; + } + else + return k * 100; + } +} |