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.

Dominates.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import org.aspectj.testing.*;
  2. /******************************
  3. Full_Name: Eelco Rommes
  4. Version: ajc version 0.7beta7 (built Oct 6, 2000 4:03 PM PST) running on java 1.3.0
  5. OS: Win 98
  6. Submission from: mede.serc.nl (192.87.7.62)
  7. I have one aspect using introduction to make some classes
  8. implement certain interfaces. In another aspect, these
  9. introductions are used to define pointcuts. The compiler
  10. warns me, however, that the advice coupled to these pointcuts
  11. have no target. This, because it apparently does not see
  12. how the introduction-aspect changes the class-hierarchy.
  13. I have tried to use 'dominates' to force aspectJ to evaluate
  14. the introduction-aspect first, but it doesn't work.
  15. ******************************/
  16. public class Dominates {
  17. public static void main(String[] args) {
  18. new Dominates().go(args);
  19. }
  20. void go(String[] args) {
  21. new A().run();
  22. new ExtendsA().run();
  23. new ExtendsRunnable().run();
  24. Tester.check(Flags.run1, "Flags.run1");
  25. Tester.check(Flags.run2, "Flags.run2");
  26. Tester.check(Flags.run3, "Flags.run3");
  27. Tester.check(Flags.run4, "Flags.run4");
  28. Tester.check(ExtendsFlags.run1, "ExtendsFlags.run1");
  29. Tester.check(ExtendsFlags.run2, "ExtendsFlags.run2");
  30. Tester.check(ExtendsFlags.run3, "ExtendsFlags.run3");
  31. Tester.check(ExtendsFlags.run4, "ExtendsFlags.run4");
  32. Tester.check(ExtendsFlags.run5, "ExtendsFlags.run5");
  33. Tester.check(ExtendsFlags.run6, "ExtendsFlags.run6");
  34. }
  35. }
  36. class A {
  37. }
  38. class Flags {
  39. public static boolean run1 = false;
  40. public static boolean run2 = false;
  41. public static boolean run3 = false;
  42. public static boolean run4 = false;
  43. }
  44. aspect Aspect0 {
  45. pointcut run(): call(* run(..)) && target(A);
  46. before(): run() {
  47. Flags.run1 = true;
  48. }
  49. }
  50. aspect Aspect00 {
  51. pointcut run(): call(* run(..)) && target(Runnable+);
  52. before(): run() {
  53. Flags.run4 = true;
  54. }
  55. }
  56. aspect Aspect1 {
  57. declare parents: A implements Runnable;
  58. public void A.run() {}
  59. }
  60. aspect Aspect2 {
  61. pointcut run(): call(* run(..)) && target(A);
  62. before(): run() {
  63. Flags.run2 = true;
  64. }
  65. }
  66. aspect Aspect3 {
  67. pointcut run(): call(* run(..)) && target(Runnable+);
  68. before(): run() {
  69. Flags.run3 = true;
  70. }
  71. }
  72. // ------------------------------
  73. class ExtendsA {
  74. }
  75. class ExtendsRunnable {
  76. public void run() {}
  77. }
  78. class ExtendsFlags {
  79. public static boolean run1 = false;
  80. public static boolean run2 = false;
  81. public static boolean run3 = false;
  82. public static boolean run4 = false;
  83. public static boolean run5 = false;
  84. public static boolean run6 = false;
  85. }
  86. aspect AspectExtends0 {
  87. pointcut run(): call(* run(..)) && target(ExtendsA);
  88. before(): run() {
  89. ExtendsFlags.run1 = true;
  90. }
  91. }
  92. aspect AspectExtends00 {
  93. pointcut run(ExtendsRunnable r): call(* run(..)) && target(r);
  94. before(ExtendsRunnable r): run(r) {
  95. if (r instanceof ExtendsA) {
  96. ExtendsFlags.run5 = true;
  97. } else {
  98. ExtendsFlags.run6 = true;
  99. }
  100. }
  101. }
  102. aspect AspectExtends1 {
  103. declare parents: ExtendsA extends ExtendsRunnable;
  104. public void ExtendsA.run() {}
  105. }
  106. aspect AspectExtends2 {
  107. pointcut run(): call(* run(..)) && target(ExtendsA);
  108. before(): run() {
  109. ExtendsFlags.run2 = true;
  110. }
  111. }
  112. aspect AspectExtends3 {
  113. pointcut run(ExtendsRunnable r): call(* run(..)) && target(r);
  114. before(ExtendsRunnable r): run(r) {
  115. if (r instanceof ExtendsA) {
  116. ExtendsFlags.run3 = true;
  117. } else {
  118. ExtendsFlags.run4 = true;
  119. }
  120. }
  121. }