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.

CflowInitInAspectVariantsBefore.java 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import org.aspectj.testing.Tester;
  2. public class CflowInitInAspectVariantsBefore {
  3. public static void main(String[] args) {
  4. new C().a();
  5. Tester.checkAllEventsIgnoreDups();
  6. }
  7. static {
  8. Tester.expectEvent("cflow before pc()");
  9. Tester.expectEvent("cflow before execution(void C.a())");
  10. Tester.expectEvent("cflowbelow before pc()");
  11. Tester.expectEvent("cflowbelow before execution(void C.a())");
  12. }
  13. }
  14. class C {
  15. void a() {b();}
  16. private void b() {int i = 1;} // avoid later optimizations
  17. }
  18. aspect A {
  19. pointcut pc() : execution(void C.a());
  20. // ---- works
  21. pointcut safety() : !within(A) ;
  22. // ---- cannot use cflow to exclude itself - reference thereto fails
  23. //pointcut safety() : !(within(A) && cflow(pc()));
  24. // ---- cannot use dynamic calculation, because before call happens first?
  25. //pointcut safety() : !within(A) || (within(A) && if(touched)) ;
  26. static boolean touched = false;
  27. // ---- does not address the before advice methods advising themselves
  28. //pointcut safety() : !(initialization(A.new(..)) || staticinitialization(A));
  29. // ---- worse way of saying !within(A)
  30. //pointcut safety() : this(C) || this(CflowInitInAspectVariantsBefore) || this(null);
  31. //pointcut safety() : this(C) || this(CflowInitInAspectVariantsBefore) || this(null);
  32. // no bug if ": within(C) && ..."
  33. // @testTarget cflow.before.namedpc
  34. before() : safety() && cflow(pc()) {
  35. if (!touched) touched = true;
  36. Tester.event("cflow before pc()");
  37. }
  38. // @testTarget cflow.before.anonpc
  39. before() : safety() && cflow(execution(void C.a())) {
  40. if (!touched) touched = true;
  41. Tester.event("cflow before execution(void C.a())");
  42. }
  43. // @testTarget cflowbelow.before.namedpc
  44. before() : safety() && cflowbelow(pc()) {
  45. if (!touched) touched = true;
  46. Tester.event("cflowbelow before pc()");
  47. }
  48. // @testTarget cflowbelow.before.anonpc
  49. before() : safety() && cflowbelow(execution(void C.a())) {
  50. if (!touched) touched = true;
  51. Tester.event("cflowbelow before execution(void C.a())");
  52. }
  53. }