aboutsummaryrefslogtreecommitdiffstats
path: root/tests/new/TypePat.java
blob: 6e358c0a6738b9ad60933311608c8be3c785cd53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package test;

import org.aspectj.testing.Tester;
import java.util.*;


public class TypePat {
    public static void main(String[] args) {
        Inner o = new Inner();
        o.m();
        
        Tester.checkAndClearEvents(new String[] {
            "A.before1: TypePat.Inner.m()",
                "InnerA.before: TypePat.Inner.m()",
                "A.before2: C.foo()",
                "TypePat.Inner.m",
                });


        Map m = new HashMap();
        m.put("a", "b");

        for (Iterator i = m.entrySet().iterator(); i.hasNext(); ) {
            Map.Entry e = (Map.Entry)i.next();
            e.getKey();
        }

        Tester.checkAndClearEvents(new String[] {
            "A.before3: Map.Entry.getKey()"
                });



        Runnable r = new Runnable() {
                public void run() {
                    C.foo();
                    Tester.event("TypePat.Runnable.run");
                }
            };

        r.run();
        Tester.checkAndClearEvents(new String[] {
            "A.before2: C.foo()",
                "TypePat.Runnable.run",
                });
            //Tester.printEvents();
    }
    static class Inner {
        public void m() {
            C.foo();
            Tester.event("TypePat.Inner.m");
        }
    }

    static aspect InnerA {
        before(): call(* Inner.*(..)) {
            Tester.event("InnerA.before: " + thisJoinPoint.getSignature().toShortString());
        }
    }
}

class C {
    static void foo() {
    }
}


aspect A {
    before(): call(* TypePat.*.*(..)) && within(TypePat) && !within(TypePat.*) {
        Tester.event("A.before1: " + thisJoinPoint.getSignature().toShortString());
    }

    pointcut checkCall(): call(* *(..)) && !call(* Tester.*(..));

    before(): checkCall() && within(TypePat.*) && !within(*.InnerA) {
        Tester.event("A.before2: " + thisJoinPoint.getSignature().toShortString());
    }

    before(): checkCall() && target(Map.Entry) {
        Tester.event("A.before3: " + thisJoinPoint.getSignature().toShortString());
    }
}