aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorchibash <chiba@javassist.org>2014-09-11 00:54:08 +0900
committerchibash <chiba@javassist.org>2014-09-11 00:54:08 +0900
commit4cdb575d4ea4ebed471f691d60f9d40b372a9fd1 (patch)
tree6cb7f2562a42abdc4625bc436cbf5943035b9883 /src/test
parent1d3ff9f328f1f90be71799857fc0ce9814eea4df (diff)
downloadjavassist-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')
-rw-r--r--src/test/Test.java32
-rw-r--r--src/test/javassist/JvstTest4.java8
-rw-r--r--src/test/test4/AnnoArg.java18
3 files changed, 45 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); }
}
diff --git a/src/test/javassist/JvstTest4.java b/src/test/javassist/JvstTest4.java
index b36e9b9f..d92384b4 100644
--- a/src/test/javassist/JvstTest4.java
+++ b/src/test/javassist/JvstTest4.java
@@ -1030,4 +1030,12 @@ public class JvstTest4 extends JvstTestRoot {
CtMethod m = CtNewMethod.make(meth, cc);
cc.addMethod(m);
}
+
+ public void testAnnArg() throws Exception {
+ CtClass cc = sloader.get("test4.AnnoArg");
+ CtMethod m = cc.getDeclaredMethod("foo");
+ test4.AnnoArg.AnnoArgAt a = (test4.AnnoArg.AnnoArgAt)m.getAnnotations()[0];
+ assertEquals("test4.AnnoArg$B", a.value().getName());
+ System.out.println(a.value().getName());
+ }
}
diff --git a/src/test/test4/AnnoArg.java b/src/test/test4/AnnoArg.java
new file mode 100644
index 00000000..0184d41e
--- /dev/null
+++ b/src/test/test4/AnnoArg.java
@@ -0,0 +1,18 @@
+package test4;
+
+public class AnnoArg {
+ public static @interface AnnoArgAt {
+ Class<? extends AnnoArg.A> value();
+ }
+
+ public static class A {
+ int baz() { return 1; }
+ }
+
+ public static class B extends A {
+ int baz() { return 2; }
+ }
+
+ @AnnoArgAt(B.class)
+ public int foo(int i) { return i; }
+}