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.

AnonymousClassName.java 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import org.aspectj.testing.Tester;
  2. import org.aspectj.lang.*;
  3. import org.aspectj.lang.reflect.*;
  4. /** @testcase declaring type in signature of anonymous class */
  5. public class AnonymousClassName {
  6. public static void main(String[] args) {
  7. Tester.expectEvent("run()");
  8. new Runnable(){
  9. public void run() {
  10. Tester.event("run()");
  11. }
  12. }.run();
  13. Tester.checkAllEvents();
  14. }
  15. }
  16. aspect A {
  17. static {
  18. Tester.expectEvent("before constructRunnable");
  19. Tester.expectEvent("before callRun");
  20. Tester.expectEvent("before executeRun");
  21. Tester.expectEvent("before initRunnable");
  22. Tester.expectEvent("around constructRunnable");
  23. Tester.expectEvent("around callRun");
  24. Tester.expectEvent("around executeRun");
  25. Tester.expectEvent("around initRunnable");
  26. Tester.expectEvent("after constructRunnable");
  27. Tester.expectEvent("after callRun");
  28. Tester.expectEvent("after executeRun");
  29. Tester.expectEvent("after initRunnable");
  30. }
  31. static final int Runnable+.provokeStaticInit = 1;
  32. pointcut constructRunnable () : call(Runnable+.new());
  33. pointcut initRunnable () : staticinitialization(Runnable+);
  34. pointcut callRun () : target(Runnable) && call(void run());
  35. pointcut executeRun () : target(Runnable) && execution(void run());
  36. before () : constructRunnable() { check("before constructRunnable", thisJoinPoint); }
  37. before () : callRun() { check("before callRun", thisJoinPoint); }
  38. before () : executeRun() { check("before executeRun", thisJoinPoint); }
  39. before () : initRunnable() { check("before initRunnable", thisJoinPoint); }
  40. Object around () : constructRunnable() {
  41. check("around constructRunnable", thisJoinPoint);
  42. return proceed();
  43. }
  44. Object around () : callRun() {
  45. check("around callRun", thisJoinPoint);
  46. return proceed();
  47. }
  48. Object around () : executeRun() {
  49. check("around executeRun", thisJoinPoint);
  50. return proceed();
  51. }
  52. Object around () : initRunnable() {
  53. check("around initRunnable", thisJoinPoint);
  54. return proceed();
  55. }
  56. after () : constructRunnable() { check("after constructRunnable", thisJoinPoint); }
  57. after () : callRun() { check("after callRun", thisJoinPoint); }
  58. after () : executeRun() { check("after executeRun", thisJoinPoint); }
  59. after () : initRunnable() { check("after initRunnable", thisJoinPoint); }
  60. void check(String event, JoinPoint jp) {
  61. Tester.event(event);
  62. //System.err.println(event + ": " + jp.toLongString());
  63. Signature sig = jp.getSignature();
  64. Class c = sig.getDeclaringType();
  65. Tester.check(null != c, event + " null class");
  66. Tester.check(ClassNotFoundException.class != c,
  67. event + " got: " + c);
  68. String name = "" + sig;
  69. Tester.check(-1 != name.indexOf("AnonymousClassName"),
  70. event + " expecting AnonymousClassName..: " + name);
  71. }
  72. }