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.

PR355.java 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import org.aspectj.testing.*;
  2. import java.io.*;
  3. public class PR355 {
  4. public static void main(String[] args) {
  5. new PR355().go();
  6. }
  7. static {
  8. String[] types = { "static", "non", "instance" };
  9. String[] advice = { "before", "after", "around" };
  10. for (int i = 0; i < types.length; i++) {
  11. for (int j = 0; j < advice.length; j++) {
  12. Tester.expectEvent(types[i] + "-" + advice[j]);
  13. }
  14. }
  15. Tester.expectEventsInString("C.f,C.e");
  16. }
  17. void go() {
  18. new C().f();
  19. Tester.checkAllEvents();
  20. }
  21. }
  22. class C {
  23. void f() { Tester.event("C.f"); e(); }
  24. void e() { Tester.event("C.e"); }
  25. }
  26. abstract aspect Cuts {
  27. pointcut p(): within(C) && call(* C.*(..));
  28. static void a(String s) { Tester.event(s); }
  29. }
  30. /* Static aspects have no problem */
  31. aspect StaticAspect extends Cuts {
  32. before(): p() { a("static-before"); }
  33. void around(): p() { a("static-around"); proceed(); }
  34. after (): p() { a("static-after"); }
  35. }
  36. /* Non-static aspects have a problem */
  37. aspect NonStaticAspect extends Cuts issingleton() {
  38. before(): p() { a("non-before"); }
  39. void around(): p() { a("non-around"); proceed(); }
  40. after (): p() { a("non-after"); }
  41. }
  42. /* No problem here */
  43. aspect InstanceOfAspect extends Cuts perthis(this(C)) {
  44. before(): p() { a("instance-before"); }
  45. void around(): p() { a("instance-around"); proceed(); }
  46. after (): p() { a("instance-after"); }
  47. }