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.

Driver.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import org.aspectj.testing.Tester;
  2. public class Driver {
  3. public static void main(String[] args) { test(); }
  4. public static void test() {
  5. C1 c1 = new C1();
  6. C11 c11 = new C11();
  7. C111 c111 = new C111();
  8. C12 c12 = new C12();
  9. Cleaf1 cleaf1 = new Cleaf1();
  10. Cleaf11 cleaf11 = new Cleaf11();
  11. Cleaf111 cleaf111 = new Cleaf111();
  12. Cleaf12 cleaf12 = new Cleaf12();
  13. Tester.checkEqual(c1.a, 0, "c1.a");
  14. Tester.checkEqual(c11.a, 0, "c11.a");
  15. Tester.checkEqual(c111.a, 0, "c111.a");
  16. Tester.checkEqual(c12.a, 0, "c12.a");
  17. Tester.checkEqual(cleaf1.a, 0, "cleaf1.a");
  18. Tester.checkEqual(cleaf11.a, 0, "cleaf11.a");
  19. Tester.checkEqual(cleaf111.a, 0, "cleaf111.a");
  20. Tester.checkEqual(cleaf12.a, 0, "cleaf12.a");
  21. Tester.checkEqual(c1.b, 0, "c1.b");
  22. Tester.checkEqual(cleaf1.b, 0, "cleaf1.b");
  23. Tester.checkEqual(I1.c, 5, "I1.c");
  24. Tester.checkEqual(c1.d, 1, "c1.d");
  25. Tester.checkEqual(c11.d, 1, "c11.d");
  26. Tester.checkEqual(c111.d, 1, "c111.d");
  27. Tester.checkEqual(c12.d, 1, "c12.d");
  28. Tester.checkEqual(c1.e, 2, "c1.e");
  29. Tester.checkEqual(cleaf1.e, 2, "cleaf1.e");
  30. Tester.checkEqual(C1.f, 4, "C1.f");
  31. Tester.checkEqual(cleaf1.f, 4, "cleaf1.f");
  32. Tester.checkEqual(c1.f, 4, "c1.f");
  33. Tester.checkEqual(c1.getF(), 4, "c1.getF()");
  34. }
  35. }
  36. interface I1 { }
  37. interface I11 extends I1 { }
  38. interface I111 extends I11 { }
  39. interface I12 extends I1 { }
  40. class C1 implements I1 { }
  41. class C11 implements I11 { }
  42. class C111 implements I111 { }
  43. class C12 implements I12 { }
  44. class Cleaf1 extends C1 { }
  45. class Cleaf11 extends C11 { }
  46. class Cleaf111 extends C111 { }
  47. class Cleaf12 extends C12 { }
  48. // For this class structure: here is the "directly implements" relation
  49. // C1 directly implements I1
  50. // C11 directly implements I11
  51. // C11 directly implements I1
  52. // C111 directly implements I111
  53. // C111 directly implements I11
  54. // C111 directly implements I1
  55. // C12 directly implements I12
  56. // C12 directly implements I1
  57. // introducing a bunch of variables (almost all non-static).
  58. aspect A1 {
  59. // Variable Introductions:
  60. // without initializer X designator is interface
  61. // with initializer X designator is class
  62. // with initializer, interface also has the two cases of presence or
  63. // absence of the modifiers.
  64. // introduce on initializer without initializer
  65. // should introduce into:
  66. // C1, C11, C111, C12
  67. int I1.a;
  68. // introduce on interface with initializer but no Mods
  69. // should introduce into:
  70. // C1, C11, C111, C12
  71. int I1.d = 1;
  72. // introduce on interface with initializer and Mods
  73. // should introduce into:
  74. // I1
  75. public static final int I1.c = 5;
  76. // introduce on class
  77. // should introduce into
  78. // C1
  79. int C1.b;
  80. int C1.e = 2;
  81. // introduce on class with static modifier
  82. // should introduce into
  83. // C1
  84. static int C1.f = 2;
  85. int C1.getF() { return 2; }
  86. }
  87. aspect A2 {
  88. declare precedence: A2, A1;
  89. int around() : set(int C1.f) && within(A1) {
  90. return C1.f = 3;
  91. }
  92. after (): staticinitialization(C1) {
  93. C1.f = 4;
  94. }
  95. // this should override the introduction from A1
  96. int C1.getF() { return 4; }
  97. }