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 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. }
  14. }
  15. interface I1 { }
  16. interface I11 extends I1 { }
  17. interface I111 extends I11 { }
  18. interface I12 extends I1 { }
  19. class C1 implements I1 { C1(String s) {} }
  20. class C11 implements I11 { }
  21. class C111 implements I111 { }
  22. class C12 implements I12 { }
  23. class Cleaf1 extends C1 { }
  24. class Cleaf11 extends C11 { }
  25. class Cleaf111 extends C111 { }
  26. class Cleaf12 extends C12 { }
  27. // For this class structure: here is the "directly implements" relation
  28. // C1 directly implements I1
  29. // C11 directly implements I11
  30. // C11 directly implements I1
  31. // C111 directly implements I111
  32. // C111 directly implements I11
  33. // C111 directly implements I1
  34. // C12 directly implements I12
  35. // C12 directly implements I1
  36. aspect A1 {
  37. static int i1Count, c1Count, c1IntCount = 0;
  38. // interface
  39. before(): initialization(I1.new(..)) {
  40. i1Count++;
  41. }
  42. C1.new() {
  43. c1Count++;
  44. }
  45. C1.new(int x) {
  46. c1IntCount++;
  47. }
  48. }
  49. aspect Verify {
  50. // In the current model, introduces on constructors !don't! work their way
  51. // down the inheritance. With the given hierarchy, the number of
  52. // invocations of the introduced constructors should match the
  53. // numbers below.
  54. after(): within(Driver) && execution(static void test(..)) {
  55. Tester.checkEqual(A1.i1Count, 8, "A1.i1Count");
  56. Tester.checkEqual(A1.c1Count, 2, "A1.c1Count");
  57. Tester.checkEqual(A1.c1IntCount, 0, "A1.c1IntCount");
  58. }
  59. }