aboutsummaryrefslogtreecommitdiffstats
path: root/tests/new/AfterReturningConstructor.java
blob: 3d87758e5075d7c71be594c2c7255b658ebd4898 (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
import org.aspectj.testing.Tester;

/** @testcase PR#827 after returning advice on interface and implementation constructor */
public class AfterReturningConstructor {
    public static void main(String[] args) {
        U.ee(U.before + U.ijp);
        U.ee(U.afterReturning + U.ijp);
        U.ee(U.before + U.cjp);
        U.ee(U.c);
        U.ee(U.afterReturning + U.cjp);
        U.ee("done");
        new C();
        U.e("done");
        Tester.checkAllEvents();
    }
}

class C implements I {
    C() { U.e("C()"); }
    public void run() { }
}

interface I {
    void run();
}

class U {
    static final String before = "before(): ";
    static final String after = "after(): ";
    static final String afterReturning = "after() returning(): ";
    static final String afterThrowing = "after() throwing(): ";
    static final String c = "C()";
    static final String i = "I()";
    static final String cjp = "initialization(" + c + ")";
    static final String ijp = "initialization(" + i + ")";

    static void e(String event) {
        //System.err.println("act event: " + event); // XXX
        Tester.event(event);
    }
    static void ee(String event) {
        //System.err.println("exp event: " + event); // XXX
        Tester.expectEvent(event);
    }
}

aspect A {
    /** must pick out both interface and implementor initializers */
    pointcut pc(): initialization(new(..)) && !within(A);

    before(): pc() {
        U.e(U.before + thisJoinPoint);
    }

    after() returning(): pc() {
        U.e(U.afterReturning + thisJoinPoint);
    }
}