You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

JvstTest5.java 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package javassist;
  2. import java.lang.annotation.Annotation;
  3. import java.lang.reflect.TypeVariable;
  4. public class JvstTest5 extends JvstTestRoot {
  5. public JvstTest5(String name) {
  6. super(name);
  7. }
  8. public void testDollarClassInStaticMethod() throws Exception {
  9. CtClass cc = sloader.makeClass("test5.DollarClass");
  10. CtMethod m = CtNewMethod.make("public static int run(){ return $class.getName().length(); }", cc);
  11. cc.addMethod(m);
  12. m = CtNewMethod.make("public int run2(){ return $class.getName().length(); }", cc);
  13. cc.addMethod(m);
  14. cc.writeFile();
  15. Object obj = make(cc.getName());
  16. assertEquals(cc.getName().length(), invoke(obj, "run"));
  17. assertEquals(cc.getName().length(), invoke(obj, "run2"));
  18. }
  19. public void testSuperDefaultMethodCall() throws Exception {
  20. CtClass cc = sloader.get("test5.DefaultMethod");
  21. CtMethod m = CtNewMethod.make("public int run(){ return test5.DefaultMethodIntf.super.foo(); }", cc);
  22. cc.addMethod(m);
  23. m = CtNewMethod.make("public int run2(){ return test5.DefaultMethodIntf.baz(); }", cc);
  24. cc.addMethod(m);
  25. m = CtNewMethod.make("public int run3(){ return test5.DefaultMethodIntf.super.baz(); }", cc);
  26. cc.addMethod(m);
  27. cc.writeFile();
  28. Object obj = make(cc.getName());
  29. assertEquals(1, invoke(obj, "run"));
  30. assertEquals(10, invoke(obj, "run2"));
  31. assertEquals(10, invoke(obj, "run3"));
  32. }
  33. public void testTypeAnno() throws Exception {
  34. CtClass cc = sloader.get("test5.TypeAnno");
  35. cc.getClassFile().compact();
  36. cc.writeFile();
  37. Object obj = make(cc.getName());
  38. TypeVariable<?> t = obj.getClass().getTypeParameters()[0];
  39. Annotation[] annos = t.getAnnotations();
  40. assertEquals("@test5.TypeAnnoA()", annos[0].toString());
  41. }
  42. }