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.

BindingThisInsteadOfFormal.java 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import org.aspectj.testing.*;
  2. public class BindingThisInsteadOfFormal {
  3. public static void main(String[] args) {
  4. Caller c = new Caller();
  5. c.goo();
  6. Tester.checkAllEvents();
  7. }
  8. static {
  9. Tester.expectEvent("before-string");
  10. Tester.expectEvent("before-go");
  11. Tester.expectEvent("before-static");
  12. Tester.expectEvent("before-c");
  13. }
  14. }
  15. class Caller {
  16. void goo() {
  17. go();
  18. staticGo();
  19. }
  20. void go() {
  21. String string = new String("string");
  22. C c = new C();
  23. }
  24. static void staticGo() {
  25. }
  26. }
  27. class C {
  28. }
  29. aspect Aspect perthis(this(Caller)) {
  30. pointcut stringCtors(): call(String.new(String));
  31. before(): stringCtors() {
  32. Tester.event("before-string");
  33. }
  34. pointcut cCtors(): call(C.new());
  35. before(): cCtors() {
  36. Tester.event("before-c");
  37. }
  38. pointcut goCalls(Caller caller): call(void go()) && target(caller);
  39. before(Caller caller): goCalls(caller) {
  40. Tester.event("before-go");
  41. Tester.check(caller != null, "instance method");
  42. }
  43. pointcut goStaticCalls(): call(void Caller.staticGo());
  44. before(): goStaticCalls() {
  45. Tester.event("before-static");
  46. }
  47. }