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.

PR353.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import org.aspectj.testing.*;
  2. import java.util.*;
  3. public class PR353 {
  4. public static void main(String[] args) {
  5. new PR353().go(args);
  6. Tester.checkAllEvents();
  7. }
  8. void go(String[] args) {
  9. A a = new A();
  10. B b = new B();
  11. C c = new C();
  12. D d = new D();
  13. E e = new E();
  14. a.f();
  15. b.f();
  16. c.f();
  17. d.f();
  18. e.f();
  19. new Verifier().verify(Aspect.map);
  20. }
  21. }
  22. interface I { public void f(); }
  23. class A { public void f() { } }
  24. class B implements I { public void f() { } }
  25. class C { public void f() { } }
  26. class D extends C { public void f() { } }
  27. class E extends B { public void f() { } }
  28. class F extends C
  29. implements I { public void f() { } }
  30. class Verifier {
  31. void verify(Map map) {
  32. Iterator iter = map.keySet().iterator();
  33. while (iter.hasNext()) {
  34. String key = (iter.next() + "").toLowerCase();
  35. List list = (List) map.get(key);
  36. Iterator it = list.iterator();
  37. while (it.hasNext()) {
  38. Object onext = it.next();
  39. String next = (onext + "").toLowerCase();
  40. if (key.indexOf(next) == -1) {
  41. Tester.check(false, next + " not found in " + key);
  42. } else {
  43. it.remove();
  44. }
  45. }
  46. Tester.check(list.size() == 0, list + " contains classes excluded");
  47. }
  48. }
  49. }
  50. aspect Aspect {
  51. pointcut r(): receptions(* f());
  52. pointcut abcdef(): r();
  53. pointcut acd(): r() && !instanceof(I);
  54. pointcut acdf(): r() && !instanceof(B);
  55. pointcut a(): r() && !instanceof(B) && !instanceof(C);
  56. public static Map map = new HashMap();
  57. static {
  58. String[] ss = {
  59. "abcdef",
  60. "acd",
  61. "acdf",
  62. "a",
  63. };
  64. for (int i = 0; i < ss.length; i++) {
  65. map.put(ss[i], new Vector());
  66. }
  67. }
  68. static before(): abcdef() {
  69. p("abcdef", thisJoinPoint.className);
  70. }
  71. static before(): acd() {
  72. p("acd", thisJoinPoint.className);
  73. }
  74. static before(): acdf() {
  75. p("acdf", thisJoinPoint.className);
  76. }
  77. static before(): a() {
  78. p("a", thisJoinPoint.className);
  79. }
  80. static void p(String key, String str) {
  81. List list = (List) map.get(key);
  82. if (list == null) {
  83. list = new Vector();
  84. }
  85. list.add(str);
  86. map.put(key, list);
  87. }
  88. static List v(Object[] os) {
  89. List v = new Vector();
  90. for (int i = 0; i < os.length; i++) {
  91. v.add(os[i]);
  92. }
  93. return v;
  94. }
  95. }