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.

TypePat.java 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package test;
  2. import org.aspectj.testing.Tester;
  3. import java.util.*;
  4. public class TypePat {
  5. public static void main(String[] args) {
  6. Inner o = new Inner();
  7. o.m();
  8. Tester.checkAndClearEvents(new String[] {
  9. "A.before1: TypePat.Inner.m()",
  10. "InnerA.before: TypePat.Inner.m()",
  11. "A.before2: C.foo()",
  12. "TypePat.Inner.m",
  13. });
  14. Map m = new HashMap();
  15. m.put("a", "b");
  16. for (Iterator i = m.entrySet().iterator(); i.hasNext(); ) {
  17. Map.Entry e = (Map.Entry)i.next();
  18. e.getKey();
  19. }
  20. Tester.checkAndClearEvents(new String[] {
  21. "A.before3: Map.Entry.getKey()"
  22. });
  23. Runnable r = new Runnable() {
  24. public void run() {
  25. C.foo();
  26. Tester.event("TypePat.Runnable.run");
  27. }
  28. };
  29. r.run();
  30. Tester.checkAndClearEvents(new String[] {
  31. "A.before2: C.foo()",
  32. "TypePat.Runnable.run",
  33. });
  34. //Tester.printEvents();
  35. }
  36. static class Inner {
  37. public void m() {
  38. C.foo();
  39. Tester.event("TypePat.Inner.m");
  40. }
  41. }
  42. static aspect InnerA {
  43. before(): call(* Inner.*(..)) {
  44. Tester.event("InnerA.before: " + thisJoinPoint.getSignature().toShortString());
  45. }
  46. }
  47. }
  48. class C {
  49. static void foo() {
  50. }
  51. }
  52. aspect A {
  53. before(): call(* TypePat.*.*(..)) && within(TypePat) && !within(TypePat.*) {
  54. Tester.event("A.before1: " + thisJoinPoint.getSignature().toShortString());
  55. }
  56. pointcut checkCall(): call(* *(..)) && !call(* Tester.*(..));
  57. before(): checkCall() && within(TypePat.*) && !within(*.InnerA) {
  58. Tester.event("A.before2: " + thisJoinPoint.getSignature().toShortString());
  59. }
  60. before(): checkCall() && target(Map.Entry) {
  61. Tester.event("A.before3: " + thisJoinPoint.getSignature().toShortString());
  62. }
  63. }