diff options
author | chibash <chiba@javassist.org> | 2014-09-11 00:54:08 +0900 |
---|---|---|
committer | chibash <chiba@javassist.org> | 2014-09-11 00:54:08 +0900 |
commit | 4cdb575d4ea4ebed471f691d60f9d40b372a9fd1 (patch) | |
tree | 6cb7f2562a42abdc4625bc436cbf5943035b9883 /src/test/Test.java | |
parent | 1d3ff9f328f1f90be71799857fc0ce9814eea4df (diff) | |
download | javassist-4cdb575d4ea4ebed471f691d60f9d40b372a9fd1.tar.gz javassist-4cdb575d4ea4ebed471f691d60f9d40b372a9fd1.zip |
fixed a bug of accesses to annotation arguments.
If foo.Bar.Baz is a nested class in foo.Bar, then the argument of
@MyAnnotation(foo.bar.Baz.class) could not be obtained.
The test code is javassist.JvstTest4#testAnnArg().
Diffstat (limited to 'src/test/Test.java')
-rw-r--r-- | src/test/Test.java | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/src/test/Test.java b/src/test/Test.java index 044b7d4e..83fe2954 100644 --- a/src/test/Test.java +++ b/src/test/Test.java @@ -2,19 +2,25 @@ import javassist.*; public class Test { public static void main(String[] args) throws Exception { - ClassPool cp = ClassPool.getDefault(); - CtClass newClass = cp.makeClass("test4.TestDeadcode"); - addDeadCode(newClass, "public void evaluate5(){ boolean b = !false; b = false && b; b = true && true;" - + " b = true || b; b = b || false; }"); + if (args.length > 1) { + new Test().bar(3); + return; + } - newClass.debugWriteFile(); - Class<?> cClass = newClass.toClass(); - Object o = cClass.newInstance(); - java.lang.reflect.Method m = cClass.getMethod("evaluate5"); - m.invoke(o); - } - private static void addDeadCode(CtClass cc, String meth) throws Exception { - CtMethod m = CtNewMethod.make(meth, cc); - cc.addMethod(m); + ClassPool cp = ClassPool.getDefault(); + CtClass str = cp.get("java.lang.String"); + CtClass cc = cp.get("Test"); + cc.getClassFile().setMajorVersion(javassist.bytecode.ClassFile.JAVA_4); + CtMethod m = cc.getDeclaredMethod("bar"); + m.addLocalVariable("aVar", str); + m.insertAfter(" dismiss( aVar );" , true); + cc.getClassFile().setMajorVersion(javassist.bytecode.ClassFile.JAVA_7); + m.insertBefore("aVar = initVar();"); + cc.writeFile(); } + + public void bar(int i) { foo(i); } + public void foo(int i) { System.out.println(i); } + public String initVar() { return "init"; } + public void dismiss(String s) { System.out.println(s); } } |